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] PMD_category_java_codestyle_FieldDeclarationsShouldBeAtStartOfClass #Codacy #245

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
303 changes: 152 additions & 151 deletions sdk-java/src/main/java/ly/count/sdk/java/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,136 +22,6 @@
* Countly configuration object.
*/
public class Config {
/**
* Logging level for {@link Log} module
*/
public enum LoggingLevel {
VERBOSE(0),
DEBUG(1),
INFO(2),
WARN(3),
ERROR(4),
OFF(5);

private final int level;

LoggingLevel(int level) {
this.level = level;
}

public int getLevel() {
return level;
}

public boolean prints(LoggingLevel l) {
return level <= l.level;
}
}

public enum DeviceIdStrategy {
UUID(0),
CUSTOM_ID(10);

private final int index;

DeviceIdStrategy(int level) {
this.index = level;
}

public int getIndex() {
return index;
}

public static DeviceIdStrategy fromIndex(int index) {
if (index == UUID.index) {
return UUID;
}
if (index == CUSTOM_ID.index) {
return CUSTOM_ID;
}
return null;
}
}

public enum Feature {
Events(CoreFeature.Events.getIndex()),
Sessions(CoreFeature.Sessions.getIndex()),
Views(CoreFeature.Views.getIndex()),
CrashReporting(CoreFeature.CrashReporting.getIndex()),
Location(CoreFeature.Location.getIndex()),
UserProfiles(CoreFeature.UserProfiles.getIndex()),
Feedback(CoreFeature.Feedback.getIndex()),
RemoteConfig(CoreFeature.RemoteConfig.getIndex());
// StarRating(1 << 12),
// PerformanceMonitoring(1 << 14);

private final int index;

Feature(int index) {
this.index = index;
}

public int getIndex() {
return index;
}

public static Config.Feature byIndex(int index) {
if (index == Events.index) {
return Events;
} else if (index == Sessions.index) {
return Sessions;
} else if (index == Views.index) {
return Views;
} else if (index == CrashReporting.index) {
return CrashReporting;
} else if (index == Location.index) {
return Location;
} else if (index == UserProfiles.index) {
return UserProfiles;
} else if (index == RemoteConfig.index) {
return RemoteConfig;
} else if (index == Feedback.index) {
return Feedback;
} else {
return null;
}
}
}

/**
* Holder class for various ids met
* adata and id itself. Final, unmodifiable.
*/
public static final class DID {
public static final int STRATEGY_UUID = 0;
public static final int STRATEGY_CUSTOM = 10;
public int strategy;
public String id;

public DID(int strategy, String id) {
this.strategy = strategy;
this.id = id;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof DID)) {
return false;
}
DID did = (DID) obj;
return did.strategy == strategy && Objects.equals(did.id, id);
}

@Override
public int hashCode() {
return id.hashCode();
}

@Override
public String toString() {
return "DID " + id + " ( " + strategy + ")";
}
}

protected Log configLog;

