Search in sources :

Example 1 with MutableInteger

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

the class SelectBooleanIterableTest method injectInto.

@Test
public void injectInto() {
    MutableInteger result = this.iterable.injectInto(new MutableInteger(0), (object, value) -> object.add(value ? 1 : 0));
    Assert.assertEquals(new MutableInteger(2), result);
}
Also used : MutableInteger(org.eclipse.collections.impl.math.MutableInteger) Test(org.junit.Test)

Example 2 with MutableInteger

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

the class TapBooleanIterableTest method injectInto.

@Test
public void injectInto() {
    StringBuilder concat = new StringBuilder();
    TapBooleanIterable iterable = new TapBooleanIterable(this.list, concat::append);
    MutableInteger result = iterable.injectInto(new MutableInteger(0), (object, value) -> object.add(value ? 1 : 0));
    Assert.assertEquals(new MutableInteger(2), result);
    Assert.assertEquals("truefalsefalsetrue", concat.toString());
}
Also used : MutableInteger(org.eclipse.collections.impl.math.MutableInteger) Test(org.junit.Test)

Example 3 with MutableInteger

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

the class AbstractBooleanSetTestCase 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) Arrays(java.util.Arrays) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) Test(org.junit.Test) BooleanPredicates(org.eclipse.collections.impl.block.factory.primitive.BooleanPredicates) Verify(org.eclipse.collections.impl.test.Verify) MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) 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) AbstractMutableBooleanCollectionTestCase(org.eclipse.collections.impl.collection.mutable.primitive.AbstractMutableBooleanCollectionTestCase) 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 4 with MutableInteger

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

the class AbstractBooleanIterableTestCase method injectInto.

@Test
public void injectInto() {
    BooleanIterable iterable = this.newWith(true, false, true);
    MutableInteger result = iterable.injectInto(new MutableInteger(0), (object, value) -> object.add(value ? 1 : 0));
    Assert.assertEquals(new MutableInteger(2), result);
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) MutableInteger(org.eclipse.collections.impl.math.MutableInteger) Test(org.junit.Test)

Example 5 with MutableInteger

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

the class IntIntervalTest method injectIntoWithIndex.

@Test
public void injectIntoWithIndex() {
    IntInterval interval1 = IntInterval.oneTo(3);
    MutableInteger result1 = this.intInterval.injectIntoWithIndex(new MutableInteger(0), (object, value, index) -> object.add(value * interval1.get(index)));
    Assert.assertEquals(new MutableInteger(14), result1);
    IntInterval interval2 = IntInterval.fromTo(3, 1);
    MutableInteger result2 = interval2.injectIntoWithIndex(new MutableInteger(0), (object, value, index) -> object.add(value * this.intInterval.get(index)));
    Assert.assertEquals(new MutableInteger(10), result2);
}
Also used : MutableInteger(org.eclipse.collections.impl.math.MutableInteger) 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