IntegerUnion implements NumberUnion<Integer> { @Override public SortedSet<Integer> tailSet(Integer e) { int index = Collections.binarySearch(intervals, e); if(index < 0) { index = -index - 1; } IntegerUnion retVal = new IntegerUnion(); if(index % 2 != 0) { retVal.intervals = new ArrayList<>(intervals.subList(index, intervals.size())); retVal.intervals.add(0, e); } else { retVal.intervals = intervals.subList(index, intervals.size()); } return retVal; } IntegerUnion(int value);  IntegerUnion(int valueBegin, int valueEnd);  IntegerUnion();  IntegerUnion(int[] externalArray);  IntegerUnion(IntegerUnion externalSet);  IntegerUnion(Collection<Integer> externalCollection);  IntegerUnion(Iterator<Integer> valueIterator); @Override boolean equals(Object obj); @Override int hashCode(); @Override boolean isEmpty(); @Override String toString(); @Override boolean remove(Object o); @Override boolean add(Integer value); @Override Iterator<Integer> iterator(); List<Integer> getValueRanges(); @Override Comparator<? super Integer> comparator(); @Override SortedSet<Integer> subSet(Integer e, Integer e1); @Override SortedSet<Integer> headSet(Integer e); @Override SortedSet<Integer> tailSet(Integer e); @Override Integer first(); @Override Integer last(); @Override int size(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override T[] toArray(T[] ts); @Override boolean containsAll(Collection<?> clctn); @Override boolean addAll(Collection<? extends Integer> clctn); @Override boolean retainAll(Collection<?> clctn); @Override boolean removeAll(Collection<?> clctn); @Override void clear(); ListIterator<Integer> listIterator(); ListIterator<Integer> listIterator(int from);  }
@Test public void testTailSet() { IntegerUnion iu = new IntegerUnion(Arrays.asList(5, 10, 11, 12, 13, 45, 46)); SortedSet<Integer> tail = iu.tailSet(11); assertArrayEquals(new Integer[] {11, 12, 13, 45, 46}, tail.toArray()); tail = iu.tailSet(45); assertArrayEquals(new Integer[] {45, 46}, tail.toArray()); tail = iu.tailSet(10); assertArrayEquals(new Integer[] {10, 11, 12, 13, 45, 46}, tail.toArray()); tail = iu.tailSet(46); assertArrayEquals(new Integer[] {46}, tail.toArray()); tail = iu.tailSet(20); assertArrayEquals(new Integer[] {45, 46}, tail.toArray()); }