Expand Down Expand Up @@ -360,26 +230,7 @@ public String toString() {
*/
protected boolean unhandledCrashReportingEnabled = true;

/**
* Get the maximum amount of breadcrumbs. Default is 100.
*
* @param maxBreadcrumbCount the maximum amount of breadcrumbs
* @return {@code this} instance for method chaining
*/
public Config setMaxBreadcrumbCount(int maxBreadcrumbCount) {
this.maxBreadcrumbCount = maxBreadcrumbCount;
return this;
}

/**
* Disable automatic crash reporting for unhandled exceptions.
*
* @return {@code this} instance for method chaining
*/
public Config disableUnhandledCrashReporting() {
this.unhandledCrashReportingEnabled = false;
return this;
}
public ConfigViews views = new ConfigViews(this);

protected String location = null;
protected String ip = null;
Expand Down Expand Up @@ -425,6 +276,27 @@ public Config(String serverURL, String serverAppKey, File sdkStorageRootDirector
this.sdkStorageRootDirectory = sdkStorageRootDirectory;
}

/**
* Get the maximum amount of breadcrumbs. Default is 100.
*
* @param maxBreadcrumbCount the maximum amount of breadcrumbs
* @return {@code this} instance for method chaining
*/
public Config setMaxBreadcrumbCount(int maxBreadcrumbCount) {
this.maxBreadcrumbCount = maxBreadcrumbCount;
return this;
}

/**
* Disable automatic crash reporting for unhandled exceptions.
*
* @return {@code this} instance for method chaining
*/
public Config disableUnhandledCrashReporting() {
this.unhandledCrashReportingEnabled = false;
return this;
}

/**
* Whether to allow fallback from unavailable device id strategy to Countly OpenUDID derivative.
*
Expand Down Expand Up @@ -1458,5 +1330,134 @@ public Config disableLocation() {
return this;
}

public ConfigViews views = new ConfigViews(this);
/**
* Logging level for {@link Log} module
*/
public enum LoggingLevel {
VERBOSE(0),
DEBUG(1),
INFO(2),
WARN(3),
ERROR(4),
OFF(5);

private final int level;

LoggingLevel(int level) {
this.level = level;
}

public int getLevel() {
return level;
}

public boolean prints(LoggingLevel l) {
return level <= l.level;
}
}

public enum DeviceIdStrategy {
UUID(0),
CUSTOM_ID(10);

private final int index;

DeviceIdStrategy(int level) {
this.index = level;
}

public int getIndex() {
return index;
}

public static DeviceIdStrategy fromIndex(int index) {
if (index == UUID.index) {
return UUID;
}
if (index == CUSTOM_ID.index) {
return CUSTOM_ID;
}
return null;
}
}

public enum Feature {
Events(CoreFeature.Events.getIndex()),
Sessions(CoreFeature.Sessions.getIndex()),
Views(CoreFeature.Views.getIndex()),
CrashReporting(CoreFeature.CrashReporting.getIndex()),
Location(CoreFeature.Location.getIndex()),
UserProfiles(CoreFeature.UserProfiles.getIndex()),
Feedback(CoreFeature.Feedback.getIndex()),
RemoteConfig(CoreFeature.RemoteConfig.getIndex());
// StarRating(1 << 12),
// PerformanceMonitoring(1 << 14);

private final int index;

Feature(int index) {
this.index = index;
}

public int getIndex() {
return index;
}

public static Config.Feature byIndex(int index) {
if (index == Events.index) {
return Events;
} else if (index == Sessions.index) {
return Sessions;
} else if (index == Views.index) {
return Views;
} else if (index == CrashReporting.index) {
return CrashReporting;
} else if (index == Location.index) {
return Location;
} else if (index == UserProfiles.index) {
return UserProfiles;
} else if (index == RemoteConfig.index) {
return RemoteConfig;
} else if (index == Feedback.index) {
return Feedback;
} else {
return null;
}
}
}

/**
* Holder class for various ids met
* adata and id itself. Final, unmodifiable.
*/
public static final class DID {
public static final int STRATEGY_UUID = 0;
public static final int STRATEGY_CUSTOM = 10;
public int strategy;
public String id;

public DID(int strategy, String id) {
this.strategy = strategy;
this.id = id;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof DID)) {
return false;
}
DID did = (DID) obj;
return did.strategy == strategy && Objects.equals(did.id, id);
}

@Override
public int hashCode() {
return id.hashCode();
}

@Override
public String toString() {
return "DID " + id + " ( " + strategy + ")";
}
}
}
5 changes: 2 additions & 3 deletions sdk-java/src/main/java/ly/count/sdk/java/Countly.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class Countly implements Usage {
public static final Device device = Device.dev;

private static final Countly cly = SingletonHolder.INSTANCE;
protected SDKCore sdk;
protected Log L;

private static class SingletonHolder {
private static final Countly INSTANCE = new Countly();
Expand All @@ -49,9 +51,6 @@ private static void empty() {
}
}

protected SDKCore sdk;
protected Log L;

protected Countly(SDKCore sdk, final Log logger) {
L = logger;
this.sdk = sdk;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

public class ConfigViews {
private final Config config;
protected Map<String, Object> globalViewSegmentation = null;

public ConfigViews(Config config) {
this.config = config;
}

protected Map<String, Object> globalViewSegmentation = null;

/**
* @param segmentation segmentation values that will be added for all recorded views (manual and automatic)
* @return Returns the same config object for convenient linking
Expand Down
9 changes: 4 additions & 5 deletions sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public class Device {
private String orientation;
private Boolean online;
private Boolean muted;

private Log L;
protected static final Double NS_IN_SECOND = 1_000_000_000.0d;
protected static final Double NS_IN_MS = 1_000_000.0d;
protected static final Double MS_IN_SECOND = 1000d;
protected static final Long BYTES_IN_MB = 1024L * 1024;

private final Map<String, String> metricOverride = new ConcurrentHashMap<>();

Expand All @@ -44,10 +47,6 @@ public void setLog(Log L) {
/**
* One second in nanoseconds
*/
protected static final Double NS_IN_SECOND = 1_000_000_000.0d;
protected static final Double NS_IN_MS = 1_000_000.0d;
protected static final Double MS_IN_SECOND = 1000d;
protected static final Long BYTES_IN_MB = 1024L * 1024;

/**
* Get operation system name
Expand Down
Loading
Loading