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] Add underscore to the numerics #Codacy #243

Merged
merged 3 commits into from
Feb 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static void recordView() {
segmentation.put("segment", "Windows");
segmentation.put("start", "1");

Countly.instance().backendM().recordView(DEVICE_ID, "SampleView", segmentation, 1646640780130L);
Countly.instance().backendM().recordView(DEVICE_ID, "SampleView", segmentation, 1_646_640_780_130L);
}

private static void recordEvent() {
Expand Down Expand Up @@ -298,7 +298,7 @@ public static void main(String[] args) throws Exception {
Config config = new Config(COUNTLY_SERVER_URL, COUNTLY_APP_KEY)
.setLoggingLevel(Config.LoggingLevel.DEBUG)
.enableBackendMode()
.setRequestQueueMaxSize(10000)
.setRequestQueueMaxSize(10_000)
.setDeviceIdStrategy(Config.DeviceIdStrategy.UUID)
.setRequiresConsent(false)
.setEventQueueSizeToSend(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static void initSDK(int eventQueueSize, int requestQueueSize) {

static void performLargeRequestQueueSizeTest() {
DemoUtils.println("===== Test Started: 'Large request queue size' =====");
int requestQSize = 1000000;
int requestQSize = 1_000_000;
DemoUtils.printf("Before SDK Initialization: Total Memory = %dMb, Available RAM = %dMb %n", Device.dev.getRAMTotal(), Device.dev.getRAMAvailable());
initSDK(1, requestQSize);
DemoUtils.printf("After SDK Initialization: Total Memory = %d Mb, Available RAM= %d Mb %n", Device.dev.getRAMTotal(), Device.dev.getRAMAvailable());
Expand Down Expand Up @@ -121,7 +121,7 @@ static void performLargeEventQueueTest() {
DemoUtils.printf("After SDK Initialization: Total Memory = %d Mb, Available RAM= %d Mb %n", Device.dev.getRAMTotal(), Device.dev.getRAMAvailable());
int noOfDevices = 10;
for (int d = 0; d <= noOfDevices; ++d) {
DemoUtils.printf("Adding %d events into event Queue against deviceID = %s%n", 1_000_00, "device-id-" + d);
DemoUtils.printf("Adding %d events into event Queue against deviceID = %s%n", 100_000, "device-id-" + d);
for (int i = 1; i <= noOfEvents; ++i) {

Map<String, Object> segment = new ConcurrentHashMap<>();
Expand Down
6 changes: 3 additions & 3 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 @@ -44,8 +44,8 @@ public void setLog(Log L) {
/**
* One second in nanoseconds
*/
protected static final Double NS_IN_SECOND = 1000000000.0d;
protected static final Double NS_IN_MS = 1000000.0d;
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;

Expand Down Expand Up @@ -74,7 +74,7 @@ public String getOSVersion() {
* @return timezone offset in seconds
*/
public int getTimezoneOffset() {
return TimeZone.getDefault().getOffset(new Date().getTime()) / 60000;
return TimeZone.getDefault().getOffset(new Date().getTime()) / 60_000;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public class TimeUtils {

protected static final Double NS_IN_SECOND = 1000000000.0d;
protected static final Double NS_IN_MS = 1000000.0d;
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 long MS_IN_SECOND = 1000;
private static final UniqueTimeGenerator uniqueTimer = new UniqueTimeGenerator();

Expand Down Expand Up @@ -39,7 +39,7 @@ protected static Instant getCurrentInstant(long timestamp) {
return new Instant(timestamp,
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.DAY_OF_WEEK) - 1, // Calendar days are 1-based, Countly days are 0-based
calendar.get(Calendar.ZONE_OFFSET) / 60000); //convert it to seconds
calendar.get(Calendar.ZONE_OFFSET) / 60_000); //convert it to seconds
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,4 +954,4 @@ private int getHourFromTimeStamp(long timeStamp) {

return calendar.get(Calendar.HOUR_OF_DAY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void validateFromJson_toJson_segmentation() {
segmentation.put("quantity", 3);
segmentation.put("name", "test");
segmentation.put("null", null);
segmentation.put("checksum", 56476587L);
segmentation.put("checksum", 56_476_587L);
segmentation.put("divisor", 0.2f);
event.segmentation = segmentation;

Expand All @@ -220,7 +220,7 @@ public void validateFromJson_toJson_segmentation() {
expectedSegmentation.put("price", BigDecimal.valueOf(9.43));
expectedSegmentation.put("quantity", 3);
expectedSegmentation.put("name", "test");
expectedSegmentation.put("checksum", 56476587);
expectedSegmentation.put("checksum", 56_476_587);
expectedSegmentation.put("divisor", BigDecimal.valueOf(0.2));

JSONObject json = new JSONObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void mixedTestFlow1() throws InterruptedException {
Countly.instance().init(TestUtils.getConfigViews());
TestUtils.validateEQSize(0);

Map<String, Object> customSegmentationA = TestUtils.map("money", 238746798234739L, "start", "1", "visit", "1", "name", TestUtils.keysValues[0], "segment", TestUtils.keysValues[1]);
Map<String, Object> customSegmentationA = TestUtils.map("money", 238_746_798_234_739L, "start", "1", "visit", "1", "name", TestUtils.keysValues[0], "segment", TestUtils.keysValues[1]);
Map<String, Object> customSegmentationB = TestUtils.map("gone_to", "Wall Sina", "map", TestUtils.map("titan", true, "level", 65));

Countly.instance().views().startView("A", customSegmentationA);
Expand All @@ -270,7 +270,7 @@ public void mixedTestFlow1() throws InterruptedException {

TestUtils.validateEQSize(4);

validateView("A", 0.0, 0, 4, true, true, TestUtils.map("money", 238746798234739L), "idv1", ""); // starting
validateView("A", 0.0, 0, 4, true, true, TestUtils.map("money", 238_746_798_234_739L), "idv1", ""); // starting
validateView("AutoStopped", 0.0, 1, 4, false, true, TestUtils.map("gone_to", "Wall Sina"), "idv2", "idv1"); // starting
validateView("AutoStopped", 1.0, 2, 4, false, false, null, "idv2", "idv1"); // closing
validateView("B", 0.0, 3, 4, false, true, null, "idv3", "idv2"); // starting
Expand Down Expand Up @@ -376,7 +376,7 @@ public void validateSegmentation2() {
validateView("A", 0.0, 0, 2, true, true, null, "idv1", "");
validateView("B", 0.0, 1, 2, false, true, null, "idv2", "idv1");

Map<String, Object> allSegmentation = TestUtils.map("Copyright", "Countly", "AppExit", true, "DestroyToken", false, "ExitedAt", 1702975890000L);
Map<String, Object> allSegmentation = TestUtils.map("Copyright", "Countly", "AppExit", true, "DestroyToken", false, "ExitedAt", 1_702_975_890_000L);
Countly.instance().views().stopAllViews(allSegmentation);

validateView("A", 0.0, 2, 4, false, false, allSegmentation, "idv1", "idv1");
Expand All @@ -401,9 +401,9 @@ public void validateSegmentation_internalKeys() {
Map<String, Object> internalKeysSegmentation = TestUtils.map("start", "YES", "name", TestUtils.keysValues[0], "visit", "YES", "segment", TestUtils.keysValues[1]);

Countly.instance().views().startView("A", TestUtils.map(internalKeysSegmentation, "ultimate", "YES"));
Countly.instance().views().stopViewWithName("A", TestUtils.map(internalKeysSegmentation, "end", "Unfortunately", "time", 1234567890L));
Countly.instance().views().stopViewWithName("A", TestUtils.map(internalKeysSegmentation, "end", "Unfortunately", "time", 1_234_567_890L));
validateView("A", 0.0, 0, 2, true, true, TestUtils.map("ultimate", "YES"), "idv1", "");
validateView("A", 0.0, 1, 2, false, false, TestUtils.map("end", "Unfortunately", "time", 1234567890), "idv1", "");
validateView("A", 0.0, 1, 2, false, false, TestUtils.map("end", "Unfortunately", "time", 1_234_567_890), "idv1", "");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void stop() {
@Test
public void constructor() {
Countly.instance().init(TestUtils.getConfigSessions());
assertEquals(new Long(12345L), createSessionImpl(12345L).getId());
assertEquals(new Long(12_345L), createSessionImpl(12_345L).getId());
}

/**
Expand Down Expand Up @@ -488,7 +488,7 @@ private void addCrashReport_base(Config config, int rqSize) {
@Test
public void hashCode_id() {
Countly.instance().init(TestUtils.getConfigSessions());
assertEquals(new Long(12345L).hashCode(), createSessionImpl(12345L).hashCode());
assertEquals(new Long(12_345L).hashCode(), createSessionImpl(12_345L).hashCode());
}

/**
Expand Down Expand Up @@ -521,7 +521,7 @@ public void equals_test() {
@Test
public void equals_notInstanceOf() {
Countly.instance().init(TestUtils.getConfigSessions());
Assert.assertFalse(createSessionImpl(12345L).equals(new Object()));
Assert.assertFalse(createSessionImpl(12_345L).equals(new Object()));
}

/**
Expand Down Expand Up @@ -632,8 +632,8 @@ public void view_stopStartedAndNext() {
private void validateNotEquals(int idOffset, BiFunction<SessionImpl, SessionImpl, Consumer<Long>> setter) {
Countly.instance().init(TestUtils.getConfigSessions());
long ts = TimeUtils.timestampMs();
SessionImpl session = createSessionImpl(12345L);
SessionImpl session2 = createSessionImpl(12345L + idOffset);
SessionImpl session = createSessionImpl(12_345L);
SessionImpl session2 = createSessionImpl(12_345L + idOffset);
setter.apply(session, session).accept(ts);
Assert.assertFalse(session.equals(session2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void testAsIs() {

long last = simulator.timestamp();

for (int i = 0; i < 10000; i++) {
for (int i = 0; i < 10_000; i++) {
long next = simulator.timestamp();
Assert.assertNotSame(last, next);
}
Expand All @@ -27,7 +27,7 @@ public void testMidTimeChange() {
Assert.assertNotSame(last, next);
}

simulator.addition = -10000;
simulator.addition = -10_000;

for (int i = 0; i < 100; i++) {
long next = simulator.timestamp();
Expand All @@ -41,7 +41,7 @@ public void testMidTimeChange() {
Assert.assertNotSame(last, next);
}

simulator.addition = 10000;
simulator.addition = 10_000;

for (int i = 0; i < 100; i++) {
long next = simulator.timestamp();
Expand All @@ -55,17 +55,17 @@ public void testMidTimeRandomChange() {

long last = simulator.timestamp();

for (int i = 0; i < 100000; i++) {
for (int i = 0; i < 100_000; i++) {
if (i % 30 == 0) {
simulator.addition = Math.round(Math.random() * 10000 - 5000);
simulator.addition = Math.round(Math.random() * 10_000 - 5000);
}
long next = simulator.timestamp();
Assert.assertNotSame(last, next);
}

simulator.addition = 0;

for (int i = 0; i < 100000; i++) {
for (int i = 0; i < 100_000; i++) {
if (i % 30 == 0) {
simulator.addition += Math.round(Math.random() * 1000 - 500);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void uniqueTimestamp() {
*/
@Test
public void nsToMs() {
Assert.assertEquals(1, TimeUtils.nsToMs(1000000));
Assert.assertEquals(1, TimeUtils.nsToMs(1_000_000));
}

/**
Expand All @@ -54,7 +54,7 @@ public void nsToMs() {
*/
@Test
public void nsToSec() {
Assert.assertEquals(1, TimeUtils.nsToSec(1000000000));
Assert.assertEquals(1, TimeUtils.nsToSec(1_000_000_000));
}

/**
Expand All @@ -72,6 +72,6 @@ public void secToMs() {
*/
@Test
public void secToNs() {
Assert.assertEquals(1000000000, TimeUtils.secToNs(1));
Assert.assertEquals(1_000_000_000, TimeUtils.secToNs(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public void set_notAString() {
.set(PredefinedUserPropertyKeys.USERNAME, new TestUtils.AtomicString("TestUsername"))
.set(PredefinedUserPropertyKeys.EMAIL, new TestUtils.AtomicString("[email protected]"))
.set(PredefinedUserPropertyKeys.ORGANIZATION, new TestUtils.AtomicString("Magical Org"))
.set(PredefinedUserPropertyKeys.PHONE, 123456789)
.set(PredefinedUserPropertyKeys.PHONE, 123_456_789)
.set(PredefinedUserPropertyKeys.PICTURE, new TestUtils.AtomicString("Not a picture"))
.set(PredefinedUserPropertyKeys.PICTURE_PATH, new TestUtils.AtomicString("Not a picture path"))
.set(PredefinedUserPropertyKeys.BIRTH_YEAR, new TestUtils.AtomicString("Not a birthyear"))
Expand Down
Loading