Skip to content
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 @@ -222,8 +222,8 @@ public int compareTo(NodeId other) {
/** Compare - provides an ordering of {@code NodeIds}. */
public static int compare(NodeId n1, NodeId n2) {
int x = Integer.compare(n1.value1, n2.value1);
if ( x == 0 )
return CMP_EQUAL;
if ( x != 0 )
return x;
return Long.compare(n1.value2, n2.value2);
}

Expand Down
34 changes: 34 additions & 0 deletions jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestNodeId.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.ByteBuffer;

Expand Down Expand Up @@ -129,4 +130,37 @@ private static void testCodecBuffer(NodeId testNid,NodeId expected) {
assertEquals(expected, nid1);
}

@Test public void nodeId_compare_01() {
// Same value - should be equal (0)
NodeId n1 = NodeIdFactory.createPtrLong(42, 100L);
NodeId n2 = NodeIdFactory.createPtrLong(42, 100L);
assertEquals(0, NodeId.compare(n1, n2));
assertEquals(0, n1.compareTo(n2));
assertTrue(n1.equals(n2));
}

@Test public void nodeId_compare_02() {
// Different value1 - value2 should not affect ordering
NodeId n1 = NodeIdFactory.createPtrLong(3, 1000L);
NodeId n2 = NodeIdFactory.createPtrLong(7, 50L);
assertTrue(NodeId.compare(n1, n2) < 0);
assertTrue(n1.compareTo(n2) < 0);

// Reverse direction
assertTrue(NodeId.compare(n2, n1) > 0);
assertTrue(n2.compareTo(n1) > 0);
}

@Test public void nodeId_compare_03() {
// Same value1, different value2 - should compare on value2
NodeId n1 = NodeIdFactory.createPtrLong(5, 100L);
NodeId n2 = NodeIdFactory.createPtrLong(5, 200L);
assertTrue(NodeId.compare(n1, n2) < 0);
assertTrue(n1.compareTo(n2) < 0);

// Reverse direction
assertTrue(NodeId.compare(n2, n1) > 0);
assertTrue(n2.compareTo(n1) > 0);
}
}