Search in sources :

Example 1 with IntIterable

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;
}
Also used : MutableIntList(org.eclipse.collections.api.list.primitive.MutableIntList) IntIterable(org.eclipse.collections.api.IntIterable) SelectIntIterable(org.eclipse.collections.impl.lazy.primitive.SelectIntIterable) ReverseIntIterable(org.eclipse.collections.impl.lazy.primitive.ReverseIntIterable) LazyIntIterable(org.eclipse.collections.api.LazyIntIterable)

Example 2 with IntIterable

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));
}
Also used : IntIterable(org.eclipse.collections.api.IntIterable) Test(org.junit.Test)

Example 3 with IntIterable

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)));
}
Also used : AbstractImmutableIntListTestCase(org.eclipse.collections.impl.list.immutable.primitive.AbstractImmutableIntListTestCase) IntIterable(org.eclipse.collections.api.IntIterable) IntPredicates(org.eclipse.collections.impl.block.factory.primitive.IntPredicates) Test(org.junit.Test) ImmutableIntList(org.eclipse.collections.api.list.primitive.ImmutableIntList) Verify(org.eclipse.collections.impl.test.Verify) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) IntIterable(org.eclipse.collections.api.IntIterable) Test(org.junit.Test)

Example 4 with IntIterable

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)));
}
Also used : AbstractImmutableIntListTestCase(org.eclipse.collections.impl.list.immutable.primitive.AbstractImmutableIntListTestCase) IntIterable(org.eclipse.collections.api.IntIterable) IntPredicates(org.eclipse.collections.impl.block.factory.primitive.IntPredicates) Test(org.junit.Test) ImmutableIntList(org.eclipse.collections.api.list.primitive.ImmutableIntList) Verify(org.eclipse.collections.impl.test.Verify) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) IntIterable(org.eclipse.collections.api.IntIterable) Test(org.junit.Test)

Example 5 with IntIterable

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)));
}
Also used : AbstractImmutableIntListTestCase(org.eclipse.collections.impl.list.immutable.primitive.AbstractImmutableIntListTestCase) IntIterable(org.eclipse.collections.api.IntIterable) IntPredicates(org.eclipse.collections.impl.block.factory.primitive.IntPredicates) Test(org.junit.Test) ImmutableIntList(org.eclipse.collections.api.list.primitive.ImmutableIntList) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) IntIterable(org.eclipse.collections.api.IntIterable) Test(org.junit.Test)

Aggregations

IntIterable (org.eclipse.collections.api.IntIterable)9 Test (org.junit.Test)7 Collectors (java.util.stream.Collectors)4 ImmutableIntList (org.eclipse.collections.api.list.primitive.ImmutableIntList)4 IntPredicates (org.eclipse.collections.impl.block.factory.primitive.IntPredicates)4 AbstractImmutableIntListTestCase (org.eclipse.collections.impl.list.immutable.primitive.AbstractImmutableIntListTestCase)4 Assert (org.junit.Assert)4 LazyIntIterable (org.eclipse.collections.api.LazyIntIterable)2 MutableIntList (org.eclipse.collections.api.list.primitive.MutableIntList)2 ReverseIntIterable (org.eclipse.collections.impl.lazy.primitive.ReverseIntIterable)2 Verify (org.eclipse.collections.impl.test.Verify)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MutableIntCollection (org.eclipse.collections.api.collection.primitive.MutableIntCollection)1 IntIterator (org.eclipse.collections.api.iterator.IntIterator)1 SelectIntIterable (org.eclipse.collections.impl.lazy.primitive.SelectIntIterable)1 IntArrayList (org.eclipse.collections.impl.list.mutable.primitive.IntArrayList)1 AbstractIntIterable (org.eclipse.collections.impl.primitive.AbstractIntIterable)1