Skip to content

Commit cb434c6

Browse files
committed
rename from Instance to FeaturevisorInstance
1 parent d7f7092 commit cb434c6

7 files changed

Lines changed: 101 additions & 101 deletions

File tree

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ See example application here: [https://github.com/featurevisor/featurevisor-exam
117117
The SDK can be initialized by passing [datafile](https://featurevisor.com/docs/building-datafiles/) content directly:
118118

119119
```java
120-
import com.featurevisor.sdk.Instance;
120+
import com.featurevisor.sdk.FeaturevisorInstance;
121121
import com.featurevisor.types.DatafileContent;
122122

123123
// Load datafile content
@@ -128,8 +128,8 @@ String datafileContent = "..." // ... load your datafile content
128128
DatafileContent datafile = DatafileContent.fromJson(datafileContent);
129129

130130
// Create SDK instance
131-
Instance f = new Instance(
132-
new Instance.InstanceOptions()
131+
FeaturevisorInstance f = new FeaturevisorInstance(
132+
new FeaturevisorInstance.InstanceOptions()
133133
.datafile(datafileContent)
134134
);
135135
```
@@ -170,7 +170,7 @@ Map<String, Object> initialContext = new HashMap<>();
170170
initialContext.put("deviceId", "123");
171171
initialContext.put("country", "nl");
172172

173-
Instance f = new Instance(new Instance.InstanceOptions()
173+
FeaturevisorInstance f = new FeaturevisorInstance(new FeaturevisorInstance.InstanceOptions()
174174
.datafile(datafile)
175175
.context(initialContext));
176176
```
@@ -357,7 +357,7 @@ Map<String, Object> anotherFeatureSticky = new HashMap<>();
357357
anotherFeatureSticky.put("enabled", false);
358358
stickyFeatures.put("anotherFeatureKey", anotherFeatureSticky);
359359

360-
Instance f = new Instance(new Instance.InstanceOptions()
360+
FeaturevisorInstance f = new FeaturevisorInstance(new FeaturevisorInstance.InstanceOptions()
361361
.datafile(datafile)
362362
.sticky(stickyFeatures));
363363
```
@@ -433,7 +433,7 @@ Setting `debug` level will print out all logs, including `info`, `warn`, and `er
433433
```java
434434
import com.featurevisor.sdk.Logger;
435435

436-
Instance f = new Instance(new Instance.InstanceOptions()
436+
FeaturevisorInstance f = new FeaturevisorInstance(new FeaturevisorInstance.InstanceOptions()
437437
.datafile(datafile)
438438
.logLevel(Logger.LogLevel.DEBUG));
439439
```
@@ -457,7 +457,7 @@ Logger customLogger = Logger.createLogger(new Logger.CreateLoggerOptions()
457457
System.out.println("[" + level + "] " + message);
458458
}));
459459

460-
Instance f = new Instance(new Instance.InstanceOptions()
460+
FeaturevisorInstance f = new FeaturevisorInstance(new FeaturevisorInstance.InstanceOptions()
461461
.datafile(datafile)
462462
.logger(customLogger));
463463
```
@@ -470,7 +470,7 @@ Logger customLogger = new Logger(Logger.LogLevel.INFO, (level, message, details)
470470
System.out.println("[" + level + "] " + message);
471471
});
472472

473-
Instance f = new Instance(new Instance.InstanceOptions()
473+
FeaturevisorInstance f = new FeaturevisorInstance(new FeaturevisorInstance.InstanceOptions()
474474
.datafile(datafile)
475475
.logger(customLogger));
476476
```
@@ -637,7 +637,7 @@ You can register hooks at the time of SDK initialization:
637637
List<Map<String, Object>> hooks = new ArrayList<>();
638638
hooks.add(myCustomHook);
639639

640-
Instance f = new Instance(new Instance.InstanceOptions()
640+
FeaturevisorInstance f = new FeaturevisorInstance(new FeaturevisorInstance.InstanceOptions()
641641
.datafile(datafile)
642642
.hooks(hooks));
643643
```
@@ -662,7 +662,7 @@ That's where child instances come in handy:
662662
Map<String, Object> childContext = new HashMap<>();
663663
childContext.put("userId", "123");
664664

665-
Instance childF = f.spawn(childContext);
665+
FeaturevisorInstance childF = f.spawn(childContext);
666666
```
667667

668668
Now you can pass the child instance where your individual request is being handled, and you can continue to evaluate features targeting that specific user alone:

src/main/java/com/featurevisor/cli/CLI.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import picocli.CommandLine.Parameters;
77

88
import com.featurevisor.sdk.Featurevisor;
9-
import com.featurevisor.sdk.Instance;
9+
import com.featurevisor.sdk.FeaturevisorInstance;
1010
import com.featurevisor.sdk.Logger;
1111
import com.featurevisor.sdk.DatafileReader;
1212
import com.featurevisor.types.DatafileContent;
@@ -250,9 +250,9 @@ private TestResult testFeature(Map<String, Object> assertion, String featureKey,
250250
Map<String, Object> sticky = (Map<String, Object>) assertion.getOrDefault("sticky", new HashMap<>());
251251

252252
// Update the SDK instance context and sticky values for this assertion
253-
if (f instanceof Instance) {
254-
((Instance) f).setContext(context, true);
255-
((Instance) f).setSticky(sticky, true);
253+
if (f instanceof FeaturevisorInstance) {
254+
((FeaturevisorInstance) f).setContext(context, true);
255+
((FeaturevisorInstance) f).setSticky(sticky, true);
256256
} else if (f instanceof com.featurevisor.sdk.ChildInstance) {
257257
((com.featurevisor.sdk.ChildInstance) f).setContext(context, true);
258258
((com.featurevisor.sdk.ChildInstance) f).setSticky(sticky, true);
@@ -274,7 +274,7 @@ private TestResult testFeature(Map<String, Object> assertion, String featureKey,
274274

275275
// Test expectedVariation
276276
if (assertion.containsKey("expectedVariation")) {
277-
Instance.OverrideOptions options = new Instance.OverrideOptions();
277+
FeaturevisorInstance.OverrideOptions options = new FeaturevisorInstance.OverrideOptions();
278278
if (assertion.containsKey("defaultVariationValue")) {
279279
options.setDefaultVariationValue(assertion.get("defaultVariationValue").toString());
280280
}
@@ -308,7 +308,7 @@ private TestResult testFeature(Map<String, Object> assertion, String featureKey,
308308
}
309309
}
310310

311-
Instance.OverrideOptions options = new Instance.OverrideOptions();
311+
FeaturevisorInstance.OverrideOptions options = new FeaturevisorInstance.OverrideOptions();
312312
if (defaultVariableValues.containsKey(variableKey)) {
313313
options.setDefaultVariableValue(defaultVariableValues.get(variableKey));
314314
}
@@ -347,7 +347,7 @@ private TestResult testFeature(Map<String, Object> assertion, String featureKey,
347347
if (expectedEvaluations.containsKey("variation")) {
348348
@SuppressWarnings("unchecked")
349349
Map<String, Object> variationEvaluation = (Map<String, Object>) expectedEvaluations.get("variation");
350-
Instance.OverrideOptions options = new Instance.OverrideOptions();
350+
FeaturevisorInstance.OverrideOptions options = new FeaturevisorInstance.OverrideOptions();
351351
if (assertion.containsKey("defaultVariationValue")) {
352352
options.setDefaultVariationValue(assertion.get("defaultVariationValue").toString());
353353
}
@@ -378,7 +378,7 @@ private TestResult testFeature(Map<String, Object> assertion, String featureKey,
378378
@SuppressWarnings("unchecked")
379379
Map<String, Object> expectedEvaluation = (Map<String, Object>) entry.getValue();
380380

381-
Instance.OverrideOptions options = new Instance.OverrideOptions();
381+
FeaturevisorInstance.OverrideOptions options = new FeaturevisorInstance.OverrideOptions();
382382
if (defaultVariableValues.containsKey(variableKey)) {
383383
options.setDefaultVariableValue(defaultVariableValues.get(variableKey));
384384
}
@@ -427,55 +427,55 @@ private TestResult testFeature(Map<String, Object> assertion, String featureKey,
427427
* Helper methods to work with both Instance and ChildInstance
428428
*/
429429
private boolean isEnabled(Object f, String featureKey, Map<String, Object> context) {
430-
if (f instanceof Instance) {
431-
return ((Instance) f).isEnabled(featureKey, context);
430+
if (f instanceof FeaturevisorInstance) {
431+
return ((FeaturevisorInstance) f).isEnabled(featureKey, context);
432432
} else if (f instanceof com.featurevisor.sdk.ChildInstance) {
433433
return ((com.featurevisor.sdk.ChildInstance) f).isEnabled(featureKey, context);
434434
}
435435
return false;
436436
}
437437

438-
private Object getVariation(Object f, String featureKey, Map<String, Object> context, Instance.OverrideOptions options) {
439-
if (f instanceof Instance) {
440-
return ((Instance) f).getVariation(featureKey, context, options);
438+
private Object getVariation(Object f, String featureKey, Map<String, Object> context, FeaturevisorInstance.OverrideOptions options) {
439+
if (f instanceof FeaturevisorInstance) {
440+
return ((FeaturevisorInstance) f).getVariation(featureKey, context, options);
441441
} else if (f instanceof com.featurevisor.sdk.ChildInstance) {
442442
return ((com.featurevisor.sdk.ChildInstance) f).getVariation(featureKey, context, options);
443443
}
444444
return null;
445445
}
446446

447-
private Object getVariable(Object f, String featureKey, String variableKey, Map<String, Object> context, Instance.OverrideOptions options) {
448-
if (f instanceof Instance) {
449-
return ((Instance) f).getVariable(featureKey, variableKey, context, options);
447+
private Object getVariable(Object f, String featureKey, String variableKey, Map<String, Object> context, FeaturevisorInstance.OverrideOptions options) {
448+
if (f instanceof FeaturevisorInstance) {
449+
return ((FeaturevisorInstance) f).getVariable(featureKey, variableKey, context, options);
450450
} else if (f instanceof com.featurevisor.sdk.ChildInstance) {
451451
return ((com.featurevisor.sdk.ChildInstance) f).getVariable(featureKey, variableKey, context, options);
452452
}
453453
return null;
454454
}
455455

456456
private com.featurevisor.sdk.Evaluation evaluateFlag(Object f, String featureKey, Map<String, Object> context) {
457-
if (f instanceof Instance) {
458-
return ((Instance) f).evaluateFlag(featureKey, context);
457+
if (f instanceof FeaturevisorInstance) {
458+
return ((FeaturevisorInstance) f).evaluateFlag(featureKey, context);
459459
} else if (f instanceof com.featurevisor.sdk.ChildInstance) {
460460
// ChildInstance doesn't have evaluateFlag, so we'll skip this test for child instances
461461
return null;
462462
}
463463
return null;
464464
}
465465

466-
private com.featurevisor.sdk.Evaluation evaluateVariation(Object f, String featureKey, Map<String, Object> context, Instance.OverrideOptions options) {
467-
if (f instanceof Instance) {
468-
return ((Instance) f).evaluateVariation(featureKey, context, options);
466+
private com.featurevisor.sdk.Evaluation evaluateVariation(Object f, String featureKey, Map<String, Object> context, FeaturevisorInstance.OverrideOptions options) {
467+
if (f instanceof FeaturevisorInstance) {
468+
return ((FeaturevisorInstance) f).evaluateVariation(featureKey, context, options);
469469
} else if (f instanceof com.featurevisor.sdk.ChildInstance) {
470470
// ChildInstance doesn't have evaluateVariation, so we'll skip this test for child instances
471471
return null;
472472
}
473473
return null;
474474
}
475475

476-
private com.featurevisor.sdk.Evaluation evaluateVariable(Object f, String featureKey, String variableKey, Map<String, Object> context, Instance.OverrideOptions options) {
477-
if (f instanceof Instance) {
478-
return ((Instance) f).evaluateVariable(featureKey, variableKey, context, options);
476+
private com.featurevisor.sdk.Evaluation evaluateVariable(Object f, String featureKey, String variableKey, Map<String, Object> context, FeaturevisorInstance.OverrideOptions options) {
477+
if (f instanceof FeaturevisorInstance) {
478+
return ((FeaturevisorInstance) f).evaluateVariable(featureKey, variableKey, context, options);
479479
} else if (f instanceof com.featurevisor.sdk.ChildInstance) {
480480
// ChildInstance doesn't have evaluateVariable, so we'll skip this test for child instances
481481
return null;
@@ -484,8 +484,8 @@ private com.featurevisor.sdk.Evaluation evaluateVariable(Object f, String featur
484484
}
485485

486486
private com.featurevisor.sdk.ChildInstance spawn(Object f, Map<String, Object> context) {
487-
if (f instanceof Instance) {
488-
return ((Instance) f).spawn(context);
487+
if (f instanceof FeaturevisorInstance) {
488+
return ((FeaturevisorInstance) f).spawn(context);
489489
} else if (f instanceof com.featurevisor.sdk.ChildInstance) {
490490
// ChildInstance doesn't have spawn, so we'll return null
491491
return null;
@@ -577,11 +577,11 @@ private void test() {
577577
return;
578578
}
579579

580-
// Create SDK instances for each environment
581-
Map<String, Instance> sdkInstancesByEnvironment = new HashMap<>();
580+
// Create SDK instances for each environment
581+
Map<String, FeaturevisorInstance> sdkInstancesByEnvironment = new HashMap<>();
582582
for (String environment : environments) {
583583
DatafileContent datafile = datafilesByEnvironment.get(environment);
584-
Instance instance = Featurevisor.createInstance(new Instance.InstanceOptions()
584+
FeaturevisorInstance instance = Featurevisor.createInstance(new FeaturevisorInstance.InstanceOptions()
585585
.datafile(datafile)
586586
.logLevel(level));
587587
sdkInstancesByEnvironment.put(environment, instance);
@@ -610,7 +610,7 @@ private void test() {
610610

611611
if (test.containsKey("feature")) {
612612
String environment = (String) assertion.get("environment");
613-
Instance f = sdkInstancesByEnvironment.get(environment);
613+
FeaturevisorInstance f = sdkInstancesByEnvironment.get(environment);
614614

615615
// If "at" parameter is provided, create a new SDK instance with the specific hook
616616
if (assertion.containsKey("at")) {
@@ -631,7 +631,7 @@ private void test() {
631631
hooksManager.add(new HooksManager.Hook("at-parameter")
632632
.bucketValue((options) -> (int) (atValue * 1000)));
633633

634-
f = Featurevisor.createInstance(new Instance.InstanceOptions()
634+
f = Featurevisor.createInstance(new FeaturevisorInstance.InstanceOptions()
635635
.datafile(datafile)
636636
.logLevel(level)
637637
.hooks(hooksManager.getAll()));
@@ -710,7 +710,7 @@ private void benchmark() {
710710
Logger.LogLevel level = getLoggerLevel();
711711
Map<String, DatafileContent> datafilesByEnvironment = buildDatafiles(rootDirectoryPath, Arrays.asList(environment));
712712

713-
Instance f = Featurevisor.createInstance(new Instance.InstanceOptions()
713+
FeaturevisorInstance f = Featurevisor.createInstance(new FeaturevisorInstance.InstanceOptions()
714714
.datafile(datafilesByEnvironment.get(environment))
715715
.logLevel(level));
716716

@@ -773,7 +773,7 @@ private void assessDistribution() {
773773

774774
Map<String, DatafileContent> datafilesByEnvironment = buildDatafiles(rootDirectoryPath, Arrays.asList(environment));
775775

776-
Instance f = Featurevisor.createInstance(new Instance.InstanceOptions()
776+
FeaturevisorInstance f = Featurevisor.createInstance(new FeaturevisorInstance.InstanceOptions()
777777
.datafile(datafilesByEnvironment.get(environment))
778778
.logLevel(getLoggerLevel()));
779779

0 commit comments

Comments
 (0)