Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Fixing codacy - ConcurrentHashMap - CoreFeature #223

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 18 additions & 16 deletions sdk-java/src/main/java/ly/count/sdk/java/internal/CoreFeature.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ly.count.sdk.java.internal;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public enum CoreFeature {
Events(1 << 1, ModuleEvents::new),
Expand Down Expand Up @@ -30,6 +30,8 @@ public enum CoreFeature {

private ModuleBaseCreator creator;

private static final Map<Integer, CoreFeature> featureMap = new ConcurrentHashMap<>();

CoreFeature(int index) {
this.index = index;
}
Expand All @@ -47,21 +49,21 @@ public int getIndex() {
return index;
}

private static final Map<Integer, CoreFeature> featureMap = new HashMap<Integer, CoreFeature>() {{
put(Sessions.index, Sessions);
put(Events.index, Events);
put(Views.index, Views);
put(CrashReporting.index, CrashReporting);
put(Location.index, Location);
put(UserProfiles.index, UserProfiles);
put(BackendMode.index, BackendMode);
put(RemoteConfig.index, RemoteConfig);
put(TestDummy.index, TestDummy);
put(DeviceId.index, DeviceId);
put(Requests.index, Requests);
put(Logs.index, Logs);
put(Feedback.index, Feedback);
}};
static void setupFeatureIndices() {
featureMap.put(Sessions.index, Sessions);
featureMap.put(Events.index, Events);
featureMap.put(Views.index, Views);
featureMap.put(CrashReporting.index, CrashReporting);
featureMap.put(Location.index, Location);
featureMap.put(UserProfiles.index, UserProfiles);
featureMap.put(BackendMode.index, BackendMode);
featureMap.put(RemoteConfig.index, RemoteConfig);
featureMap.put(TestDummy.index, TestDummy);
featureMap.put(DeviceId.index, DeviceId);
featureMap.put(Requests.index, Requests);
featureMap.put(Logs.index, Logs);
featureMap.put(Feedback.index, Feedback);
}

static CoreFeature byIndex(int index) {
return featureMap.get(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ protected void prepareMappings(InternalConfig config) throws IllegalStateExcepti
}

moduleMappings.clear();
CoreFeature.setupFeatureIndices();
registerDefaultModuleMappings();

for (int feature : config.getModuleOverrides()) {
Expand Down