use of org.eclipse.collections.api.IntIterable in project eclipse-collections by eclipse.
the class IntInterval 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()) {
int innerFrom = this.from;
int lastUpdated = this.from;
if (this.from <= this.to) {
while ((lastUpdated + this.step) <= this.to) {
MutableIntList batch = IntLists.mutable.empty();
for (int i = innerFrom; i <= this.to && batch.size() < size; i += this.step) {
batch.add(i);
lastUpdated = i;
}
result.add(batch);
innerFrom = lastUpdated + this.step;
}
} else {
while ((lastUpdated + this.step) >= this.to) {
MutableIntList batch = IntLists.mutable.empty();
for (int i = innerFrom; i >= this.to && batch.size() < size; i += this.step) {
batch.add(i);
lastUpdated = i;
}
result.add(batch);
innerFrom = lastUpdated + this.step;
}
}
}
return result;
}
use of org.eclipse.collections.api.IntIterable in project eclipse-collections by eclipse.
the class AbstractRichIterableTestCase method collectInt.
@Test
public void collectInt() {
IntIterable result = this.newWith(1, 2, 3, 4).collectInt(PrimitiveFunctions.unboxIntegerToInt());
Assert.assertEquals(IntBags.mutable.of(1, 2, 3, 4), result.toBag());
Assert.assertEquals(IntBags.mutable.of(1, 2, 3, 4), IntBags.mutable.ofAll(result));
}
use of org.eclipse.collections.api.IntIterable in project eclipse-collections by eclipse.
the class CodePointAdapterTest 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 CodePointAdapterTest method allSatisfy.
@Override
@Test
public void allSatisfy() {
Assert.assertFalse(this.newWith(1, 0, 2).allSatisfy(IntPredicates.greaterThan(0)));
Assert.assertTrue(this.newWith(1, 2, 3).allSatisfy(IntPredicates.greaterThan(0)));
Assert.assertFalse(this.newWith(1, 0, 31, 32).allSatisfy(IntPredicates.greaterThan(0)));
Assert.assertFalse(this.newWith(1, 0, 31, 32).allSatisfy(IntPredicates.greaterThan(0)));
Assert.assertTrue(this.newWith(1, 2, 31, 32).allSatisfy(IntPredicates.greaterThan(0)));
Assert.assertFalse(this.newWith(32).allSatisfy(IntPredicates.equal(33)));
IntIterable iterable = this.newWith(0, 1, 2);
Assert.assertFalse(iterable.allSatisfy(value -> 3 < value));
Assert.assertTrue(iterable.allSatisfy(IntPredicates.lessThan(3)));
IntIterable iterable1 = this.classUnderTest();
int size = iterable1.size();
Assert.assertEquals(size == 0, iterable1.allSatisfy(IntPredicates.greaterThan(3)));
Assert.assertEquals(size < 3, iterable1.allSatisfy(IntPredicates.lessThan(3)));
}
use of org.eclipse.collections.api.IntIterable in project eclipse-collections by eclipse.
the class CodePointListTest method allSatisfy.
@Override
@Test
public void allSatisfy() {
Assert.assertFalse(this.newWith(1, 0, 2).allSatisfy(IntPredicates.greaterThan(0)));
Assert.assertTrue(this.newWith(1, 2, 3).allSatisfy(IntPredicates.greaterThan(0)));
Assert.assertFalse(this.newWith(1, 0, 31, 32).allSatisfy(IntPredicates.greaterThan(0)));
Assert.assertFalse(this.newWith(1, 0, 31, 32).allSatisfy(IntPredicates.greaterThan(0)));
Assert.assertTrue(this.newWith(1, 2, 31, 32).allSatisfy(IntPredicates.greaterThan(0)));
Assert.assertFalse(this.newWith(32).allSatisfy(IntPredicates.equal(33)));
IntIterable iterable = this.newWith(0, 1, 2);
Assert.assertFalse(iterable.allSatisfy(value -> 3 < value));
Assert.assertTrue(iterable.allSatisfy(IntPredicates.lessThan(3)));
IntIterable iterable1 = this.classUnderTest();
int size = iterable1.size();
Assert.assertEquals(size == 0, iterable1.allSatisfy(IntPredicates.greaterThan(3)));
Assert.assertEquals(size < 3, iterable1.allSatisfy(IntPredicates.lessThan(3)));
}
Aggregations