@Override public boolean isLess(int i, int j) { String s1 = resourceIds[resourceIdsIndex[i]]; String s2 = resourceIds[resourceIdsIndex[j]]; return FastStringComparator.INSTANCE.compare(s1, s2) < 0; }
private static boolean contains(List<Integer> a, List<Integer> b) { return SortedListsUtils.contains(a, b, IntegerComparator.INSTANCE); }
@Test public void testContains() { assertThat(contains(Arrays.asList(1, 2, 3), Arrays.asList(1, 2)), is(true)); assertThat(contains(Arrays.asList(1, 2), Arrays.asList(1, 2, 3)), is(false)); assertThat(contains(Arrays.asList(1, 2, 3), Arrays.asList(1, 3)), is(true)); assertThat(contains(Arrays.asList(1, 3), Arrays.asList(1, 2, 3)), is(false)); assertThat(contains(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 2, 3)), is(true)); assertThat(contains(Arrays.asList(1, 2, 2, 3), Arrays.asList(1, 2, 3)), is(true)); }
static int compare(String left, String right) { return FastStringComparator.INSTANCE.compare(left, right); }
@Test public void sameHashCode() { // Next two Strings have same hash code in Java - see http://www.drmaciver.com/2008/07/javalangstringhashcode/ String s1 = "Od"; String s2 = "PE"; assertThat(s1.hashCode()).isEqualTo(s2.hashCode()); assertThat(compare(s1, s2)).isLessThan(0); assertThat(compare(s2, s1)).isGreaterThan(0); }
@Override public int compare(ClonePart o1, ClonePart o2) { return FastStringComparator.INSTANCE.compare(o1.getResourceId(), o2.getResourceId()); } };
@Override public ResourceBlocks next() { if (!hasNext()) { throw new NoSuchElementException(); } String resourceId = resourceIds[resourceIdsIndex[index]]; List<Block> blocks = new ArrayList<>(); // while we are at the same resource, keep going do { blocks.add(getBlock(resourceIdsIndex[index], resourceId)); index++; } while (hasNext() && FastStringComparator.INSTANCE.compare(resourceIds[resourceIdsIndex[index]], resourceId) == 0); return new ResourceBlocks(resourceId, blocks); }
/** * {@inheritDoc} * <p> * <strong>Note that this implementation does not guarantee that blocks would be sorted by index.</strong> * </p> */ @Override public Collection<Block> getByResourceId(String resourceId) { ensureSorted(); // prepare resourceId for binary search resourceIds[size] = resourceId; resourceIdsIndex[size] = size; int index = DataUtils.binarySearch(byResourceId); List<Block> result = new ArrayList<>(); int realIndex = resourceIdsIndex[index]; while (index < size && FastStringComparator.INSTANCE.compare(resourceIds[realIndex], resourceId) == 0) { result.add(getBlock(realIndex, resourceId)); index++; realIndex = resourceIdsIndex[index]; } return result; }
@Override public boolean isLess(int i, int j) { String s1 = resourceIds[resourceIdsIndex[i]]; String s2 = resourceIds[resourceIdsIndex[j]]; return FastStringComparator.INSTANCE.compare(s1, s2) < 0; }
@Override public int compare(ClonePart o1, ClonePart o2) { return FastStringComparator.INSTANCE.compare(o1.getResourceId(), o2.getResourceId()); } };
while (index < size && FastStringComparator.INSTANCE.compare(resourceIds[realIndex], resourceId) == 0) {