IndexToIndexMultiMapReader { public static IndexToIndexMultiMap from( final Buffer byteBuffer) { final int type = byteBuffer.getInt(); if (type == V1DatabaseFormat.MultiMapType.LIST_BASED.getCode()) { return IntIndexToIndexMultiMap.from(byteBuffer.slice()); } else if (type == V1DatabaseFormat.MultiMapType.LONG_ARRAY_BIT_SET_BASED.getCode()) { return BitSetIndexToIndexMultiMap.from(byteBuffer.slice()); } else if (type == V1DatabaseFormat.MultiMapType.ASCENDING_BIT_SET_BASED.getCode()) { return AscendingBitSetIndexToIndexMultiMap.from(byteBuffer.slice()); } else { throw new UnsupportedOperationException( "Unsupported IndexToIndexMultiMap type: " + type); } } private  IndexToIndexMultiMapReader(); static IndexToIndexMultiMap from(
            final Buffer byteBuffer);  }
@Test public void buildInt() throws IOException { final TreeMultimap<Integer, Integer> elements = TreeMultimap.create(); for (int i = 0; i < DOCS; i++) { elements.put(i / 2, i); } final com.yandex.yoctodb.util.mutable.IndexToIndexMultiMap mutable = new com.yandex.yoctodb.util.mutable.impl.IntIndexToIndexMultiMap( elements.asMap().values()); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); mutable.writeTo(baos); final Buffer buf = Buffer.from(baos.toByteArray()); final IndexToIndexMultiMap result = IndexToIndexMultiMapReader.from(buf); assertTrue(result instanceof IntIndexToIndexMultiMap); }
@Test public void buildBitSet() throws IOException { final TreeMultimap<Integer, Integer> elements = TreeMultimap.create(); for (int i = 0; i < DOCS; i++) { elements.put(i / 2, i); } final com.yandex.yoctodb.util.mutable.IndexToIndexMultiMap mutable = new com.yandex.yoctodb.util.mutable.impl.BitSetIndexToIndexMultiMap( elements.asMap().values(), DOCS); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); mutable.writeTo(baos); final Buffer buf = Buffer.from(baos.toByteArray()); final IndexToIndexMultiMap result = IndexToIndexMultiMapReader.from(buf); assertTrue(result instanceof BitSetIndexToIndexMultiMap); }
@Test(expected = UnsupportedOperationException.class) public void unsupported() throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(Ints.toByteArray(Integer.MAX_VALUE)); final Buffer buf = Buffer.from(baos.toByteArray()); IndexToIndexMultiMapReader.from(buf); }