-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsplit_prerequisite.dart
More file actions
55 lines (45 loc) · 1.42 KB
/
split_prerequisite.dart
File metadata and controls
55 lines (45 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/// Prerequisite class.
class Prerequisite {
final String _name;
final Set<String> _treatments;
/// The feature flag name of the prerequisite.
String get name => _name;
/// The treatments of the prerequisite.
Set<String> get treatments => _treatments;
/// Creates a new Prerequisite instance.
Prerequisite(this._name, this._treatments);
/// Creates a Prerequisite instance from a map.
static Prerequisite fromEntry(Map<String, dynamic> el) {
final String name = (el['n'] ?? el['n:'] ?? '').toString();
final List<dynamic> rawTreatments = (el['t'] as List<dynamic>?) ?? [];
final Set<String> treatments =
rawTreatments.map((e) => e.toString()).toSet();
return Prerequisite(name, treatments);
}
@override
String toString() {
return '''Prerequisite = {
name: $name,
treatments: $treatments
}''';
}
/// Checks if this Prerequisite is equal to another Prerequisite.
bool equals(Prerequisite other) {
return name == other.name && treatments == other.treatments;
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Prerequisite &&
name == other.name &&
other.treatments.containsAll(treatments);
}
@override
int get hashCode {
int treatmentsHash = 0;
for (final t in _treatments) {
treatmentsHash ^= t.hashCode;
}
return name.hashCode ^ treatmentsHash;
}
}