-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsplit_view.dart
More file actions
78 lines (67 loc) · 2.37 KB
/
split_view.dart
File metadata and controls
78 lines (67 loc) · 2.37 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import 'dart:core';
class SplitView {
static const String _keyName = 'name';
static const String _keyTrafficType = 'trafficType';
static const String _keyKilled = 'killed';
static const String _keyTreatments = 'treatments';
static const String _keyChangeNumber = 'changeNumber';
static const String _keyConfigs = 'configs';
static const String _keyDefaultTreatment = 'defaultTreatment';
static const String _keySets = 'sets';
static const String _keyImpressionsDisabled = 'impressionsDisabled';
String name;
String trafficType;
bool killed = false;
List<String> treatments = [];
int changeNumber;
Map<String, String> configs = {};
String defaultTreatment;
List<String> sets = [];
bool impressionsDisabled = false;
SplitView(this.name, this.trafficType, this.killed, this.treatments,
this.changeNumber, this.configs,
[this.defaultTreatment = '', this.sets = const [], this.impressionsDisabled = false]);
static SplitView? fromEntry(Map<dynamic, dynamic>? entry) {
if (entry == null || entry.isEmpty) {
return null;
}
final Map<String, String> mappedConfig = {};
entry[_keyConfigs]?.entries.forEach((MapEntry<dynamic, dynamic> entry) => {
mappedConfig.addAll({entry.key.toString(): entry.value.toString()})
});
if (entry[_keyTreatments] == null) {
entry[_keyTreatments] = entry[_keyTreatments] ?? [];
}
if (entry[_keySets] == null) {
entry[_keySets] = [];
}
if (entry[_keyImpressionsDisabled] == null) {
entry[_keyImpressionsDisabled] = false;
}
return SplitView(
entry[_keyName],
entry[_keyTrafficType],
entry[_keyKilled],
(entry[_keyTreatments] as List).map((el) => el as String).toList(),
entry[_keyChangeNumber],
mappedConfig,
entry[_keyDefaultTreatment] ?? '',
(entry[_keySets] as List).map((el) => el as String).toList(),
entry[_keyImpressionsDisabled] ?? false
);
}
@override
String toString() {
return '''SplitView = {
$_keyName: $name,
$_keyTrafficType: $trafficType,
$_keyKilled: $killed,
$_keyTreatments: ${treatments.toString()},
$_keyChangeNumber: $changeNumber,
$_keyConfigs: $configs,
$_keyDefaultTreatment: $defaultTreatment,
$_keySets: ${sets.toString()},
$_keyImpressionsDisabled: $impressionsDisabled
}''';
}
}