IntegerUnion implements NumberUnion<Integer> { public ListIterator<Integer> listIterator() { return new ValueListIterator(intervals.listIterator()); } 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 testListIterator() { IntegerUnion iu = new IntegerUnion(Arrays.asList(5, 10, 11, 12, 13, 45, 46)); List<Integer> model = new ArrayList<>(Arrays.asList(5, 10, 11, 12, 13, 45, 46)); ListIterator<Integer> it = iu.listIterator(); ListIterator<Integer> modelIt = model.listIterator(); assertFalse(it.hasPrevious()); assertTrue(it.hasNext()); assertEquals(modelIt.next(), it.next()); assertTrue(it.hasNext()); assertEquals(modelIt.next(), it.next()); assertTrue(it.hasPrevious()); assertEquals(modelIt.previous(), it.previous()); assertTrue(it.hasPrevious()); assertEquals(modelIt.previous(), it.previous()); assertTrue(it.hasNext()); assertEquals(modelIt.next(), it.next()); assertTrue(it.hasNext()); assertEquals(modelIt.next(), it.next()); assertTrue(it.hasNext()); assertEquals(modelIt.next(), it.next()); assertTrue(it.hasNext()); assertEquals(modelIt.next(), it.next()); assertTrue(it.hasNext()); assertEquals(modelIt.next(), it.next()); assertTrue(it.hasPrevious()); assertEquals(modelIt.previous(), it.previous()); assertTrue(it.hasPrevious()); assertEquals(modelIt.previous(), it.previous()); assertTrue(it.hasPrevious()); assertEquals(modelIt.previous(), it.previous()); assertTrue(it.hasPrevious()); assertEquals(modelIt.previous(), it.previous()); assertTrue(it.hasPrevious()); assertEquals(modelIt.previous(), it.previous()); assertFalse(it.hasPrevious()); }
@Test public void testIteratorIndex() { IntegerUnion iu = new IntegerUnion(Arrays.asList(5, 10, 11, 12, 13, 45, 46)); assertArrayEquals(new Integer[] {11, 12, 13, 45, 46}, iteratorToList(iu.listIterator(11))); assertArrayEquals(new Integer[] {12, 13, 45, 46}, iteratorToList(iu.listIterator(12))); assertArrayEquals(new Integer[] {13, 45, 46}, iteratorToList(iu.listIterator(13))); assertArrayEquals(new Integer[] {45, 46}, iteratorToList(iu.listIterator(20))); assertArrayEquals(new Integer[] {45, 46}, iteratorToList(iu.listIterator(44))); assertArrayEquals(new Integer[] {45, 46}, iteratorToList(iu.listIterator(45))); assertArrayEquals(new Integer[] {46}, iteratorToList(iu.listIterator(46))); }