Skip to content
Open
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
2 changes: 1 addition & 1 deletion api/src/main/java/javax/jdo/identity/IntIdentity.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public int compareTo(IntIdentity o) {
throw new ClassCastException("object is null");
}
int result = super.compare(o);
return (result == 0) ? (key - o.key) : result;
return (result == 0) ? Integer.compare(key, o.key) : result;
}

/**
Expand Down
15 changes: 1 addition & 14 deletions api/src/main/java/javax/jdo/identity/LongIdentity.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,7 @@ public int compareTo(LongIdentity o) {
throw new ClassCastException("object is null");
}
int result = super.compare(o);
if (result == 0) {
long diff = key - o.key;
if (diff == 0) {
return 0;
} else {
if (diff < 0) {
return -1;
} else {
return 1;
}
}
} else {
return result;
}
return (result == 0) ? Long.compare(key, o.key) : result;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions api/src/test/java/javax/jdo/identity/IntIdentityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,18 @@ void testCompareTo() {
IntIdentity c2 = new IntIdentity(Object.class, 1);
IntIdentity c3 = new IntIdentity(Object.class, 2);
IntIdentity c4 = new IntIdentity(Class.class, 1);
IntIdentity c6 = new IntIdentity(Object.class, Integer.MIN_VALUE);
IntIdentity c7 = new IntIdentity(Object.class, Integer.MAX_VALUE);
Assertions.assertEquals(0, c1.compareTo(c2), "Equal IntIdentity instances compare not equal.");
Assertions.assertTrue(
c1.compareTo(c3) < 0, "Not equal IntIdentity instances have wrong compareTo result");
Assertions.assertTrue(
c3.compareTo(c1) > 0, "Not equal IntIdentity instances have wrong compareTo result");
Assertions.assertTrue(
c1.compareTo(c4) > 0, "Not equal IntIdentity instances have wrong compareTo result");
Assertions.assertTrue(
c6.compareTo(c7) < 0, "Not equal LongIdentity instances have wrong compareTo result");
Assertions.assertTrue(
c7.compareTo(c6) > 0, "Not equal LongIdentity instances have wrong compareTo result");
}
}
8 changes: 7 additions & 1 deletion api/src/test/java/javax/jdo/identity/LongIdentityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ void testCompareTo() {
LongIdentity c3 = new LongIdentity(Object.class, 2);
LongIdentity c4 = new LongIdentity(Class.class, 1);
LongIdentity c5 = new LongIdentity(Object.class, 0x100000001L);
LongIdentity c6 = new LongIdentity(Object.class, Long.MIN_VALUE);
LongIdentity c7 = new LongIdentity(Object.class, Long.MAX_VALUE);
Assertions.assertEquals(0, c1.compareTo(c2), "Equal LongIdentity instances compare not equal.");
Assertions.assertTrue(
c1.compareTo(c3) < 0, "Not equal LongIdentity instances have wrong compareTo result");
Expand All @@ -142,6 +144,10 @@ void testCompareTo() {
Assertions.assertTrue(
c1.compareTo(c4) > 0, "Not equal LongIdentity instances have wrong compareTo result");
Assertions.assertTrue(
c5.compareTo(c1) > 0, "Not equal LongIdentity instances have wrong compareTo result");
c5.compareTo(c1) > 0, "Not equal LongIdentity instances have wrong compareTo result");
Assertions.assertTrue(
c6.compareTo(c7) < 0, "Not equal LongIdentity instances have wrong compareTo result");
Assertions.assertTrue(
c7.compareTo(c6) > 0, "Not equal LongIdentity instances have wrong compareTo result");
}
}
Loading