@Test public void compareTo() { assertEquals(0, fromString(" ").compareTo(blankString(3))); assertTrue(fromString("").compareTo(fromString("a")) < 0); assertTrue(fromString("abc").compareTo(fromString("ABC")) > 0); assertTrue(fromString("abc0").compareTo(fromString("abc")) > 0); assertEquals(0, fromString("abcabcabc").compareTo(fromString("abcabcabc"))); assertTrue(fromString("aBcabcabc").compareTo(fromString("Abcabcabc")) > 0); assertTrue(fromString("Abcabcabc").compareTo(fromString("abcabcabC")) < 0); assertTrue(fromString("abcabcabc").compareTo(fromString("abcabcabC")) > 0); assertTrue(fromString("abc").compareTo(fromString("世界")) < 0); assertTrue(fromString("你好").compareTo(fromString("世界")) > 0); assertTrue(fromString("你好123").compareTo(fromString("你好122")) > 0); MemorySegment segment1 = MemorySegmentFactory.allocateUnpooledSegment(1024); MemorySegment segment2 = MemorySegmentFactory.allocateUnpooledSegment(1024); SortUtil.putStringNormalizedKey(fromString("abcabcabc"), segment1, 0, 9); SortUtil.putStringNormalizedKey(fromString("abcabcabC"), segment2, 0, 9); assertTrue(segment1.compare(segment2, 0, 0, 9) > 0); SortUtil.putStringNormalizedKey(fromString("abcab"), segment1, 0, 9); assertTrue(segment1.compare(segment2, 0, 0, 9) < 0); }
@Override public int compareTo(@Nonnull BinaryString other) { if (javaObject != null && other.javaObject != null) { return javaObject.compareTo(other.javaObject); } ensureMaterialized(); other.ensureMaterialized(); if (segments.length == 1 && other.segments.length == 1) { int len = Math.min(sizeInBytes, other.sizeInBytes); MemorySegment seg1 = segments[0]; MemorySegment seg2 = other.segments[0]; for (int i = 0; i < len; i++) { int res = (seg1.get(offset + i) & 0xFF) - (seg2.get(other.offset + i) & 0xFF); if (res != 0) { return res; } } return sizeInBytes - other.sizeInBytes; } return compareMultiSegments(other); }
BinaryString extends LazyBinaryFormat<String> implements Comparable<BinaryString> { @Override public int compareTo(@Nonnull BinaryString other) { if (javaObject != null && other.javaObject != null) { return javaObject.compareTo(other.javaObject); } ensureMaterialized(); other.ensureMaterialized(); if (segments.length == 1 && other.segments.length == 1) { int len = Math.min(sizeInBytes, other.sizeInBytes); MemorySegment seg1 = segments[0]; MemorySegment seg2 = other.segments[0]; for (int i = 0; i < len; i++) { int res = (seg1.get(offset + i) & 0xFF) - (seg2.get(other.offset + i) & 0xFF); if (res != 0) { return res; } } return sizeInBytes - other.sizeInBytes; } return compareMultiSegments(other); } }
BinaryString extends LazyBinaryFormat<String> implements Comparable<BinaryString> { @Override public int compareTo(@Nonnull BinaryString other) { if (javaObject != null && other.javaObject != null) { return javaObject.compareTo(other.javaObject); } ensureMaterialized(); other.ensureMaterialized(); if (segments.length == 1 && other.segments.length == 1) { int len = Math.min(sizeInBytes, other.sizeInBytes); MemorySegment seg1 = segments[0]; MemorySegment seg2 = other.segments[0]; for (int i = 0; i < len; i++) { int res = (seg1.get(offset + i) & 0xFF) - (seg2.get(other.offset + i) & 0xFF); if (res != 0) { return res; } } return sizeInBytes - other.sizeInBytes; } return compareMultiSegments(other); } BinaryString(); private  BinaryString(MemorySegment[] segments, int offset, int sizeInBytes); private  BinaryString(String javaObject); private  BinaryString(MemorySegment[] segments, int offset, int sizeInBytes, String javaObject); }
BinaryString extends LazyBinaryFormat<String> implements Comparable<BinaryString> { @Override public int compareTo(@Nonnull BinaryString other) { if (javaObject != null && other.javaObject != null) { return javaObject.compareTo(other.javaObject); } ensureMaterialized(); other.ensureMaterialized(); if (segments.length == 1 && other.segments.length == 1) { int len = Math.min(sizeInBytes, other.sizeInBytes); MemorySegment seg1 = segments[0]; MemorySegment seg2 = other.segments[0]; for (int i = 0; i < len; i++) { int res = (seg1.get(offset + i) & 0xFF) - (seg2.get(other.offset + i) & 0xFF); if (res != 0) { return res; } } return sizeInBytes - other.sizeInBytes; } return compareMultiSegments(other); } BinaryString(); private  BinaryString(MemorySegment[] segments, int offset, int sizeInBytes); private  BinaryString(String javaObject); private  BinaryString(MemorySegment[] segments, int offset, int sizeInBytes, String javaObject); static BinaryString fromAddress(
			MemorySegment[] segments, int offset, int numBytes); static BinaryString fromString(String str); static BinaryString fromBytes(byte[] bytes); static BinaryString fromBytes(byte[] bytes, int offset, int numBytes); static BinaryString blankString(int length); int numChars(); byte byteAt(int index); byte[] getBytes(); @Override boolean equals(Object o); @Override String toString(); @Override void materialize(); BinaryString copy(); @Override int compareTo(@Nonnull BinaryString other); BinaryString substring(int beginIndex, int endIndex); boolean contains(final BinaryString s); boolean startsWith(final BinaryString prefix); boolean endsWith(final BinaryString suffix); BinaryString trim(); int indexOf(BinaryString str, int fromIndex); BinaryString toUpperCase(); BinaryString toLowerCase(); }
