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

Commit a8f5832

Browse files
committed
Merge pull request #40 from launchdarkly/dr/java7Syntax
Syntax changes for Java7
2 parents 3f64c2e + 9fb7dcc commit a8f5832

File tree

15 files changed

+43
-59
lines changed

15 files changed

+43
-59
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.launchdarkly.client;
22

33
import com.google.gson.JsonElement;
4-
import com.google.gson.JsonObject;
54

65
class CustomEvent extends Event {
76
private final JsonElement data;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.launchdarkly.client;
22

33
import com.google.gson.Gson;
4-
import org.apache.http.HttpResponse;
54
import org.apache.http.HttpStatus;
65
import org.apache.http.client.methods.CloseableHttpResponse;
76
import org.apache.http.client.methods.HttpPost;
@@ -25,7 +24,7 @@ class EventProcessor implements Closeable {
2524

2625
EventProcessor(String apiKey, LDConfig config) {
2726
this.apiKey = apiKey;
28-
this.queue = new ArrayBlockingQueue<Event>(config.capacity);
27+
this.queue = new ArrayBlockingQueue<>(config.capacity);
2928
this.consumer = new Consumer(config);
3029
this.scheduler.scheduleAtFixedRate(consumer, 0, config.flushInterval, TimeUnit.SECONDS);
3130
}
@@ -70,7 +69,7 @@ public void run() {
7069
}
7170

7271
public void flush() {
73-
List<Event> events = new ArrayList<Event>(queue.size());
72+
List<Event> events = new ArrayList<>(queue.size());
7473
queue.drainTo(events);
7574

7675
if (!events.isEmpty()) {

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.List;
1515
import java.util.concurrent.*;
1616
import java.util.concurrent.atomic.AtomicReference;
17-
import java.util.logging.Level;
1817

1918
// EventSource class modified from
2019
// https://github.com/jersey/jersey/blob/master/media/sse/src/main/java/org/glassfish/jersey/media/sse/EventSource.java
@@ -55,15 +54,15 @@ private static enum State {
5554
/**
5655
* Event source internal state.
5756
*/
58-
private final AtomicReference<State> state = new AtomicReference<State>(State.READY);
57+
private final AtomicReference<State> state = new AtomicReference<>(State.READY);
5958
/**
6059
* List of all listeners not bound to receive only events of a particular name.
6160
*/
62-
private final List<EventListener> unboundListeners = new CopyOnWriteArrayList<EventListener>();
61+
private final List<EventListener> unboundListeners = new CopyOnWriteArrayList<>();
6362
/**
6463
* A map of listeners bound to receive only events of a particular name.
6564
*/
66-
private final ConcurrentMap<String, List<EventListener>> boundListeners = new ConcurrentHashMap<String, List<EventListener>>();
65+
private final ConcurrentMap<String, List<EventListener>> boundListeners = new ConcurrentHashMap<>();
6766

6867
private final MultivaluedMap<String, Object> headers;
6968

@@ -96,7 +95,7 @@ private Builder(final WebTarget endpoint) {
9695
this.endpoint = endpoint;
9796
}
9897

99-
private MultivaluedMap<String, Object> headers = new StringKeyIgnoreCaseMultivaluedMap<Object>();
98+
private MultivaluedMap<String, Object> headers = new StringKeyIgnoreCaseMultivaluedMap<>();
10099

101100
/**
102101
* Set a custom name for the event source.
@@ -233,7 +232,7 @@ public static Builder target(WebTarget endpoint) {
233232
* @throws NullPointerException in case the supplied web target is {@code null}.
234233
*/
235234
public EventSource(final WebTarget endpoint) {
236-
this(endpoint, true, new StringKeyIgnoreCaseMultivaluedMap<Object>());
235+
this(endpoint, true, new StringKeyIgnoreCaseMultivaluedMap<>());
237236
}
238237

239238
/**
@@ -293,7 +292,7 @@ public Thread newThread(Runnable r) {
293292
}
294293
});
295294

296-
this.headers = new StringKeyIgnoreCaseMultivaluedMap<Object>();
295+
this.headers = new StringKeyIgnoreCaseMultivaluedMap<>();
297296
this.headers.putAll(headers);
298297

299298
if (open) {
@@ -373,7 +372,7 @@ public void register(final EventListener listener, final String eventName, final
373372

374373
private void addBoundListener(final String name, final EventListener listener) {
375374
List<EventListener> listeners = boundListeners.putIfAbsent(name,
376-
new CopyOnWriteArrayList<EventListener>(Collections.singleton(listener)));
375+
new CopyOnWriteArrayList<>(Collections.singleton(listener)));
377376
if (listeners != null) {
378377
// alas, new listener collection registration conflict:
379378
// need to add the new listener to the existing listener collection

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public int hashCode() {
7070
this.on = b.on;
7171
this.deleted = b.deleted;
7272
this.version = b.version;
73-
this.variations = new ArrayList<Variation<E>>(b.variations);
73+
this.variations = new ArrayList<>(b.variations);
7474
}
7575

7676
private Float paramForUser(LDUser user) {
@@ -147,7 +147,7 @@ static class Builder<E> {
147147
this.name = name;
148148
this.key = key;
149149
this.salt = UUID.randomUUID().toString();
150-
this.variations = new ArrayList<Variation<E>>();
150+
this.variations = new ArrayList<>();
151151
}
152152

153153
Builder<E> salt(String s) {
@@ -176,7 +176,7 @@ Builder<E> version(int v) {
176176
}
177177

178178
FeatureRep<E> build() {
179-
return new FeatureRep<E>(this);
179+
return new FeatureRep<>(this);
180180
}
181181

182182
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.launchdarkly.client;
22

3-
import com.google.gson.JsonObject;
4-
53
class IdentifyEvent extends Event {
64

75
IdentifyEvent(LDUser user) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public class InMemoryFeatureStore implements FeatureStore {
1414

1515
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
16-
final Map<String, FeatureRep<?>> features = new HashMap<String, FeatureRep<?>>();
16+
final Map<String, FeatureRep<?>> features = new HashMap<>();
1717
volatile boolean initialized = false;
1818

1919

@@ -52,7 +52,7 @@ public FeatureRep<?> get(String key) {
5252
public Map<String, FeatureRep<?>> all() {
5353
try {
5454
lock.readLock().lock();
55-
Map<String, FeatureRep<?>> fs = new HashMap<String, FeatureRep<?>>();
55+
Map<String, FeatureRep<?>> fs = new HashMap<>();
5656

5757
for (Map.Entry<String, FeatureRep<?>> entry : features.entrySet()) {
5858
if (!entry.getValue().deleted) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void identify(LDUser user) {
116116
}
117117

118118
private void sendFlagRequestEvent(String featureKey, LDUser user, boolean value, boolean defaultValue) {
119-
boolean processed = eventProcessor.sendEvent(new FeatureRequestEvent<Boolean>(featureKey, user, value, defaultValue));
119+
boolean processed = eventProcessor.sendEvent(new FeatureRequestEvent<>(featureKey, user, value, defaultValue));
120120
if (!processed) {
121121
logger.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.");
122122
}
@@ -174,9 +174,8 @@ public boolean toggle(String featureKey, LDUser user, boolean defaultValue) {
174174
sendFlagRequestEvent(featureKey, user, defaultValue, defaultValue);
175175
return defaultValue;
176176
} else {
177-
boolean value = val.booleanValue();
178-
sendFlagRequestEvent(featureKey, user, value, defaultValue);
179-
return value;
177+
sendFlagRequestEvent(featureKey, user, val, defaultValue);
178+
return val;
180179
}
181180
} catch (Exception e) {
182181
logger.error("Encountered exception in LaunchDarkly client", e);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,8 +2131,8 @@ enum Assignment
21312131
}
21322132

21332133

2134-
private static final Map<String, LDCountryCode> alpha3Map = new HashMap<String, LDCountryCode>();
2135-
private static final Map<Integer, LDCountryCode> numericMap = new HashMap<Integer, LDCountryCode>();
2134+
private static final Map<String, LDCountryCode> alpha3Map = new HashMap<>();
2135+
private static final Map<Integer, LDCountryCode> numericMap = new HashMap<>();
21362136

21372137

21382138
static
@@ -2640,7 +2640,7 @@ public static List<LDCountryCode> findByName(Pattern pattern)
26402640
throw new IllegalArgumentException("pattern is null.");
26412641
}
26422642

2643-
List<LDCountryCode> list = new ArrayList<LDCountryCode>();
2643+
List<LDCountryCode> list = new ArrayList<>();
26442644

26452645
for (LDCountryCode entry : values())
26462646
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected LDUser(Builder builder) {
5454
this.name = builder.name == null ? null : new JsonPrimitive(builder.name);
5555
this.avatar = builder.avatar == null ? null : new JsonPrimitive(builder.avatar);
5656
this.anonymous = builder.anonymous == null ? null : new JsonPrimitive(builder.anonymous);
57-
this.custom = new HashMap<String, JsonElement>(builder.custom);
57+
this.custom = new HashMap<>(builder.custom);
5858
}
5959

6060
/**
@@ -63,7 +63,7 @@ protected LDUser(Builder builder) {
6363
*/
6464
public LDUser(String key) {
6565
this.key = new JsonPrimitive(key);
66-
this.custom = new HashMap<String, JsonElement>();
66+
this.custom = new HashMap<>();
6767
}
6868

6969
JsonPrimitive getKey() {
@@ -123,7 +123,7 @@ public static class Builder {
123123
*/
124124
public Builder(String key) {
125125
this.key = key;
126-
this.custom = new HashMap<String, JsonElement>();
126+
this.custom = new HashMap<>();
127127
}
128128

129129
/**

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ final class NewRelicReflector {
1818
try {
1919
newRelic = Class.forName("com.newrelic.api.agent.NewRelic");
2020
addCustomParameter = newRelic.getDeclaredMethod("addCustomParameter", String.class, String.class);
21-
} catch (ClassNotFoundException e) {
22-
logger.info("No NewRelic agent detected");
23-
} catch (NoSuchMethodException e) {
21+
} catch (ClassNotFoundException | NoSuchMethodException e) {
2422
logger.info("No NewRelic agent detected");
2523
}
2624
}

0 commit comments

Comments
 (0)