@Test public void testCompare() { MSIStreamName name1 = new MSIStreamName("Foo"); MSIStreamName name2 = new MSIStreamName("Boo"); MSIStreamName name3 = new MSIStreamName("FooBar"); assertTrue(name1.compareTo(name1) == 0); assertTrue(name1.compareTo(name2) > 0); assertTrue(name2.compareTo(name1) < 0); assertTrue(name3.compareTo(name1) > 0); Set<MSIStreamName> names = new TreeSet<>(); names.add(name1); names.add(name2); names.add(name3); Iterator<MSIStreamName> iterator = names.iterator(); assertEquals("1st element", name2, iterator.next()); assertEquals("2nd element", name1, iterator.next()); assertEquals("3rd element", name3, iterator.next()); }
public int compareTo(MSIStreamName other) { byte[] a = this.nameUTF16; byte[] b = other.nameUTF16; int size = Math.min(a.length, b.length); for (int i = 0; i < size; i++) { if (a[i] != b[i]) { return (a[i] & 0xFF) - (b[i] & 0xFF); } } return a.length - b.length; }
MSIStreamName implements Comparable<MSIStreamName> { public int compareTo(MSIStreamName other) { byte[] a = this.nameUTF16; byte[] b = other.nameUTF16; int size = Math.min(a.length, b.length); for (int i = 0; i < size; i++) { if (a[i] != b[i]) { return (a[i] & 0xFF) - (b[i] & 0xFF); } } return a.length - b.length; } }
MSIStreamName implements Comparable<MSIStreamName> { public int compareTo(MSIStreamName other) { byte[] a = this.nameUTF16; byte[] b = other.nameUTF16; int size = Math.min(a.length, b.length); for (int i = 0; i < size; i++) { if (a[i] != b[i]) { return (a[i] & 0xFF) - (b[i] & 0xFF); } } return a.length - b.length; } MSIStreamName(String name); }
MSIStreamName implements Comparable<MSIStreamName> { public int compareTo(MSIStreamName other) { byte[] a = this.nameUTF16; byte[] b = other.nameUTF16; int size = Math.min(a.length, b.length); for (int i = 0; i < size; i++) { if (a[i] != b[i]) { return (a[i] & 0xFF) - (b[i] & 0xFF); } } return a.length - b.length; } MSIStreamName(String name); String decode(); String toString(); int compareTo(MSIStreamName other); }
MSIStreamName implements Comparable<MSIStreamName> { public int compareTo(MSIStreamName other) { byte[] a = this.nameUTF16; byte[] b = other.nameUTF16; int size = Math.min(a.length, b.length); for (int i = 0; i < size; i++) { if (a[i] != b[i]) { return (a[i] & 0xFF) - (b[i] & 0xFF); } } return a.length - b.length; } MSIStreamName(String name); String decode(); String toString(); int compareTo(MSIStreamName other);  }