Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,24 +354,24 @@ private void track(@Nonnull String eventName,
return null;
}

public @Nullable Float getVariableFloat(@Nonnull String variableKey,
@Nonnull String userId,
boolean activateExperiment) throws UnknownLiveVariableException {
return getVariableFloat(variableKey, userId, Collections.<String, String>emptyMap(), activateExperiment);
public @Nullable Double getVariableDouble(@Nonnull String variableKey,
@Nonnull String userId,
boolean activateExperiment) throws UnknownLiveVariableException {
return getVariableDouble(variableKey, userId, Collections.<String, String>emptyMap(), activateExperiment);
}

public @Nullable Float getVariableFloat(@Nonnull String variableKey,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
boolean activateExperiment)
public @Nullable Double getVariableDouble(@Nonnull String variableKey,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
boolean activateExperiment)
throws UnknownLiveVariableException {

String variableValueString = getVariableString(variableKey, userId, attributes, activateExperiment);
if (variableValueString != null) {
try {
return Float.parseFloat(variableValueString);
return Double.parseDouble(variableValueString);
} catch (NumberFormatException e) {
logger.error("Variable value \"{}\" for live variable \"{}\" is not a float.", variableValueString,
logger.error("Variable value \"{}\" for live variable \"{}\" is not a double.", variableValueString,
variableKey);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public enum VariableType {
@SerializedName("string")
STRING ("string"),

@SerializedName("float")
FLOAT ("float");
@SerializedName("double")
DOUBLE ("double");

private final String variableType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,11 +1116,11 @@ public void getVariableBoolean() throws Exception {
}

/**
* Verify that {@link Optimizely#getVariableFloat(String, String, Map, boolean)} returns a float live variable
* Verify that {@link Optimizely#getVariableDouble(String, String, Map, boolean)} returns a double live variable
* value when an proper variable key is provided and dispatches an impression when activateExperiment is true.
*/
@Test
public void getVariableFloat() throws Exception {
public void getVariableDouble() throws Exception {
String datafile = validConfigJsonV3();
ProjectConfig projectConfig = validProjectConfigV3();

Expand All @@ -1135,9 +1135,9 @@ public void getVariableFloat() throws Exception {
.withBucketing(mockBucketer)
.build();

assertThat(optimizely.getVariableFloat("float_variable", "userId",
assertThat(optimizely.getVariableDouble("double_variable", "userId",
Collections.singletonMap("browser_type", "chrome"), true),
is(5.3f));
is(5.3));
verify(mockEventHandler).dispatchEvent(any(LogEvent.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ private static ProjectConfig generateValidProjectConfigV3() {
LiveVariable.VariableType.INTEGER),
new LiveVariable("3", "string_variable", "string_live_variable", LiveVariable.VariableStatus.ACTIVE,
LiveVariable.VariableType.STRING),
new LiveVariable("4", "float_variable", "13.37", LiveVariable.VariableStatus.ACTIVE,
LiveVariable.VariableType.FLOAT),
new LiveVariable("4", "double_variable", "13.37", LiveVariable.VariableStatus.ACTIVE,
LiveVariable.VariableType.DOUBLE),
new LiveVariable("5", "archived_variable", "True", LiveVariable.VariableStatus.ARCHIVED,
LiveVariable.VariableType.BOOLEAN),
new LiveVariable("6", "etag1_variable", "False", LiveVariable.VariableStatus.ACTIVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@
},
{
"id": "4",
"key": "float_variable",
"type": "float",
"key": "double_variable",
"type": "double",
"defaultValue": "13.37",
"status": "active"
},
Expand Down