StreamIdSupplier { int nextStreamId(IntObjectMap<?> streamIds) { int streamId; do { this.streamId += 2; streamId = (int) (this.streamId & MASK); } while (streamId == 0 || streamIds.containsKey(streamId)); return streamId; } StreamIdSupplier(int streamId);   }
@Test public void testWrap() { IntObjectMap<Object> map = new IntObjectHashMap<>(); StreamIdSupplier s = new StreamIdSupplier(Integer.MAX_VALUE - 3); assertEquals(2147483646, s.nextStreamId(map)); assertEquals(2, s.nextStreamId(map)); assertEquals(4, s.nextStreamId(map)); s = new StreamIdSupplier(Integer.MAX_VALUE - 2); assertEquals(2147483647, s.nextStreamId(map)); assertEquals(1, s.nextStreamId(map)); assertEquals(3, s.nextStreamId(map)); }