BitSetIndexToIndexMultiMap implements IndexToIndexMultiMap { @Override public void writeTo( @NotNull final OutputStream os) throws IOException { os.write(Ints.toByteArray(V1DatabaseFormat.MultiMapType.LONG_ARRAY_BIT_SET_BASED.getCode())); os.write(Ints.toByteArray(map.size())); os.write(Ints.toByteArray(LongArrayBitSet.arraySize(documentsCount))); final ArrayBitSet docs = LongArrayBitSet.zero(documentsCount); for (Collection<Integer> ids : map) { docs.clear(); for (int docId : ids) { assert 0 <= docId && docId < documentsCount; docs.set(docId); } for (long currentWord : docs.toArray()) { os.write(Longs.toByteArray(currentWord)); } } } BitSetIndexToIndexMultiMap(
            @NotNull
            final Collection<? extends Collection<Integer>> map,
            final int documentsCount); @Override long getSizeInBytes(); @Override void writeTo(
            @NotNull
            final OutputStream os); @Override String toString();  }
@Test(expected = AssertionError.class) public void wrongDocument() throws IOException { new BitSetIndexToIndexMultiMap( singletonList(singletonList(1)), 1) .writeTo(new ByteArrayOutputStream()); }
@Test(expected = IllegalArgumentException.class) public void negativeValue() throws IOException { new BitSetIndexToIndexMultiMap( singletonList(singletonList(1)), -1) .writeTo(new ByteArrayOutputStream()); }