Skip to content

Commit 812c14a

Browse files
refactor: reorder field declarations to the top (#245)
1 parent 5953ffb commit 812c14a

File tree

9 files changed

+203
-214
lines changed

9 files changed

+203
-214
lines changed

sdk-java/src/main/java/ly/count/sdk/java/Config.java

Lines changed: 152 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -22,136 +22,6 @@
2222
* Countly configuration object.
2323
*/
2424
public class Config {
25-
/**
26-
* Logging level for {@link Log} module
27-
*/
28-
public enum LoggingLevel {
29-
VERBOSE(0),
30-
DEBUG(1),
31-
INFO(2),
32-
WARN(3),
33-
ERROR(4),
34-
OFF(5);
35-
36-
private final int level;
37-
38-
LoggingLevel(int level) {
39-
this.level = level;
40-
}
41-
42-
public int getLevel() {
43-
return level;
44-
}
45-
46-
public boolean prints(LoggingLevel l) {
47-
return level <= l.level;
48-
}
49-
}
50-
51-
public enum DeviceIdStrategy {
52-
UUID(0),
53-
CUSTOM_ID(10);
54-
55-
private final int index;
56-
57-
DeviceIdStrategy(int level) {
58-
this.index = level;
59-
}
60-
61-
public int getIndex() {
62-
return index;
63-
}
64-
65-
public static DeviceIdStrategy fromIndex(int index) {
66-
if (index == UUID.index) {
67-
return UUID;
68-
}
69-
if (index == CUSTOM_ID.index) {
70-
return CUSTOM_ID;
71-
}
72-
return null;
73-
}
74-
}
75-
76-
public enum Feature {
77-
Events(CoreFeature.Events.getIndex()),
78-
Sessions(CoreFeature.Sessions.getIndex()),
79-
Views(CoreFeature.Views.getIndex()),
80-
CrashReporting(CoreFeature.CrashReporting.getIndex()),
81-
Location(CoreFeature.Location.getIndex()),
82-
UserProfiles(CoreFeature.UserProfiles.getIndex()),
83-
Feedback(CoreFeature.Feedback.getIndex()),
84-
RemoteConfig(CoreFeature.RemoteConfig.getIndex());
85-
// StarRating(1 << 12),
86-
// PerformanceMonitoring(1 << 14);
87-
88-
private final int index;
89-
90-
Feature(int index) {
91-
this.index = index;
92-
}
93-
94-
public int getIndex() {
95-
return index;
96-
}
97-
98-
public static Config.Feature byIndex(int index) {
99-
if (index == Events.index) {
100-
return Events;
101-
} else if (index == Sessions.index) {
102-
return Sessions;
103-
} else if (index == Views.index) {
104-
return Views;
105-
} else if (index == CrashReporting.index) {
106-
return CrashReporting;
107-
} else if (index == Location.index) {
108-
return Location;
109-
} else if (index == UserProfiles.index) {
110-
return UserProfiles;
111-
} else if (index == RemoteConfig.index) {
112-
return RemoteConfig;
113-
} else if (index == Feedback.index) {
114-
return Feedback;
115-
} else {
116-
return null;
117-
}
118-
}
119-
}
120-
121-
/**
122-
* Holder class for various ids met
123-
* adata and id itself. Final, unmodifiable.
124-
*/
125-
public static final class DID {
126-
public static final int STRATEGY_UUID = 0;
127-
public static final int STRATEGY_CUSTOM = 10;
128-
public int strategy;
129-
public String id;
130-
131-
public DID(int strategy, String id) {
132-
this.strategy = strategy;
133-
this.id = id;
134-
}
135-
136-
@Override
137-
public boolean equals(Object obj) {
138-
if (!(obj instanceof DID)) {
139-
return false;
140-
}
141-
DID did = (DID) obj;
142-
return did.strategy == strategy && Objects.equals(did.id, id);
143-
}
144-
145-
@Override
146-
public int hashCode() {
147-
return id.hashCode();
148-
}
149-
150-
@Override
151-
public String toString() {
152-
return "DID " + id + " ( " + strategy + ")";
153-
}
154-
}
15525

15626
protected Log configLog;
15727

@@ -360,26 +230,7 @@ public String toString() {
360230
*/
361231
protected boolean unhandledCrashReportingEnabled = true;
362232

363-
/**
364-
* Get the maximum amount of breadcrumbs. Default is 100.
365-
*
366-
* @param maxBreadcrumbCount the maximum amount of breadcrumbs
367-
* @return {@code this} instance for method chaining
368-
*/
369-
public Config setMaxBreadcrumbCount(int maxBreadcrumbCount) {
370-
this.maxBreadcrumbCount = maxBreadcrumbCount;
371-
return this;
372-
}
373-
374-
/**
375-
* Disable automatic crash reporting for unhandled exceptions.
376-
*
377-
* @return {@code this} instance for method chaining
378-
*/
379-
public Config disableUnhandledCrashReporting() {
380-
this.unhandledCrashReportingEnabled = false;
381-
return this;
382-
}
233+
public ConfigViews views = new ConfigViews(this);
383234

384235
protected String location = null;
385236
protected String ip = null;
@@ -425,6 +276,27 @@ public Config(String serverURL, String serverAppKey, File sdkStorageRootDirector
425276
this.sdkStorageRootDirectory = sdkStorageRootDirectory;
426277
}
427278

279+
/**
280+
* Get the maximum amount of breadcrumbs. Default is 100.
281+
*
282+
* @param maxBreadcrumbCount the maximum amount of breadcrumbs
283+
* @return {@code this} instance for method chaining
284+
*/
285+
public Config setMaxBreadcrumbCount(int maxBreadcrumbCount) {
286+
this.maxBreadcrumbCount = maxBreadcrumbCount;
287+
return this;
288+
}
289+
290+
/**
291+
* Disable automatic crash reporting for unhandled exceptions.
292+
*
293+
* @return {@code this} instance for method chaining
294+
*/
295+
public Config disableUnhandledCrashReporting() {
296+
this.unhandledCrashReportingEnabled = false;
297+
return this;
298+
}
299+
428300
/**
429301
* Whether to allow fallback from unavailable device id strategy to Countly OpenUDID derivative.
430302
*
@@ -1458,5 +1330,134 @@ public Config disableLocation() {
14581330
return this;
14591331
}
14601332

1461-
public ConfigViews views = new ConfigViews(this);
1333+
/**
1334+
* Logging level for {@link Log} module
1335+
*/
1336+
public enum LoggingLevel {
1337+
VERBOSE(0),
1338+
DEBUG(1),
1339+
INFO(2),
1340+
WARN(3),
1341+
ERROR(4),
1342+
OFF(5);
1343+
1344+
private final int level;
1345+
1346+
LoggingLevel(int level) {
1347+
this.level = level;
1348+
}
1349+
1350+
public int getLevel() {
1351+
return level;
1352+
}
1353+
1354+
public boolean prints(LoggingLevel l) {
1355+
return level <= l.level;
1356+
}
1357+
}
1358+
1359+
public enum DeviceIdStrategy {
1360+
UUID(0),
1361+
CUSTOM_ID(10);
1362+
1363+
private final int index;
1364+
1365+
DeviceIdStrategy(int level) {
1366+
this.index = level;
1367+
}
1368+
1369+
public int getIndex() {
1370+
return index;
1371+
}
1372+
1373+
public static DeviceIdStrategy fromIndex(int index) {
1374+
if (index == UUID.index) {
1375+
return UUID;
1376+
}
1377+
if (index == CUSTOM_ID.index) {
1378+
return CUSTOM_ID;
1379+
}
1380+
return null;
1381+
}
1382+
}
1383+
1384+
public enum Feature {
1385+
Events(CoreFeature.Events.getIndex()),
1386+
Sessions(CoreFeature.Sessions.getIndex()),
1387+
Views(CoreFeature.Views.getIndex()),
1388+
CrashReporting(CoreFeature.CrashReporting.getIndex()),
1389+
Location(CoreFeature.Location.getIndex()),
1390+
UserProfiles(CoreFeature.UserProfiles.getIndex()),
1391+
Feedback(CoreFeature.Feedback.getIndex()),
1392+
RemoteConfig(CoreFeature.RemoteConfig.getIndex());
1393+
// StarRating(1 << 12),
1394+
// PerformanceMonitoring(1 << 14);
1395+
1396+
private final int index;
1397+
1398+
Feature(int index) {
1399+
this.index = index;
1400+
}
1401+
1402+
public int getIndex() {
1403+
return index;
1404+
}
1405+
1406+
public static Config.Feature byIndex(int index) {
1407+
if (index == Events.index) {
1408+
return Events;
1409+
} else if (index == Sessions.index) {
1410+
return Sessions;
1411+
} else if (index == Views.index) {
1412+
return Views;
1413+
} else if (index == CrashReporting.index) {
1414+
return CrashReporting;
1415+
} else if (index == Location.index) {
1416+
return Location;
1417+
} else if (index == UserProfiles.index) {
1418+
return UserProfiles;
1419+
} else if (index == RemoteConfig.index) {
1420+
return RemoteConfig;
1421+
} else if (index == Feedback.index) {
1422+
return Feedback;
1423+
} else {
1424+
return null;
1425+
}
1426+
}
1427+
}
1428+
1429+
/**
1430+
* Holder class for various ids met
1431+
* adata and id itself. Final, unmodifiable.
1432+
*/
1433+
public static final class DID {
1434+
public static final int STRATEGY_UUID = 0;
1435+
public static final int STRATEGY_CUSTOM = 10;
1436+
public int strategy;
1437+
public String id;
1438+
1439+
public DID(int strategy, String id) {
1440+
this.strategy = strategy;
1441+
this.id = id;
1442+
}
1443+
1444+
@Override
1445+
public boolean equals(Object obj) {
1446+
if (!(obj instanceof DID)) {
1447+
return false;
1448+
}
1449+
DID did = (DID) obj;
1450+
return did.strategy == strategy && Objects.equals(did.id, id);
1451+
}
1452+
1453+
@Override
1454+
public int hashCode() {
1455+
return id.hashCode();
1456+
}
1457+
1458+
@Override
1459+
public String toString() {
1460+
return "DID " + id + " ( " + strategy + ")";
1461+
}
1462+
}
14621463
}

sdk-java/src/main/java/ly/count/sdk/java/Countly.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class Countly implements Usage {
3535
public static final Device device = Device.dev;
3636

3737
private static final Countly cly = SingletonHolder.INSTANCE;
38+
protected SDKCore sdk;
39+
protected Log L;
3840

3941
private static class SingletonHolder {
4042
private static final Countly INSTANCE = new Countly();
@@ -49,9 +51,6 @@ private static void empty() {
4951
}
5052
}
5153

52-
protected SDKCore sdk;
53-
protected Log L;
54-
5554
protected Countly(SDKCore sdk, final Log logger) {
5655
L = logger;
5756
this.sdk = sdk;

sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigViews.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
public class ConfigViews {
77
private final Config config;
8+
protected Map<String, Object> globalViewSegmentation = null;
89

910
public ConfigViews(Config config) {
1011
this.config = config;
1112
}
1213

13-
protected Map<String, Object> globalViewSegmentation = null;
14-
1514
/**
1615
* @param segmentation segmentation values that will be added for all recorded views (manual and automatic)
1716
* @return Returns the same config object for convenient linking

sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ public class Device {
2828
private String orientation;
2929
private Boolean online;
3030
private Boolean muted;
31-
3231
private Log L;
32+
protected static final Double NS_IN_SECOND = 1_000_000_000.0d;
33+
protected static final Double NS_IN_MS = 1_000_000.0d;
34+
protected static final Double MS_IN_SECOND = 1000d;
35+
protected static final Long BYTES_IN_MB = 1024L * 1024;
3336

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

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

5251
/**
5352
* Get operation system name

0 commit comments

Comments
 (0)