Skip to content

Commit 6c8657d

Browse files
chore: various improvements as suggested by sonar (#797)
* various improvements as suggested by sonar Signed-off-by: Kavindu Dodanduwa <[email protected]> * revert clonable change Signed-off-by: Kavindu Dodanduwa <[email protected]> --------- Signed-off-by: Kavindu Dodanduwa <[email protected]>
1 parent 69f95b1 commit 6c8657d

File tree

8 files changed

+8
-14
lines changed

8 files changed

+8
-14
lines changed

src/main/java/dev/openfeature/sdk/EventSupport.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ static class HandlerStore {
163163

164164
private final Map<ProviderEvent, List<Consumer<EventDetails>>> handlerMap;
165165

166-
{
167-
handlerMap = new ConcurrentHashMap<ProviderEvent, List<Consumer<EventDetails>>>();
166+
HandlerStore() {
167+
handlerMap = new ConcurrentHashMap<>();
168168
handlerMap.put(ProviderEvent.PROVIDER_READY, new ArrayList<>());
169169
handlerMap.put(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, new ArrayList<>());
170170
handlerMap.put(ProviderEvent.PROVIDER_ERROR, new ArrayList<>());

src/main/java/dev/openfeature/sdk/ImmutableStructure.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ImmutableStructure(Map<String, Value> attributes) {
4040
.collect(HashMap::new,
4141
(accumulated, entry) -> accumulated.put(entry.getKey(),
4242
Optional.ofNullable(entry.getValue())
43-
.map(e -> e.clone())
43+
.map(Value::clone)
4444
.orElse(null)),
4545
HashMap::putAll)));
4646
}
@@ -70,7 +70,7 @@ public Map<String, Value> asMap() {
7070
.collect(HashMap::new,
7171
(accumulated, entry) -> accumulated.put(entry.getKey(),
7272
Optional.ofNullable(entry.getValue())
73-
.map(e -> e.clone())
73+
.map(Value::clone)
7474
.orElse(null)),
7575
HashMap::putAll);
7676
}

src/main/java/dev/openfeature/sdk/MutableContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public MutableStructure add(String ignoredKey, List<Value> ignoredValue) {
145145
return null;
146146
}
147147

148-
public MutableStructure add(String ignoredKey, MutableStructure ignoredValue) {
148+
public MutableStructure add(String ignoredKey, Structure ignoredValue) {
149149
return null;
150150
}
151151

src/main/java/dev/openfeature/sdk/MutableStructure.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public MutableStructure add(String key, Structure value) {
7575
return this;
7676
}
7777

78-
public <T> MutableStructure add(String key, List<Value> value) {
78+
public MutableStructure add(String key, List<Value> value) {
7979
attributes.put(key, new Value(value));
8080
return this;
8181
}

src/main/java/dev/openfeature/sdk/NoOpProvider.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ public ProviderState getState() {
1818

1919
@Override
2020
public Metadata getMetadata() {
21-
return new Metadata() {
22-
@Override
23-
public String getName() {
24-
return name;
25-
}
26-
};
21+
return () -> name;
2722
}
2823

2924
@Override

src/main/java/dev/openfeature/sdk/ProviderRepository.java

-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ private boolean isProviderRegistered(FeatureProvider provider) {
168168
private void shutdownProvider(FeatureProvider provider) {
169169
taskExecutor.submit(() -> {
170170
try {
171-
// detachProviderEvents(provider);
172171
provider.shutdown();
173172
} catch (Exception e) {
174173
log.error("Exception when shutting down feature provider {}", provider.getClass().getName(), e);

src/main/java/dev/openfeature/sdk/Value.java

-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ public Instant asInstant() {
266266
*
267267
* @return Value
268268
*/
269-
270269
@SneakyThrows
271270
@Override
272271
protected Value clone() {

src/main/java/dev/openfeature/sdk/providers/memory/InMemoryProvider.java

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public InMemoryProvider(Map<String, Flag<?>> flags) {
5252
* @param evaluationContext evaluation context
5353
* @throws Exception on error
5454
*/
55+
@Override
5556
public void initialize(EvaluationContext evaluationContext) throws Exception {
5657
super.initialize(evaluationContext);
5758
state = ProviderState.READY;

0 commit comments

Comments
 (0)