public static <VALUE> PrimitiveLongObjectMap<VALUE> longObjectMap() { return longObjectMap( DEFAULT_HEAP_CAPACITY ); }
public static <T> PrimitiveLongObjectMap<T> copy( PrimitiveLongObjectMap<T> original ) { PrimitiveLongObjectMap<T> copy = Primitive.longObjectMap( original.size() ); original.visitEntries( ( key, value ) -> { copy.put( key, value ); return false; } ); return copy; }
@Test void longObjectKeyVisitorShouldNotSeeEntriesAfterRequestingBreakOut() { // GIVEN PrimitiveLongObjectMap<Integer> map = Primitive.longObjectMap(); map.put( 1, 100 ); map.put( 2, 200 ); map.put( 3, 300 ); map.put( 4, 400 ); final AtomicInteger counter = new AtomicInteger(); // WHEN map.visitKeys( value -> counter.incrementAndGet() > 2 ); // THEN assertThat( counter.get(), is( 3 ) ); }
@Test void longObjectEntryVisitorShouldNotSeeEntriesAfterRequestingBreakOut() { // GIVEN PrimitiveLongObjectMap<Integer> map = Primitive.longObjectMap(); map.put( 1, 100 ); map.put( 2, 200 ); map.put( 3, 300 ); map.put( 4, 400 ); final AtomicInteger counter = new AtomicInteger(); // WHEN map.visitEntries( ( key, value ) -> counter.incrementAndGet() > 2 ); // THEN assertThat( counter.get(), is( 3 ) ); }
@Test void longObjectMapValuesContainsAllValues() { PrimitiveLongObjectMap<String> map = Primitive.longObjectMap(); map.put( 1, "a" ); map.put( 2, "b" ); map.put( 3, "c" ); assertThat( map.values(), containsInAnyOrder( "a", "b", "c" ) ); }
@SuppressWarnings( "unchecked" ) @Test void longObjectKeyVisitorShouldSeeAllEntriesIfItDoesNotBreakOut() { // GIVEN PrimitiveLongObjectMap<Integer> map = Primitive.longObjectMap(); map.put( 1, 100 ); map.put( 2, 200 ); map.put( 3, 300 ); PrimitiveLongVisitor<RuntimeException> visitor = mock( PrimitiveLongVisitor.class ); // WHEN map.visitKeys( visitor ); // THEN verify( visitor ).visited( 1 ); verify( visitor ).visited( 2 ); verify( visitor ).visited( 3 ); verifyNoMoreInteractions( visitor ); }
@SuppressWarnings( "unchecked" ) @Test void longObjectEntryVisitorShouldSeeAllEntriesIfItDoesNotBreakOut() { // GIVEN PrimitiveLongObjectMap<Integer> map = Primitive.longObjectMap(); map.put( 1, 100 ); map.put( 2, 200 ); map.put( 3, 300 ); PrimitiveLongObjectVisitor<Integer, RuntimeException> visitor = mock( PrimitiveLongObjectVisitor.class ); // WHEN map.visitEntries( visitor ); // THEN verify( visitor ).visited( 1, 100 ); verify( visitor ).visited( 2, 200 ); verify( visitor ).visited( 3, 300 ); verifyNoMoreInteractions( visitor ); }
expectedEntries.put( 1433091763L, 22 ); PrimitiveLongObjectMap<Integer> map = Primitive.longObjectMap(); for ( Map.Entry<Long, Integer> entry: expectedEntries.entrySet() )
@Test void copyMap() { PrimitiveLongObjectMap<Object> originalMap = Primitive.longObjectMap(); originalMap.put( 1L, "a" ); originalMap.put( 2L, "b" ); originalMap.put( 3L, "c" ); PrimitiveLongObjectMap<Object> copyMap = PrimitiveLongCollections.copy( originalMap ); assertNotSame( originalMap, copyMap ); assertEquals( 3, copyMap.size() ); assertEquals( "a", copyMap.get( 1L ) ); assertEquals( "b", copyMap.get( 2L ) ); assertEquals( "c", copyMap.get( 3L ) ); }
@Test void shouldContainAddedValues_2() { // GIVEN PrimitiveLongObjectMap<Integer> map = Primitive.longObjectMap(); map.put( 1950736976, 4 ); map.put( 1054824202, 58 ); map.put( 348690619, 54 ); map.put( 1224909480, 79 ); map.put( 1508493474, 82 ); // WHEN/THEN boolean existedBefore = map.containsKey( 1508493474 ); Integer valueBefore = map.get( 1508493474 ); Integer previous = map.put( 1508493474, 62 ); boolean existsAfter = map.containsKey( 1508493474 ); Integer valueAfter = map.get( 1508493474 ); assertTrue( existedBefore, "1508493474 should exist before putting here" ); assertEquals( (Integer) 82, valueBefore, "value before should be 82" ); assertEquals( (Integer) 82, previous, "value returned from put should be 82" ); assertTrue( existsAfter, "1508493474 should exist" ); assertEquals( (Integer) 62, valueAfter, "value after putting should be 62" ); }
@Test void shouldMoveValuesWhenMovingEntriesAround() { // GIVEN PrimitiveLongObjectMap<Integer> map = Primitive.longObjectMap(); map.put( 206243105, 47 ); map.put( 2083304695, 63 ); map.put( 689837337, 7 ); map.remove( 206243105 ); // WHEN/THEN int sizeBefore = map.size(); boolean existedBefore = map.containsKey( 689837337 ); Integer valueBefore = map.get( 689837337 ); Integer previous = map.put( 689837337, 20 ); boolean existsAfter = map.containsKey( 689837337 ); Integer valueAfter = map.get( 689837337 ); int sizeAfter = map.size(); assertEquals( 2, sizeBefore, "Size before put should have been 2" ); assertTrue( existedBefore, "689837337 should exist before putting here" ); assertEquals( (Integer) 7, valueBefore, "value before should be 7" ); assertEquals( (Integer) 7, previous, "value returned from put should be 7" ); assertTrue( existsAfter, "689837337 should exist" ); assertEquals( (Integer) 20, valueAfter, "value after putting should be 20" ); assertEquals( 2, sizeAfter, "Size after put should have been 2" ); }
PrimitiveLongObjectMap<Integer> map = Primitive.longObjectMap(); map.remove( 1338037218 ); map.put( 680125236, 83 );
public static <VALUE> PrimitiveLongObjectMap<VALUE> longObjectMap() { return longObjectMap( DEFAULT_HEAP_CAPACITY ); }
public static <VALUE> PrimitiveLongObjectMap<VALUE> longObjectMap() { return longObjectMap( DEFAULT_HEAP_CAPACITY ); }
PrimitiveLongObjectMap<Integer> map = Primitive.longObjectMap(); map.put( 152407843, 17 ); map.put( 435803197, 29 );
public static <T> PrimitiveLongObjectMap<T> copy( PrimitiveLongObjectMap<T> original ) { PrimitiveLongObjectMap<T> copy = Primitive.longObjectMap( original.size() ); original.visitEntries( ( key, value ) -> { copy.put( key, value ); return false; } ); return copy; }
public static <T> PrimitiveLongObjectMap<T> copy( PrimitiveLongObjectMap<T> original ) { PrimitiveLongObjectMap<T> copy = Primitive.longObjectMap( original.size() ); original.visitEntries( ( key, value ) -> { copy.put( key, value ); return false; } ); return copy; }
private SocketTransportHandler.ProtocolChooser protocolChooser( final Session session ) { PrimitiveLongObjectMap<Function<Channel, SocketProtocol>> availableVersions = longObjectMap(); availableVersions.put( SocketProtocolV1.VERSION, new Function<Channel, SocketProtocol>() { @Override public SocketProtocol apply( Channel channel ) { return new SocketProtocolV1( NullLogService.getInstance(), session, channel ); } } ); return new SocketTransportHandler.ProtocolChooser( availableVersions ); }
PrimitiveLongObjectMap<Integer> map = Primitive.longObjectMap(); map.put( 2083704227957337692L, 50 ); map.put( 1039748383662879297L, 12 );
PrimitiveLongObjectMap<Function<Channel, SocketProtocol>> availableVersions = longObjectMap(); availableVersions.put( SocketProtocolV1.VERSION, new Function<Channel, SocketProtocol>()