Skip to content

Commit d2bcb68

Browse files
authored
Merge pull request #205 from Tochukwu-tech/feat/routing-result
feat(routing): add immutable RoutingResult class for routing resolution
2 parents 83cab6b + 2d88dd7 commit d2bcb68

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'result.dart';
2+
3+
/// Immutable result object returned from routing resolution.
4+
///
5+
/// Holds the [source] tag indicating how the route was resolved,
6+
/// an optional numeric [id] extracted from the address or memo,
7+
/// and any [warnings] emitted during resolution.
8+
final class RoutingResult {
9+
final RoutingSource source;
10+
final BigInt? id;
11+
final List<RoutingWarning> warnings;
12+
13+
RoutingResult({
14+
required this.source,
15+
this.id,
16+
List<RoutingWarning>? warnings,
17+
}) : warnings = List.unmodifiable(warnings ?? const []);
18+
19+
@override
20+
String toString() =>
21+
'RoutingResult(source: $source, id: $id, warnings: $warnings)';
22+
23+
@override
24+
bool operator ==(Object other) =>
25+
identical(this, other) ||
26+
other is RoutingResult &&
27+
source == other.source &&
28+
id == other.id &&
29+
_listEquals(warnings, other.warnings);
30+
31+
@override
32+
int get hashCode => Object.hash(source, id, Object.hashAll(warnings));
33+
34+
static bool _listEquals(List<RoutingWarning> a, List<RoutingWarning> b) {
35+
if (a.length != b.length) return false;
36+
for (var i = 0; i < a.length; i++) {
37+
if (a[i] != b[i]) return false;
38+
}
39+
return true;
40+
}
41+
}

0 commit comments

Comments
 (0)