Skip to content

Commit 2df361b

Browse files
committed
use better return types
1 parent 6cd8645 commit 2df361b

File tree

4 files changed

+30
-75
lines changed

4 files changed

+30
-75
lines changed

src/main/java/com/featurevisor/sdk/ChildInstance.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.Map;
44
import java.util.HashMap;
5+
import java.util.List;
6+
import com.featurevisor.types.EvaluatedFeatures;
57

68
/**
79
* Child instance of Featurevisor SDK
@@ -224,7 +226,7 @@ public Double getVariableDouble(String featureKey, String variableKey) {
224226
return getVariableDouble(featureKey, variableKey, null, null);
225227
}
226228

227-
public java.util.List<String> getVariableArray(String featureKey, String variableKey, Map<String, Object> context, Instance.OverrideOptions options) {
229+
public List<String> getVariableArray(String featureKey, String variableKey, Map<String, Object> context, Instance.OverrideOptions options) {
228230
return this.parent.getVariableArray(
229231
featureKey,
230232
variableKey,
@@ -233,11 +235,11 @@ public java.util.List<String> getVariableArray(String featureKey, String variabl
233235
);
234236
}
235237

236-
public java.util.List<String> getVariableArray(String featureKey, String variableKey, Map<String, Object> context) {
238+
public List<String> getVariableArray(String featureKey, String variableKey, Map<String, Object> context) {
237239
return getVariableArray(featureKey, variableKey, context, null);
238240
}
239241

240-
public java.util.List<String> getVariableArray(String featureKey, String variableKey) {
242+
public List<String> getVariableArray(String featureKey, String variableKey) {
241243
return getVariableArray(featureKey, variableKey, null, null);
242244
}
243245

@@ -278,23 +280,23 @@ public <T> T getVariableJSON(String featureKey, String variableKey) {
278280
/**
279281
* Get all evaluations
280282
*/
281-
public Map<String, Object> getAllEvaluations(Map<String, Object> context, java.util.List<String> featureKeys, Instance.OverrideOptions options) {
283+
public EvaluatedFeatures getAllEvaluations(Map<String, Object> context, List<String> featureKeys, Instance.OverrideOptions options) {
282284
return this.parent.getAllEvaluations(
283285
mergeContexts(this.context, context),
284286
featureKeys,
285287
mergeOverrideOptions(options)
286288
);
287289
}
288290

289-
public Map<String, Object> getAllEvaluations(Map<String, Object> context, java.util.List<String> featureKeys) {
291+
public EvaluatedFeatures getAllEvaluations(Map<String, Object> context, List<String> featureKeys) {
290292
return getAllEvaluations(context, featureKeys, null);
291293
}
292294

293-
public Map<String, Object> getAllEvaluations(Map<String, Object> context) {
295+
public EvaluatedFeatures getAllEvaluations(Map<String, Object> context) {
294296
return getAllEvaluations(context, null, null);
295297
}
296298

297-
public Map<String, Object> getAllEvaluations() {
299+
public EvaluatedFeatures getAllEvaluations() {
298300
return getAllEvaluations(null, null, null);
299301
}
300302

src/main/java/com/featurevisor/sdk/Instance.java

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.featurevisor.types.DatafileContent;
44
import com.featurevisor.types.Feature;
5+
import com.featurevisor.types.EvaluatedFeature;
6+
import com.featurevisor.types.EvaluatedFeatures;
57
import com.fasterxml.jackson.databind.ObjectMapper;
68
import java.util.Map;
79
import java.util.HashMap;
@@ -613,7 +615,7 @@ public <T> T getVariableJSON(String featureKey, String variableKey) {
613615
/**
614616
* Get all evaluations
615617
*/
616-
public Map<String, Object> getAllEvaluations(Map<String, Object> context, List<String> featureKeys, OverrideOptions options) {
618+
public EvaluatedFeatures getAllEvaluations(Map<String, Object> context, List<String> featureKeys, OverrideOptions options) {
617619
if (context == null) {
618620
context = new HashMap<>();
619621
}
@@ -624,15 +626,15 @@ public Map<String, Object> getAllEvaluations(Map<String, Object> context, List<S
624626
options = new OverrideOptions();
625627
}
626628

627-
Map<String, Object> result = new HashMap<>();
629+
Map<String, EvaluatedFeature> result = new HashMap<>();
628630

629631
List<String> keys = featureKeys.isEmpty() ? this.datafileReader.getFeatureKeys() : featureKeys;
630632
for (String featureKey : keys) {
631633
// isEnabled
632634
Evaluation flagEvaluation = evaluateFlag(featureKey, context, options);
633635

634-
Map<String, Object> evaluatedFeature = new HashMap<>();
635-
evaluatedFeature.put("enabled", Boolean.TRUE.equals(flagEvaluation.getEnabled()));
636+
EvaluatedFeature evaluatedFeature = new EvaluatedFeature();
637+
evaluatedFeature.setEnabled(Boolean.TRUE.equals(flagEvaluation.getEnabled()));
636638

637639
OverrideOptions opts = new OverrideOptions()
638640
.sticky(options.getSticky())
@@ -644,7 +646,7 @@ public Map<String, Object> getAllEvaluations(Map<String, Object> context, List<S
644646
if (this.datafileReader.hasVariations(featureKey)) {
645647
Object variation = getVariation(featureKey, context, opts);
646648
if (variation != null) {
647-
evaluatedFeature.put("variation", variation);
649+
evaluatedFeature.setVariation(variation.toString());
648650
}
649651
}
650652

@@ -657,75 +659,24 @@ public Map<String, Object> getAllEvaluations(Map<String, Object> context, List<S
657659
variables.put(variableKey, getVariable(featureKey, variableKey, context, opts));
658660
}
659661

660-
evaluatedFeature.put("variables", variables);
662+
evaluatedFeature.setVariables(variables);
661663
}
662664

663665
result.put(featureKey, evaluatedFeature);
664666
}
665667

666-
return result;
668+
return EvaluatedFeatures.of(result);
667669
}
668670

669-
public Map<String, Object> getAllEvaluations(Map<String, Object> context, List<String> featureKeys) {
671+
public EvaluatedFeatures getAllEvaluations(Map<String, Object> context, List<String> featureKeys) {
670672
return getAllEvaluations(context, featureKeys, null);
671673
}
672674

673-
public Map<String, Object> getAllEvaluations(Map<String, Object> context) {
675+
public EvaluatedFeatures getAllEvaluations(Map<String, Object> context) {
674676
return getAllEvaluations(context, null, null);
675677
}
676678

677-
public Map<String, Object> getAllEvaluations() {
678-
return getAllEvaluations(getContext());
679-
}
680-
681-
// Static factory methods for direct function-like access
682-
/**
683-
* Create a new Featurevisor instance with default options
684-
* @return new Instance
685-
*/
686-
public static Instance createInstance() {
687-
return new Instance(new InstanceOptions());
688-
}
689-
690-
/**
691-
* Create a new Featurevisor instance with datafile
692-
* @param datafile the datafile content
693-
* @return new Instance
694-
*/
695-
public static Instance createInstance(DatafileContent datafile) {
696-
InstanceOptions options = new InstanceOptions();
697-
options.setDatafile(datafile);
698-
return new Instance(options);
699-
}
700-
701-
/**
702-
* Create a new Featurevisor instance with datafile string
703-
* @param datafileString JSON string of the datafile
704-
* @return new Instance
705-
*/
706-
public static Instance createInstance(String datafileString) {
707-
InstanceOptions options = new InstanceOptions();
708-
options.setDatafileString(datafileString);
709-
return new Instance(options);
710-
}
711-
712-
/**
713-
* Create a new Featurevisor instance with context
714-
* @param context the context map
715-
* @return new Instance
716-
*/
717-
public static Instance createInstance(Map<String, Object> context) {
718-
InstanceOptions options = new InstanceOptions();
719-
options.setContext(context);
720-
return new Instance(options);
721-
}
722-
723-
/**
724-
* Create a new Featurevisor instance with full options
725-
* @param options the instance options
726-
* @return new Instance
727-
*/
728-
public static Instance createInstance(InstanceOptions options) {
729-
return new Instance(options);
679+
public EvaluatedFeatures getAllEvaluations() {
680+
return getAllEvaluations(null, null, null);
730681
}
731682
}

src/test/java/com/featurevisor/sdk/ChildTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,10 @@ public void testCreateChildInstance() {
324324
assertTrue(childInstance.isEnabled("newFeature"));
325325

326326
// Test getAllEvaluations
327-
Map<String, Object> allEvaluations = childInstance.getAllEvaluations();
328-
assertTrue(allEvaluations.containsKey("test"));
329-
assertTrue(allEvaluations.containsKey("anotherTest"));
327+
com.featurevisor.types.EvaluatedFeatures allEvaluations = childInstance.getAllEvaluations();
328+
assertNotNull(allEvaluations.getValue());
329+
assertTrue(allEvaluations.getValue().containsKey("test"));
330+
assertTrue(allEvaluations.getValue().containsKey("anotherTest"));
330331

331332
// Test close
332333
childInstance.close();

src/test/java/com/featurevisor/sdk/InstanceTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,10 +1464,11 @@ public void testGetVariableComprehensive() {
14641464
);
14651465

14661466
// Test getAllEvaluations
1467-
Map<String, Object> evaluatedFeatures = sdk.getAllEvaluations(context);
1467+
com.featurevisor.types.EvaluatedFeatures evaluatedFeatures = sdk.getAllEvaluations(context);
14681468
assertNotNull(evaluatedFeatures);
1469-
assertTrue(evaluatedFeatures.containsKey("test"));
1470-
assertTrue(evaluatedFeatures.containsKey("anotherTest"));
1469+
assertNotNull(evaluatedFeatures.getValue());
1470+
assertTrue(evaluatedFeatures.getValue().containsKey("test"));
1471+
assertTrue(evaluatedFeatures.getValue().containsKey("anotherTest"));
14711472

14721473
assertEquals("treatment", sdk.getVariation("test", context));
14731474
assertEquals("control", sdk.getVariation("test", Map.of(

0 commit comments

Comments
 (0)