@@ -9,14 +9,14 @@ import com.featurevisor.types.Segment
9
9
import com.featurevisor.types.SegmentKey
10
10
11
11
class DatafileReader constructor(
12
- datafileJson : DatafileContent ,
12
+ datafileContent : DatafileContent ,
13
13
) {
14
14
15
- private val schemaVersion: String = datafileJson .schemaVersion
16
- private val revision: String = datafileJson .revision
17
- private val attributes: List < Attribute > = datafileJson .attributes
18
- private val segments: List < Segment > = datafileJson .segments
19
- private val features: List < Feature > = datafileJson .features
15
+ private val schemaVersion: String = datafileContent .schemaVersion
16
+ private val revision: String = datafileContent .revision
17
+ private val attributes: Map < AttributeKey , Attribute > = datafileContent .attributes.associateBy { it.key }
18
+ private val segments: Map < SegmentKey , Segment > = datafileContent .segments.associateBy { it.key }
19
+ private val features: Map < FeatureKey , Feature > = datafileContent .features.associateBy { it.key }
20
20
21
21
fun getRevision (): String {
22
22
return revision
@@ -27,18 +27,18 @@ class DatafileReader constructor(
27
27
}
28
28
29
29
fun getAllAttributes (): List <Attribute > {
30
- return attributes
30
+ return attributes.values.toList()
31
31
}
32
32
33
33
fun getAttribute (attributeKey : AttributeKey ): Attribute ? {
34
- return attributes.find { attribute -> attribute.key == attributeKey }
34
+ return attributes[ attributeKey]
35
35
}
36
36
37
37
fun getSegment (segmentKey : SegmentKey ): Segment ? {
38
- return segments.find { segment -> segment.key == segmentKey }
38
+ return segments[ segmentKey]
39
39
}
40
40
41
41
fun getFeature (featureKey : FeatureKey ): Feature ? {
42
- return features.find { feature -> feature.key == featureKey }
42
+ return features[ featureKey]
43
43
}
44
44
}
0 commit comments