Search in sources :

Example 6 with MutableInteger

use of org.eclipse.collections.impl.math.MutableInteger in project eclipse-collections by eclipse.

the class IntIntervalTest method injectInto.

@Test
public void injectInto() {
    IntInterval intInterval1 = IntInterval.oneTo(3);
    MutableInteger result = intInterval1.injectInto(new MutableInteger(0), MutableInteger::add);
    Assert.assertEquals(new MutableInteger(6), result);
    IntInterval intInterval2 = IntInterval.fromTo(3, 1);
    MutableInteger result2 = intInterval2.injectInto(new MutableInteger(0), MutableInteger::add);
    Assert.assertEquals(new MutableInteger(6), result2);
}
Also used : MutableInteger(org.eclipse.collections.impl.math.MutableInteger) Test(org.junit.Test)

Example 7 with MutableInteger

use of org.eclipse.collections.impl.math.MutableInteger in project eclipse-collections by eclipse.

the class AbstractImmutableBooleanListTestCase method injectIntoWithIndex.

@Test
public void injectIntoWithIndex() {
    ImmutableBooleanList list = this.newWith(true, false, true);
    MutableInteger result = list.injectIntoWithIndex(new MutableInteger(0), (object, value, index) -> object.add((value ? 1 : 0) + index));
    Assert.assertEquals(new MutableInteger(5), result);
}
Also used : MutableInteger(org.eclipse.collections.impl.math.MutableInteger) ImmutableBooleanList(org.eclipse.collections.api.list.primitive.ImmutableBooleanList) Test(org.junit.Test)

Example 8 with MutableInteger

use of org.eclipse.collections.impl.math.MutableInteger in project eclipse-collections by eclipse.

the class ImmutableBooleanHashSetTest method injectInto.

@Override
@Test
public void injectInto() {
    ObjectBooleanToObjectFunction<MutableInteger, MutableInteger> function = (object, value) -> object.add(value ? 1 : 0);
    Assert.assertEquals(new MutableInteger(1), BooleanHashSet.newSetWith(true, false, true).injectInto(new MutableInteger(0), function));
    Assert.assertEquals(new MutableInteger(1), BooleanHashSet.newSetWith(true).injectInto(new MutableInteger(0), function));
    Assert.assertEquals(new MutableInteger(0), BooleanHashSet.newSetWith(false).injectInto(new MutableInteger(0), function));
    Assert.assertEquals(new MutableInteger(0), new BooleanHashSet().injectInto(new MutableInteger(0), function));
}
Also used : BooleanToObjectFunction(org.eclipse.collections.api.block.function.primitive.BooleanToObjectFunction) AbstractImmutableBooleanCollectionTestCase(org.eclipse.collections.impl.collection.immutable.primitive.AbstractImmutableBooleanCollectionTestCase) Arrays(java.util.Arrays) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) Test(org.junit.Test) ImmutableBooleanSet(org.eclipse.collections.api.set.primitive.ImmutableBooleanSet) BooleanPredicates(org.eclipse.collections.impl.block.factory.primitive.BooleanPredicates) Verify(org.eclipse.collections.impl.test.Verify) ImmutableBooleanCollection(org.eclipse.collections.api.collection.primitive.ImmutableBooleanCollection) MutableSet(org.eclipse.collections.api.set.MutableSet) MutableBooleanSet(org.eclipse.collections.api.set.primitive.MutableBooleanSet) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) ObjectBooleanToObjectFunction(org.eclipse.collections.api.block.function.primitive.ObjectBooleanToObjectFunction) NoSuchElementException(java.util.NoSuchElementException) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) Assert(org.junit.Assert) MutableInteger(org.eclipse.collections.impl.math.MutableInteger) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Before(org.junit.Before) MutableInteger(org.eclipse.collections.impl.math.MutableInteger) Test(org.junit.Test)

Example 9 with MutableInteger

use of org.eclipse.collections.impl.math.MutableInteger in project eclipse-collections by eclipse.

the class AbstractBooleanListTestCase method injectIntoWithIndex.

@Test
public void injectIntoWithIndex() {
    MutableBooleanList list = this.newWith(true, false, true);
    MutableInteger result = list.injectIntoWithIndex(new MutableInteger(0), (object, value, index) -> object.add((value ? 1 : 0) + index));
    Assert.assertEquals(new MutableInteger(5), result);
}
Also used : MutableInteger(org.eclipse.collections.impl.math.MutableInteger) MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) Test(org.junit.Test)

Aggregations

MutableInteger (org.eclipse.collections.impl.math.MutableInteger)9 Test (org.junit.Test)9 LazyBooleanIterable (org.eclipse.collections.api.LazyBooleanIterable)3 Arrays (java.util.Arrays)2 NoSuchElementException (java.util.NoSuchElementException)2 BooleanToObjectFunction (org.eclipse.collections.api.block.function.primitive.BooleanToObjectFunction)2 ObjectBooleanToObjectFunction (org.eclipse.collections.api.block.function.primitive.ObjectBooleanToObjectFunction)2 BooleanIterator (org.eclipse.collections.api.iterator.BooleanIterator)2 MutableSet (org.eclipse.collections.api.set.MutableSet)2 MutableBooleanSet (org.eclipse.collections.api.set.primitive.MutableBooleanSet)2 BooleanHashBag (org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag)2 BooleanPredicates (org.eclipse.collections.impl.block.factory.primitive.BooleanPredicates)2 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)2 UnifiedSet (org.eclipse.collections.impl.set.mutable.UnifiedSet)2 Verify (org.eclipse.collections.impl.test.Verify)2 Assert (org.junit.Assert)2 Before (org.junit.Before)2 BooleanIterable (org.eclipse.collections.api.BooleanIterable)1 ImmutableBooleanCollection (org.eclipse.collections.api.collection.primitive.ImmutableBooleanCollection)1 MutableBooleanCollection (org.eclipse.collections.api.collection.primitive.MutableBooleanCollection)1