IntIndexToIndexMultiMap implements IndexToIndexMultiMap { @NotNull @Override public Iterator<IntToIntArray> descending( @NotNull final BitSet valueFilter) { return new Iterator<IntToIntArray>() { private int key = keysCount - 1; private IntToIntArray next = null; private void advance() { while (next == null && key >= 0) { next = getFilteredValues(key--, valueFilter); } } @Override public boolean hasNext() { if (next != null) return true; advance(); return next != null; } @Override public IntToIntArray next() { if (!hasNext()) throw new NoSuchElementException(); final IntToIntArray result = next; next = null; return result; } @Override public void remove() { throw new UnsupportedOperationException( "Removal not supported"); } }; } private  IntIndexToIndexMultiMap(
            final int keysCount,
            @NotNull
            final Buffer offsets,
            @NotNull
            final Buffer elements); @NotNull static IntIndexToIndexMultiMap from(
            @NotNull
            final Buffer buf); @Override boolean get(
            @NotNull
            final BitSet dest,
            final int key); @Override boolean getFrom(
            @NotNull
            final BitSet dest,
            final int fromInclusive); @Override boolean getTo(
            @NotNull
            final BitSet dest,
            final int toExclusive); @Override boolean getBetween(
            @NotNull
            final BitSet dest,
            final int fromInclusive,
            final int toExclusive); @Override int getKeysCount(); @Override String toString(); @NotNull @Override Iterator<IntToIntArray> ascending(
            @NotNull
            final BitSet valueFilter); @NotNull @Override Iterator<IntToIntArray> descending(
            @NotNull
            final BitSet valueFilter);  }
@Test public void descendingIterator() throws IOException { final Iterator<IntToIntArray> iter = build().descending(LongArrayBitSet.one(VALUES)); for (int i = VALUES / 2 - 1; i >= 0; i--) { assertTrue(iter.hasNext()); final IntToIntArray e = iter.next(); assertEquals(i, e.getKey()); assertEquals(2, e.getCount()); assertArrayEquals(new int[]{i * 2, i * 2 + 1}, e.getValues()); } assertFalse(iter.hasNext()); }
@Test public void descendingSparseIterator() throws IOException { final BitSet filter = LongArrayBitSet.zero(VALUES); final int step = 4; for (int i = 0; i < VALUES; i += step) filter.set(i); final Iterator<IntToIntArray> iter = build().descending(filter); for (int i = VALUES / 2 - 2; i >= 0; i -= 2) { assertTrue(iter.hasNext()); final IntToIntArray e = iter.next(); assertEquals(i, e.getKey()); assertEquals(1, e.getCount()); assertEquals(i * 2, e.getValues()[0]); } assertFalse(iter.hasNext()); }
@Test(expected = NoSuchElementException.class) public void descendingEmptyIterator() throws IOException { final Iterator<IntToIntArray> iter = build().descending(LongArrayBitSet.zero(VALUES)); assertFalse(iter.hasNext()); iter.next(); }
@Test(expected = UnsupportedOperationException.class) public void descendingRemoveUnsupported() throws IOException { final Iterator<IntToIntArray> iter = build().descending(LongArrayBitSet.one(VALUES)); assertTrue(iter.hasNext()); iter.remove(); }