IntegerList implements SortedSet<Integer>, List<Integer> { protected int getSegmentIndexFor(int value) { if (this.values != null) { int first = 0; int last = getSegmentCount() - 1; while (first <= last) { final int center = (first + last) / 2; final int min = this.values[center * 2]; final int max = this.values[center * 2 + 1]; if (value >= min && value <= max) { return center * 2; } if (value < min) { last = center - 1; } else { first = center + 1; } } } return -1; } IntegerList();  IntegerList(int value);  IntegerList(int start, int end);  IntegerList(Collection<? extends Integer> collection); @Pure @Override String toString(); @Pure @Inline(value = "null", constantExpression = true) @Override Comparator<? super Integer> comparator(); @Pure @Override Integer first(); @Pure @Override SortedSet<Integer> headSet(Integer toElement); @Pure @Override Integer last(); @Pure @Override SortedSet<Integer> subSet(Integer fromElement, Integer toElement); @Pure @Override SortedSet<Integer> tailSet(Integer fromElement); @Override final void add(int index, Integer element); @Override boolean add(Integer value); @Override final boolean addAll(int index, Collection<? extends Integer> collection); @Override boolean addAll(Collection<? extends Integer> collection); @Override void clear(); @Pure @Override boolean contains(Object obj); @Pure @Override boolean containsAll(Collection<?> collection); @Pure @Override boolean isEmpty(); @Pure @Override Iterator<Integer> iterator(); @Pure Iterator<IntegerSegment> segmentIterator(); @Pure Iterable<IntegerSegment> toSegmentIterable(); @Override boolean remove(Object obj); @Override Integer remove(int index); @Override boolean removeAll(Collection<?> collection); @Override boolean retainAll(Collection<?> collection); @Override Integer set(int index, Integer element); void set(SortedSet<? extends Number> collection); @Pure @Override int size(); @Override @Pure Integer get(int index); @Override @Pure Object[] toArray(); @Override @SuppressWarnings("unchecked") T[] toArray(T[] array); @Pure int[] toIntArray(); @Pure SortedSet<Integer> toSortedSet(); @Pure @Override int indexOf(Object obj); @Pure @Override int lastIndexOf(Object obj); @Pure @Override ListIterator<Integer> listIterator(); @Pure @Override ListIterator<Integer> listIterator(int index); @Pure @Override List<Integer> subList(int fromIndex, int toIndex); @Pure @Override Spliterator<Integer> spliterator();  }
@Test public void getSegmentIndexForInt() { assertEquals(-1, this.list.getSegmentIndexFor(0)); assertEquals(0, this.list.getSegmentIndexFor(1)); assertEquals(0, this.list.getSegmentIndexFor(2)); assertEquals(0, this.list.getSegmentIndexFor(3)); assertEquals(-1, this.list.getSegmentIndexFor(4)); assertEquals(-1, this.list.getSegmentIndexFor(5)); assertEquals(-1, this.list.getSegmentIndexFor(6)); assertEquals(-1, this.list.getSegmentIndexFor(7)); assertEquals(-1, this.list.getSegmentIndexFor(8)); assertEquals(-1, this.list.getSegmentIndexFor(9)); assertEquals(2, this.list.getSegmentIndexFor(10)); assertEquals(-1, this.list.getSegmentIndexFor(11)); assertEquals(-1, this.list.getSegmentIndexFor(12)); assertEquals(-1, this.list.getSegmentIndexFor(13)); assertEquals(-1, this.list.getSegmentIndexFor(14)); assertEquals(-1, this.list.getSegmentIndexFor(15)); assertEquals(-1, this.list.getSegmentIndexFor(16)); assertEquals(-1, this.list.getSegmentIndexFor(17)); assertEquals(-1, this.list.getSegmentIndexFor(18)); assertEquals(-1, this.list.getSegmentIndexFor(19)); assertEquals(4, this.list.getSegmentIndexFor(20)); assertEquals(4, this.list.getSegmentIndexFor(21)); assertEquals(4, this.list.getSegmentIndexFor(22)); assertEquals(4, this.list.getSegmentIndexFor(23)); assertEquals(4, this.list.getSegmentIndexFor(24)); assertEquals(4, this.list.getSegmentIndexFor(25)); assertEquals(-1, this.list.getSegmentIndexFor(26)); assertEquals(-1, this.list.getSegmentIndexFor(27)); assertEquals(-1, this.list.getSegmentIndexFor(28)); assertEquals(-1, this.list.getSegmentIndexFor(29)); assertEquals(-1, this.list.getSegmentIndexFor(30)); }