Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 462e8ab

Browse files
authored
Merge pull request #64 from launchdarkly/dr/deprecateToggle
Deprecate toggle method. Update readme.
2 parents 2147e44 + c616e37 commit 462e8ab

File tree

3 files changed

+16
-42
lines changed

3 files changed

+16
-42
lines changed

README.md

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,14 @@ Your first feature flag
2929
2. In your application code, use the feature's key to check wthether the flag is on for each user:
3030

3131
LDUser user = new LDUser(username);
32-
boolean showFeature = ldClient.toggle("your.feature.key", user, false);
32+
boolean showFeature = ldClient.boolVariation("your.feature.key", user, false);
3333
if (showFeature) {
3434
// application code to show the feature
3535
}
3636
else {
3737
// the code to run if the feature is off
3838
}
3939

40-
Troubleshooting
41-
---------------
42-
1. Json parsing exception: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was....ExceptionType: com.google.gson.JsonSyntaxException
43-
Make sure your build tool is bringing in the proper version of Gson. The LaunchDarkly SDK may have problems with versions earlier than 2.2.4. To enforce the proper version add this dependency:
44-
```
45-
<dependency>
46-
<groupId>com.google.code.gson</groupId>
47-
<artifactId>gson</artifactId>
48-
<version>2.2.4</version>
49-
</dependency>
50-
```
51-
52-
1. SSL exceptions when calling toggle():
53-
Make sure your build tool is bringing in the proper version of the Apache http client. The LaunchDarkly SDK may have problems with versions earlier than 3.3.6. To enforce the proper version add this dependency:
54-
```
55-
<dependency>
56-
<groupId>org.apache.httpcomponents</groupId>
57-
<artifactId>httpclient</artifactId>
58-
<version>4.3.6</version>
59-
</dependency>
60-
```
61-
6240
Learn more
6341
----------
6442

src/main/java/com/launchdarkly/client/LDClient.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,6 @@ private void sendFlagRequestEvent(String featureKey, LDUser user, JsonElement va
173173
NewRelicReflector.annotateTransaction(featureKey, String.valueOf(value));
174174
}
175175

176-
/**
177-
* Calculates the boolean value of a feature flag for a given user.
178-
*
179-
* @param featureKey the unique featureKey for the feature flag
180-
* @param user the end user requesting the flag
181-
* @param defaultValue the default value of the flag
182-
* @return whether or not the flag should be enabled, or {@code defaultValue} if the flag is disabled in the LaunchDarkly control panel
183-
* @deprecated As of version 0.7.0, renamed to {@link #toggle(String, LDUser, boolean)}
184-
*/
185-
public boolean getFlag(String featureKey, LDUser user, boolean defaultValue) {
186-
return toggle(featureKey, user, defaultValue);
187-
}
188-
189176
/**
190177
* Returns a map from feature flag keys to Boolean feature flag values for a given user. The map will contain {@code null}
191178
* entries for any flags that are off or for any feature flags with non-boolean variations. If the client is offline or
@@ -227,14 +214,23 @@ public Map<String, Boolean> allFlags(LDUser user) {
227214
* @param defaultValue the default value of the flag
228215
* @return whether or not the flag should be enabled, or {@code defaultValue} if the flag is disabled in the LaunchDarkly control panel
229216
*/
230-
public boolean toggle(String featureKey, LDUser user, boolean defaultValue) {
217+
public boolean boolVariation(String featureKey, LDUser user, boolean defaultValue) {
231218
JsonElement value = jsonVariation(featureKey, user, new JsonPrimitive(defaultValue));
232219
if (value.isJsonPrimitive() && value.getAsJsonPrimitive().isBoolean()) {
233220
return value.getAsJsonPrimitive().getAsBoolean();
234221
}
235222
return false;
236223
}
237224

225+
/**
226+
* @deprecated use {@link #boolVariation(String, LDUser, boolean)}
227+
*/
228+
@Deprecated
229+
public boolean toggle(String featureKey, LDUser user, boolean defaultValue) {
230+
logger.warn("Deprecated method: Toggle() called. Use boolVariation() instead.");
231+
return boolVariation(featureKey, user, defaultValue);
232+
}
233+
238234
/**
239235
* Calculates the integer value of a feature flag for a given user.
240236
*

src/test/java/com/launchdarkly/client/LDClientTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void testTestFeatureStoreSetFeatureTrue() throws IOException, Interrupted
6666

6767
client = createMockClient(config);
6868
testFeatureStore.setFeatureTrue("key");
69-
assertTrue("Test flag should be true, but was not.", client.toggle("key", new LDUser("user"), false));
69+
assertTrue("Test flag should be true, but was not.", client.boolVariation("key", new LDUser("user"), false));
7070

7171
verifyAll();
7272
}
@@ -88,7 +88,7 @@ public void testTestFeatureStoreSetFalse() throws IOException, InterruptedExcept
8888

8989
client = createMockClient(config);
9090
testFeatureStore.setFeatureFalse("key");
91-
assertFalse("Test flag should be false, but was on (the default).", client.toggle("key", new LDUser("user"), true));
91+
assertFalse("Test flag should be false, but was on (the default).", client.boolVariation("key", new LDUser("user"), true));
9292

9393
verifyAll();
9494
}
@@ -111,10 +111,10 @@ public void testTestFeatureStoreFlagTrueThenFalse() throws IOException, Interrup
111111
client = createMockClient(config);
112112

113113
testFeatureStore.setFeatureTrue("key");
114-
assertTrue("Test flag should be true, but was not.", client.toggle("key", new LDUser("user"), false));
114+
assertTrue("Test flag should be true, but was not.", client.boolVariation("key", new LDUser("user"), false));
115115

116116
testFeatureStore.setFeatureFalse("key");
117-
assertFalse("Test flag should be false, but was on (the default).", client.toggle("key", new LDUser("user"), true));
117+
assertFalse("Test flag should be false, but was on (the default).", client.boolVariation("key", new LDUser("user"), true));
118118

119119
verifyAll();
120120
}
@@ -342,7 +342,7 @@ public void testPollingWait() throws Exception {
342342
}
343343

344344
private void assertDefaultValueIsReturned() {
345-
boolean result = client.toggle("test", new LDUser("test.key"), true);
345+
boolean result = client.boolVariation("test", new LDUser("test.key"), true);
346346
assertEquals(true, result);
347347
}
348348

0 commit comments

Comments
 (0)