Skip to content

Commit

Permalink
chore: Used Maps in place of Lists
Browse files Browse the repository at this point in the history
  • Loading branch information
hsinha610 authored Jul 30, 2024
1 parent ab978ba commit 1516d9c
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/main/kotlin/com/featurevisor/sdk/DatafileReader.kt
Original file line number Diff line number Diff line change
@@ -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<Attribute> = datafileJson.attributes
private val segments: List<Segment> = datafileJson.segments
private val features: List<Feature> = datafileJson.features
private val schemaVersion: String = datafileContent.schemaVersion
private val revision: String = datafileContent.revision
private val attributes: Map<AttributeKey, Attribute> = datafileContent.attributes.associateBy { it.key }
private val segments: Map<SegmentKey, Segment> = datafileContent.segments.associateBy { it.key }
private val features: Map<FeatureKey, Feature> = datafileContent.features.associateBy { it.key }

fun getRevision(): String {
return revision
Expand All @@ -26,19 +20,19 @@ class DatafileReader constructor(
return schemaVersion
}

fun getAllAttributes(): List<Attribute> {
fun getAllAttributes(): Map<AttributeKey, Attribute> {
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]
}
}

0 comments on commit 1516d9c

Please sign in to comment.