BinaryString extends LazyBinaryFormat<String> implements Comparable<BinaryString> { @Override public int compareTo(@Nonnull BinaryString other) { if (javaObject != null && other.javaObject != null) { return javaObject.compareTo(other.javaObject); } ensureMaterialized(); other.ensureMaterialized(); if (segments.length == 1 && other.segments.length == 1) { int len = Math.min(sizeInBytes, other.sizeInBytes); MemorySegment seg1 = segments[0]; MemorySegment seg2 = other.segments[0]; for (int i = 0; i < len; i++) { int res = (seg1.get(offset + i) & 0xFF) - (seg2.get(other.offset + i) & 0xFF); if (res != 0) { return res; } } return sizeInBytes - other.sizeInBytes; } return compareMultiSegments(other); } BinaryString(); private  BinaryString(MemorySegment[] segments, int offset, int sizeInBytes); private  BinaryString(String javaObject); private  BinaryString(MemorySegment[] segments, int offset, int sizeInBytes, String javaObject); static BinaryString fromAddress(
			MemorySegment[] segments, int offset, int numBytes); static BinaryString fromString(String str); static BinaryString fromBytes(byte[] bytes); static BinaryString fromBytes(byte[] bytes, int offset, int numBytes); static BinaryString blankString(int length); int numChars(); byte byteAt(int index); byte[] getBytes(); @Override boolean equals(Object o); @Override String toString(); @Override void materialize(); BinaryString copy(); @Override int compareTo(@Nonnull BinaryString other); BinaryString substring(int beginIndex, int endIndex); boolean contains(final BinaryString s); boolean startsWith(final BinaryString prefix); boolean endsWith(final BinaryString suffix); BinaryString trim(); int indexOf(BinaryString str, int fromIndex); BinaryString toUpperCase(); BinaryString toLowerCase(); static final BinaryString EMPTY_UTF8; }