use of org.eclipse.collections.api.IntIterable in project eclipse-collections by eclipse.
the class MapIterableTestCase method collectInt.
@Test
public void collectInt() {
MapIterable<String, String> map = this.newMapWithKeysValues("One", "1", "Two", "2", "Three", "3");
IntIterable actual = map.collectInt(Integer::parseInt);
Assert.assertEquals(IntHashBag.newBagWith(1, 2, 3), actual.toBag());
}
use of org.eclipse.collections.api.IntIterable in project eclipse-collections by eclipse.
the class AbstractRichIterableTestCase method collectIntWithTarget.
@Test
public void collectIntWithTarget() {
MutableIntCollection target = new IntArrayList();
IntIterable result = this.newWith(1, 2, 3, 4).collectInt(PrimitiveFunctions.unboxIntegerToInt(), target);
Assert.assertSame("Target list sent as parameter not returned", target, result);
Assert.assertEquals(IntHashBag.newBagWith(1, 2, 3, 4), result.toBag());
}
use of org.eclipse.collections.api.IntIterable in project eclipse-collections by eclipse.
the class CodePointListTest method anySatisfy.
@Override
@Test
public void anySatisfy() {
Assert.assertTrue(this.newWith(1, 2).anySatisfy(IntPredicates.greaterThan(0)));
Assert.assertFalse(this.newWith(1, 2).anySatisfy(IntPredicates.equal(0)));
Assert.assertTrue(this.newWith(31, 32).anySatisfy(IntPredicates.greaterThan(0)));
Assert.assertTrue(this.newWith(2, 31, 32).anySatisfy(IntPredicates.greaterThan(0)));
Assert.assertFalse(this.newWith(1, 31, 32).anySatisfy(IntPredicates.equal(0)));
Assert.assertTrue(this.newWith(32).anySatisfy(IntPredicates.greaterThan(0)));
IntIterable iterable = this.newWith(0, 1, 2);
Assert.assertTrue(iterable.anySatisfy(value -> value < 3));
Assert.assertFalse(iterable.anySatisfy(IntPredicates.greaterThan(3)));
IntIterable iterable1 = this.classUnderTest();
int size = iterable1.size();
Assert.assertEquals(size > 3, iterable1.anySatisfy(IntPredicates.greaterThan(3)));
Assert.assertEquals(size != 0, iterable1.anySatisfy(IntPredicates.lessThan(3)));
}
use of org.eclipse.collections.api.IntIterable in project eclipse-collections by eclipse.
the class CodePointAdapter method chunk.
@Override
public RichIterable<IntIterable> chunk(int size) {
if (size <= 0) {
throw new IllegalArgumentException("Size for groups must be positive but was: " + size);
}
MutableList<IntIterable> result = Lists.mutable.empty();
if (this.notEmpty()) {
if (this.size() <= size) {
result.add(IntLists.immutable.withAll(this));
} else {
IntIterator iterator = this.intIterator();
while (iterator.hasNext()) {
MutableIntList batch = IntLists.mutable.empty();
for (int i = 0; i < size && iterator.hasNext(); i++) {
batch.add(iterator.next());
}
result.add(CodePointList.from(batch));
}
}
}
return result.toImmutable();
}
Aggregations