Search in sources :

Example 6 with IntIterable

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

Example 7 with IntIterable

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());
}
Also used : MutableIntCollection(org.eclipse.collections.api.collection.primitive.MutableIntCollection) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) IntIterable(org.eclipse.collections.api.IntIterable) Test(org.junit.Test)

Example 8 with IntIterable

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)));
}
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)

Example 9 with IntIterable

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

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