public int intValueOf(Iterable<?> iterable) { return Iterate.sizeOf(iterable); } }
@Override public int size() { return Iterate.sizeOf(this.adapted); }
@Override public int size() { return Iterate.sizeOf(this.adapted); }
public static <T, BT extends ObjectIntProcedure<? super T>> void forEachWithIndex( Iterable<T> iterable, ObjectIntProcedureFactory<BT> procedureFactory, Combiner<BT> combiner, Executor executor) { int taskCount = Math.max( ParallelIterate.DEFAULT_PARALLEL_TASK_COUNT, Iterate.sizeOf(iterable) / ParallelIterate.DEFAULT_MIN_FORK_SIZE); ParallelIterate.forEachWithIndex( iterable, procedureFactory, combiner, ParallelIterate.DEFAULT_MIN_FORK_SIZE, taskCount, executor); }
private static <T> int calculateTaskCount(Iterable<T> iterable, int batchSize) { if (iterable instanceof BatchIterable<?>) { return FJIterate.calculateTaskCount((BatchIterable<?>) iterable, batchSize); } return FJIterate.calculateTaskCount(Iterate.sizeOf(iterable), batchSize); }
public static <E> ArrayAdapter<E> newArrayWithItem(Iterable<? extends E> iterable, E itemToAdd) { int oldSize = Iterate.sizeOf(iterable); E[] array = (E[]) new Object[oldSize + 1]; Iterate.toArray(iterable, array); array[oldSize] = itemToAdd; return new ArrayAdapter<E>(array); }
private static <T> int calculateTaskCount(Iterable<T> iterable, int batchSize) { if (iterable instanceof BatchIterable<?>) { return ParallelIterate.calculateTaskCount((BatchIterable<?>) iterable, batchSize); } return ParallelIterate.calculateTaskCount(Iterate.sizeOf(iterable), batchSize); }
public static <T, PT extends ObjectIntProcedure<? super T>> void forEachWithIndex( Iterable<T> iterable, ObjectIntProcedureFactory<PT> procedureFactory, Combiner<PT> combiner, ForkJoinPool executor) { int taskCount = Math.max( FJIterate.DEFAULT_PARALLEL_TASK_COUNT, Iterate.sizeOf(iterable) / DEFAULT_MIN_FORK_SIZE); FJIterate.forEachWithIndex(iterable, procedureFactory, combiner, DEFAULT_MIN_FORK_SIZE, taskCount, executor); }
public ImmutableList<T> newWithAll(Iterable<? extends T> elements) { final int oldSize = this.size(); int newSize = Iterate.sizeOf(elements); final T[] array = (T[]) new Object[oldSize + newSize]; this.toArray(array); Iterate.forEachWithIndex(elements, new ObjectIntProcedure<T>() { public void value(T each, int index) { array[oldSize + index] = each; } }); return Lists.immutable.with(array); }
private boolean retainAllFromNonSet(Iterable<?> iterable) { int retainedSize = Iterate.sizeOf(iterable); UnifiedSetWithHashingStrategy<T> retainedCopy = new UnifiedSetWithHashingStrategy<T>(this.hashingStrategy, retainedSize, this.loadFactor); for (Object key : iterable) { this.addIfFound((T) key, retainedCopy); } if (retainedCopy.size() < this.size()) { this.maxSize = retainedCopy.maxSize; this.occupied = retainedCopy.occupied; this.table = retainedCopy.table; return true; } return false; }
private boolean retainAllFromNonSet(Iterable<?> iterable) { int retainedSize = Iterate.sizeOf(iterable); UnifiedSet<T> retainedCopy = new UnifiedSet<T>(retainedSize, this.loadFactor); for (Object key : iterable) { this.addIfFound((T) key, retainedCopy); } if (retainedCopy.size() < this.size()) { this.maxSize = retainedCopy.maxSize; this.occupied = retainedCopy.occupied; this.table = retainedCopy.table; return true; } return false; }
public boolean addAllIterable(Iterable<? extends T> iterable) { if (iterable instanceof UnifiedSetWithHashingStrategy) { return this.copySet((UnifiedSetWithHashingStrategy<?>) iterable); } int size = Iterate.sizeOf(iterable); this.ensureCapacity(size); int oldSize = this.size(); Iterate.forEachWith(iterable, Procedures2.<T>addToCollection(), this); return this.size() != oldSize; }
public static <T, V, R extends Collection<V>> R flatCollect( Iterable<T> iterable, Function<? super T, ? extends Iterable<V>> function, R target, int batchSize, ForkJoinPool executor, boolean allowReorderedResult) { int size = Iterate.sizeOf(iterable); int taskSize = size / FJIterate.DEFAULT_PARALLEL_TASK_COUNT; FlatCollectProcedureCombiner<T, V> combiner = new FlatCollectProcedureCombiner<>(iterable, target, size, allowReorderedResult); FlatCollectProcedureFactory<T, V> procedureFactory = new FlatCollectProcedureFactory<>(function, taskSize); int taskCount = FJIterate.calculateTaskCount(size, batchSize); FJIterate.forEach(iterable, procedureFactory, combiner, batchSize, taskCount, executor); return (R) combiner.getResult(); }
public static <T, V, R extends Collection<V>> R collect( Iterable<T> iterable, Function<? super T, V> function, R target, int batchSize, Executor executor, boolean allowReorderedResult) { int size = Iterate.sizeOf(iterable); FastListCollectProcedureCombiner<T, V> combiner = new FastListCollectProcedureCombiner<T, V>(iterable, target, size, allowReorderedResult); int taskCount = ParallelIterate.calculateTaskCount(iterable, batchSize); FastListCollectProcedureFactory<T, V> procedureFactory = new FastListCollectProcedureFactory<T, V>(function, size / taskCount); ParallelIterate.forEach( iterable, procedureFactory, combiner, batchSize, taskCount, executor); return (R) combiner.getResult(); }
public static <T, V, R extends Collection<V>> R collect( Iterable<T> iterable, Function<? super T, V> function, R target, int batchSize, ForkJoinPool executor, boolean allowReorderedResult) { int size = Iterate.sizeOf(iterable); FastListCollectProcedureCombiner<T, V> combiner = new FastListCollectProcedureCombiner<>(iterable, target, size, allowReorderedResult); int taskCount = FJIterate.calculateTaskCount(size, batchSize); FastListCollectProcedureFactory<T, V> procedureFactory = new FastListCollectProcedureFactory<>(function, size / taskCount); FJIterate.forEach( iterable, procedureFactory, combiner, batchSize, taskCount, executor); return (R) combiner.getResult(); }
public boolean addAllIterable(Iterable<? extends T> iterable) { if (iterable instanceof UnifiedSet) { return this.copySet((UnifiedSet<?>) iterable); } int size = Iterate.sizeOf(iterable); this.ensureCapacity(size); int oldSize = this.size(); if (iterable instanceof List && iterable instanceof RandomAccess) { List<T> list = (List<T>) iterable; for (int i = 0; i < size; i++) { this.add(list.get(i)); } } else { Iterate.forEachWith(iterable, Procedures2.<T>addToCollection(), this); } return this.size() != oldSize; }
/** * Assert that the given {@link Iterable} is <em>not</em> empty. */ public static void assertNotEmpty(String iterableName, Iterable<?> actualIterable) { try { Verify.assertObjectNotNull(iterableName, actualIterable); Assert.assertFalse(iterableName + " should be non-empty, but was empty", Iterate.isEmpty(actualIterable)); Assert.assertTrue(iterableName + " should be non-empty, but was empty", Iterate.notEmpty(actualIterable)); Assert.assertNotEquals(iterableName + " should be non-empty, but was empty", 0, Iterate.sizeOf(actualIterable)); } catch (AssertionError e) { Verify.throwMangledException(e); } }
/** * Assert that the given {@link Iterable} is <em>not</em> empty. */ public static void assertIterableNotEmpty(String iterableName, Iterable<?> iterable) { try { Verify.assertObjectNotNull(iterableName, iterable); Assert.assertFalse(iterableName + " should be non-empty, but was empty", Iterate.isEmpty(iterable)); Assert.assertTrue(iterableName + " should be non-empty, but was empty", Iterate.notEmpty(iterable)); Assert.assertNotEquals(iterableName + " should be non-empty, but was empty", 0, Iterate.sizeOf(iterable)); } catch (AssertionError e) { Verify.throwMangledException(e); } }
@Test @Override default void Iterable_remove() { Iterable<Integer> iterable = this.newWith(3, 3, 3, 2, 2, 1); Iterator<Integer> iterator = iterable.iterator(); iterator.next(); iterator.remove(); assertEquals(this.allowsDuplicates() ? 5 : 2, Iterate.sizeOf(iterable)); assertThat( iterable, isOneOf( this.newWith(3, 3, 3, 2, 2), this.newWith(3, 3, 3, 2, 1), this.newWith(3, 3, 2, 2, 1))); } }
@Override default void Iterable_remove() { MutableMap<Object, Integer> iterable = this.newWith(3, 3, 3, 2, 2, 1); Iterator<Integer> iterator = iterable.iterator(); iterator.next(); iterator.remove(); assertEquals(this.allowsDuplicates() ? 5 : 2, Iterate.sizeOf(iterable)); assertThat(iterable.toBag(), isOneOf( this.getExpectedFiltered(3, 3, 3, 2, 2), this.getExpectedFiltered(3, 3, 3, 2, 1), this.getExpectedFiltered(3, 3, 2, 2, 1))); } }