Skip to content

Commit 47c752d

Browse files
committed
various improvements as suggested by sonar
Signed-off-by: Kavindu Dodanduwa <[email protected]>
1 parent 69f95b1 commit 47c752d

File tree

8 files changed

+12
-19
lines changed

8 files changed

+12
-19
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

+3-3
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::copy)
4444
.orElse(null)),
4545
HashMap::putAll)));
4646
}
@@ -54,7 +54,7 @@ public Set<String> keySet() {
5454
@Override
5555
public Value getValue(String key) {
5656
Value value = this.attributes.get(key);
57-
return value != null ? value.clone() : null;
57+
return value != null ? value.copy() : null;
5858
}
5959

6060
/**
@@ -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::copy)
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

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@ToString
2121
@EqualsAndHashCode
2222
@SuppressWarnings({"PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType", "checkstyle:NoFinalizer"})
23-
public class Value implements Cloneable {
23+
public class Value {
2424

2525
private final Object innerObject;
2626

@@ -262,14 +262,12 @@ public Instant asInstant() {
262262
}
263263

264264
/**
265-
* Perform deep clone of value object.
265+
* Perform a deep copy of this value.
266266
*
267267
* @return Value
268268
*/
269-
270269
@SneakyThrows
271-
@Override
272-
protected Value clone() {
270+
protected Value copy() {
273271
if (this.isList()) {
274272
List<Value> copy = this.asList().stream().map(Value::new).collect(Collectors.toList());
275273
return new Value(copy);

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)