public static PrimitiveIntIterator deduplicate( PrimitiveIntIterator source ) { return new PrimitiveIntFilteringIterator( source ) { private final PrimitiveIntSet visited = Primitive.intSet(); @Override public boolean test( int testItem ) { return visited.add( testItem ); } }; }
public static PrimitiveIntSet intSet() { return intSet( DEFAULT_HEAP_CAPACITY ); }
public static PrimitiveIntSet asSet( int[] values ) { PrimitiveIntSet set = Primitive.intSet( values.length ); for ( int value: values ) { set.add( value ); } return set; }
public static PrimitiveIntSet asSet( long[] values, LongToIntFunction converter ) { PrimitiveIntSet set = Primitive.intSet( values.length ); for ( long value: values ) { set.add( converter.applyAsInt( value ) ); } return set; }
public static PrimitiveIntSet asSet( PrimitiveIntIterator iterator ) { PrimitiveIntSet set = Primitive.intSet(); while ( iterator.hasNext() ) { int next = iterator.next(); if ( !set.add( next ) ) { throw new IllegalStateException( "Duplicate " + next + " from " + iterator ); } } return set; }
@Test void intVisitorShouldNotSeeEntriesAfterRequestingBreakOut() { // GIVEN PrimitiveIntSet map = Primitive.intSet(); map.add( 1 ); map.add( 2 ); map.add( 3 ); map.add( 4 ); final AtomicInteger counter = new AtomicInteger(); // WHEN map.visitKeys( value -> counter.incrementAndGet() > 2 ); // THEN assertThat( counter.get(), is( 3 ) ); }
@Test void longVisitorShouldNotSeeEntriesAfterRequestingBreakOut() { // GIVEN PrimitiveIntSet map = Primitive.intSet(); map.add( 1 ); map.add( 2 ); map.add( 3 ); map.add( 4 ); final AtomicInteger counter = new AtomicInteger(); // WHEN map.visitKeys( value -> counter.incrementAndGet() > 2 ); // THEN assertThat( counter.get(), is( 3 ) ); }
@SuppressWarnings( "unchecked" ) @Test void intVisitorShouldSeeAllEntriesIfItDoesNotBreakOut() { // GIVEN PrimitiveIntSet set = Primitive.intSet(); set.add( 1 ); set.add( 2 ); set.add( 3 ); PrimitiveIntVisitor<RuntimeException> visitor = mock( PrimitiveIntVisitor.class ); // WHEN set.visitKeys( visitor ); // THEN verify( visitor ).visited( 1 ); verify( visitor ).visited( 2 ); verify( visitor ).visited( 3 ); verifyNoMoreInteractions( visitor ); }
public static PrimitiveIntIterator deduplicate( PrimitiveIntIterator source ) { return new PrimitiveIntFilteringIterator( source ) { private final PrimitiveIntSet visited = Primitive.intSet(); @Override public boolean test( int testItem ) { return visited.add( testItem ); } }; }
public static PrimitiveIntSet intSet() { return intSet( DEFAULT_HEAP_CAPACITY ); }
public static PrimitiveIntIterator deduplicate( PrimitiveIntIterator source ) { return new PrimitiveIntFilteringIterator( source ) { private final PrimitiveIntSet visited = Primitive.intSet(); @Override public boolean test( int testItem ) { return visited.add( testItem ); } }; }
public static PrimitiveIntSet intSet() { return intSet( DEFAULT_HEAP_CAPACITY ); }
public static PrimitiveIntSet asSet( int[] values ) { PrimitiveIntSet set = Primitive.intSet( values.length ); for ( int value: values ) { set.add( value ); } return set; }
public static PrimitiveIntSet asSet( int[] values ) { PrimitiveIntSet set = Primitive.intSet( values.length ); for ( int value : values ) { set.add( value ); } return set; }
public static PrimitiveIntSet asSet( long[] values, LongToIntFunction converter ) { PrimitiveIntSet set = Primitive.intSet( values.length ); for ( long value : values ) { set.add( converter.applyAsInt( value ) ); } return set; }
public static PrimitiveIntSet asSet( long[] values, LongToIntFunction converter ) { PrimitiveIntSet set = Primitive.intSet( values.length ); for ( long value: values ) { set.add( converter.applyAsInt( value ) ); } return set; }
public static PrimitiveIntSet asSet( PrimitiveIntIterator iterator ) { PrimitiveIntSet set = Primitive.intSet(); while ( iterator.hasNext() ) { int next = iterator.next(); if ( !set.add( next ) ) { throw new IllegalStateException( "Duplicate " + next + " from " + iterator ); } } return set; }
public static PrimitiveIntSet asSet( PrimitiveIntIterator iterator ) { PrimitiveIntSet set = Primitive.intSet(); while ( iterator.hasNext() ) { int next = iterator.next(); if ( !set.add( next ) ) { throw new IllegalStateException( "Duplicate " + next + " from " + iterator ); } } return set; }
PrimitiveIntSet blackListed = Primitive.intSet(); for ( String role : roles )