From 1516d9c318710becac6188c9d545b9770d55c391 Mon Sep 17 00:00:00 2001 From: HARSHIT SINHA <47042785+hsinha610@users.noreply.github.com> Date: Tue, 30 Jul 2024 16:35:57 +0530 Subject: [PATCH] chore: Used Maps in place of Lists --- .../com/featurevisor/sdk/DatafileReader.kt | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/com/featurevisor/sdk/DatafileReader.kt b/src/main/kotlin/com/featurevisor/sdk/DatafileReader.kt index eef4c77..2698b76 100644 --- a/src/main/kotlin/com/featurevisor/sdk/DatafileReader.kt +++ b/src/main/kotlin/com/featurevisor/sdk/DatafileReader.kt @@ -1,22 +1,16 @@ package com.featurevisor.sdk -import com.featurevisor.types.Attribute -import com.featurevisor.types.AttributeKey -import com.featurevisor.types.DatafileContent -import com.featurevisor.types.Feature -import com.featurevisor.types.FeatureKey -import com.featurevisor.types.Segment -import com.featurevisor.types.SegmentKey - -class DatafileReader constructor( - datafileJson: DatafileContent, +import com.featurevisor.types.* + +class DatafileReader( + datafileContent: DatafileContent, ) { - private val schemaVersion: String = datafileJson.schemaVersion - private val revision: String = datafileJson.revision - private val attributes: List = datafileJson.attributes - private val segments: List = datafileJson.segments - private val features: List = datafileJson.features + private val schemaVersion: String = datafileContent.schemaVersion + private val revision: String = datafileContent.revision + private val attributes: Map = datafileContent.attributes.associateBy { it.key } + private val segments: Map = datafileContent.segments.associateBy { it.key } + private val features: Map = datafileContent.features.associateBy { it.key } fun getRevision(): String { return revision @@ -26,19 +20,19 @@ class DatafileReader constructor( return schemaVersion } - fun getAllAttributes(): List { + fun getAllAttributes(): Map { return attributes } fun getAttribute(attributeKey: AttributeKey): Attribute? { - return attributes.find { attribute -> attribute.key == attributeKey } + return attributes[attributeKey] } fun getSegment(segmentKey: SegmentKey): Segment? { - return segments.find { segment -> segment.key == segmentKey } + return segments[segmentKey] } fun getFeature(featureKey: FeatureKey): Feature? { - return features.find { feature -> feature.key == featureKey } + return features[featureKey] } }