/** * Assert that the given {@link Iterable} is empty. */ public static void assertIterableEmpty(String iterableName, Iterable<?> iterable) { try { Verify.assertObjectNotNull(iterableName, iterable); if (Iterate.notEmpty(iterable)) { Assert.fail(iterableName + " should be empty; actual size:<" + Iterate.sizeOf(iterable) + '>'); } if (!Iterate.isEmpty(iterable)) { Assert.fail(iterableName + " should be empty; actual size:<" + Iterate.sizeOf(iterable) + '>'); } if (Iterate.sizeOf(iterable) != 0) { Assert.fail(iterableName + " should be empty; actual size:<" + Iterate.sizeOf(iterable) + '>'); } } catch (AssertionError e) { Verify.throwMangledException(e); } }
@Override public <V> MutableSet<V> collect(Function<? super T, ? extends V> function) { return Iterate.collect(this.delegate, function, UnifiedSet.<V>newSet()); }
public boolean accept(Object each) { return Iterate.contains(iterable, each); } };
public int intValueOf(Iterable<?> iterable) { return Iterate.sizeOf(iterable); } }
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); }
public void combineAll(Iterable<BT> thingsToCombine) { Iterate.forEach(thingsToCombine, new Procedure<BT>() { public void value(BT object) { AbstractProcedureCombiner.this.combineOne(object); } }); }
public static <T> void assertCount( int expectedCount, Iterable<T> iterable, Predicate<? super T> predicate) { Assert.assertEquals(expectedCount, Iterate.count(iterable, predicate)); }
@Override public MutableSet<T> select(Predicate<? super T> predicate) { return Iterate.select(this.delegate, predicate, UnifiedSet.<T>newSet()); }
@Override public MutableSet<T> reject(Predicate<? super T> predicate) { return Iterate.reject(this.delegate, predicate, UnifiedSet.<T>newSet()); }
@Override public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure) { Iterate.forEachWithIndex(this.adapted, objectIntProcedure); }
@Override public boolean isEmpty() { return Iterate.isEmpty(this.adapted); }
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; }
/** * Assert that the given {@link MutableMapIterable} is <em>not</em> empty. */ public static void assertNotEmpty(String mutableMapIterableName, MutableMapIterable<?, ?> actualMutableMapIterable) { try { Verify.assertObjectNotNull(mutableMapIterableName, actualMutableMapIterable); Assert.assertFalse(mutableMapIterableName + " should be non-empty, but was empty", Iterate.isEmpty(actualMutableMapIterable)); Assert.assertTrue(mutableMapIterableName + " should be non-empty, but was empty", Iterate.notEmpty(actualMutableMapIterable)); Assert.assertTrue(mutableMapIterableName + " should be non-empty, but was empty", actualMutableMapIterable.notEmpty()); Assert.assertNotEquals(mutableMapIterableName + " should be non-empty, but was empty", 0, actualMutableMapIterable.size()); Assert.assertNotEquals(mutableMapIterableName + " should be non-empty, but was empty", 0, actualMutableMapIterable.keySet().size()); Assert.assertNotEquals(mutableMapIterableName + " should be non-empty, but was empty", 0, actualMutableMapIterable.values().size()); Assert.assertNotEquals(mutableMapIterableName + " should be non-empty, but was empty", 0, actualMutableMapIterable.entrySet().size()); } catch (AssertionError e) { Verify.throwMangledException(e); } }
public boolean putAll(K key, Iterable<? extends V> values) { return Iterate.notEmpty(values) && this.putAllNotEmpty(key, values); }
public C replaceValues(K key, Iterable<? extends V> values) { if (Iterate.isEmpty(values)) { return this.removeAll(key); } C newValues = Iterate.addAllTo(values, this.createCollection()); C oldValues = this.map.put(key, newValues); oldValues = oldValues == null ? this.createCollection() : oldValues; this.addToTotalSize(newValues.size() - oldValues.size()); return (C) oldValues.asUnmodifiable(); }
@Override public int size() { return Iterate.sizeOf(this.adapted); }
public void value(final K key, Iterable<V> values) { Iterate.forEach(values, new Procedure<V>() { public void value(V value) { result.put(value, key); } }); } });