Search in sources :

Example 1 with Function3

use of org.eclipse.collections.api.block.function.Function3 in project eclipse-collections by eclipse.

the class ArrayListIterateTest method injectIntoWithOver100.

@Test
public void injectIntoWithOver100() {
    Sum result = new IntegerSum(0);
    Integer parameter = 2;
    Function3<Sum, Integer, Integer, Sum> function = (sum, element, withValue) -> sum.add((element.intValue() - element.intValue()) * withValue.intValue());
    Sum sumOfDoubledValues = ArrayListIterate.injectIntoWith(result, this.getOver100IntegerList(), function, parameter);
    Assert.assertEquals(0, sumOfDoubledValues.getValue().intValue());
}
Also used : Procedures2(org.eclipse.collections.impl.block.factory.Procedures2) Iterables.mList(org.eclipse.collections.impl.factory.Iterables.mList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) MutableIntList(org.eclipse.collections.api.list.primitive.MutableIntList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) MutableList(org.eclipse.collections.api.list.MutableList) FastListMultimap(org.eclipse.collections.impl.multimap.list.FastListMultimap) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Tuples(org.eclipse.collections.impl.tuple.Tuples) Interval(org.eclipse.collections.impl.list.Interval) MutableFloatList(org.eclipse.collections.api.list.primitive.MutableFloatList) MutableShortList(org.eclipse.collections.api.list.primitive.MutableShortList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) Collection(java.util.Collection) Twin(org.eclipse.collections.api.tuple.Twin) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) List(java.util.List) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) MutableDoubleList(org.eclipse.collections.api.list.primitive.MutableDoubleList) MinSizeFunction(org.eclipse.collections.impl.block.function.MinSizeFunction) Iterables.iList(org.eclipse.collections.impl.factory.Iterables.iList) Lists(org.eclipse.collections.impl.factory.Lists) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Function(org.eclipse.collections.api.block.function.Function) Sum(org.eclipse.collections.impl.math.Sum) MutableByteList(org.eclipse.collections.api.list.primitive.MutableByteList) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) Function3(org.eclipse.collections.api.block.function.Function3) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) PartitionMutableList(org.eclipse.collections.api.partition.list.PartitionMutableList) Pair(org.eclipse.collections.api.tuple.Pair) PrimitiveFunctions(org.eclipse.collections.impl.block.factory.PrimitiveFunctions) Predicates(org.eclipse.collections.impl.block.factory.Predicates) MutableCharList(org.eclipse.collections.api.list.primitive.MutableCharList) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) Test(org.junit.Test) MaxSizeFunction(org.eclipse.collections.impl.block.function.MaxSizeFunction) ObjectIntProcedures(org.eclipse.collections.impl.block.factory.ObjectIntProcedures) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) Assert(org.junit.Assert) Collections(java.util.Collections) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Test(org.junit.Test)

Example 2 with Function3

use of org.eclipse.collections.api.block.function.Function3 in project eclipse-collections by eclipse.

the class IterateTest method basicTestDoubleSum.

private void basicTestDoubleSum(Sum newResult, Collection<Integer> newIntegers, Integer newParameter) {
    Function3<Sum, Integer, Integer, Sum> function = (sum, element, withValue) -> sum.add(element.intValue() * withValue.intValue());
    Sum sumOfDoubledValues = Iterate.injectIntoWith(newResult, newIntegers, function, newParameter);
    Assert.assertEquals(30, sumOfDoubledValues.getValue().intValue());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) Maps(org.eclipse.collections.impl.factory.Maps) Arrays(java.util.Arrays) Multimap(org.eclipse.collections.api.multimap.Multimap) Iterables.mList(org.eclipse.collections.impl.factory.Iterables.mList) PairPredicate(org.eclipse.collections.impl.block.predicate.PairPredicate) Verify(org.eclipse.collections.impl.test.Verify) StringFunctions(org.eclipse.collections.impl.block.factory.StringFunctions) MutableList(org.eclipse.collections.api.list.MutableList) FastListMultimap(org.eclipse.collections.impl.multimap.list.FastListMultimap) UnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.UnifiedSetMultimap) BigDecimal(java.math.BigDecimal) MutableSet(org.eclipse.collections.api.set.MutableSet) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) RichIterable(org.eclipse.collections.api.RichIterable) MutableLongCollection(org.eclipse.collections.api.collection.primitive.MutableLongCollection) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Functions(org.eclipse.collections.impl.block.factory.Functions) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) TreeBagMultimap(org.eclipse.collections.impl.multimap.bag.sorted.mutable.TreeBagMultimap) Tuples(org.eclipse.collections.impl.tuple.Tuples) Interval(org.eclipse.collections.impl.list.Interval) BigInteger(java.math.BigInteger) Comparators(org.eclipse.collections.impl.block.factory.Comparators) MutableCharCollection(org.eclipse.collections.api.collection.primitive.MutableCharCollection) MutableListMultimap(org.eclipse.collections.api.multimap.list.MutableListMultimap) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) MutableIntCollection(org.eclipse.collections.api.collection.primitive.MutableIntCollection) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) MutableSortedBagMultimap(org.eclipse.collections.api.multimap.sortedbag.MutableSortedBagMultimap) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) Collection(java.util.Collection) Twin(org.eclipse.collections.api.tuple.Twin) Set(java.util.Set) ObjectDoubleMap(org.eclipse.collections.api.map.primitive.ObjectDoubleMap) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) Procedures(org.eclipse.collections.impl.block.factory.Procedures) MutableBagMultimap(org.eclipse.collections.api.multimap.bag.MutableBagMultimap) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) TreeSortedSetMultimap(org.eclipse.collections.impl.multimap.set.sorted.TreeSortedSetMultimap) List(java.util.List) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) ObjectLongMap(org.eclipse.collections.api.map.primitive.ObjectLongMap) MinSizeFunction(org.eclipse.collections.impl.block.function.MinSizeFunction) Iterables.iList(org.eclipse.collections.impl.factory.Iterables.iList) Lists(org.eclipse.collections.impl.factory.Lists) Optional(java.util.Optional) MutableByteCollection(org.eclipse.collections.api.collection.primitive.MutableByteCollection) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Function(org.eclipse.collections.api.block.function.Function) MutableShortCollection(org.eclipse.collections.api.collection.primitive.MutableShortCollection) Iterables.iBag(org.eclipse.collections.impl.factory.Iterables.iBag) Sum(org.eclipse.collections.impl.math.Sum) TreeSet(java.util.TreeSet) Multimaps(org.eclipse.collections.impl.factory.Multimaps) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Function3(org.eclipse.collections.api.block.function.Function3) Function0(org.eclipse.collections.api.block.function.Function0) MutableMap(org.eclipse.collections.api.map.MutableMap) HashBagMultimap(org.eclipse.collections.impl.multimap.bag.HashBagMultimap) Function2(org.eclipse.collections.api.block.function.Function2) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableSetMultimap(org.eclipse.collections.api.multimap.set.MutableSetMultimap) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) Pair(org.eclipse.collections.api.tuple.Pair) PrimitiveFunctions(org.eclipse.collections.impl.block.factory.PrimitiveFunctions) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) MutableSortedSetMultimap(org.eclipse.collections.api.multimap.sortedset.MutableSortedSetMultimap) Collectors2(org.eclipse.collections.impl.collector.Collectors2) MutableFloatCollection(org.eclipse.collections.api.collection.primitive.MutableFloatCollection) Iterator(java.util.Iterator) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) MutableDoubleCollection(org.eclipse.collections.api.collection.primitive.MutableDoubleCollection) Bags(org.eclipse.collections.impl.factory.Bags) Test(org.junit.Test) MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) Iterables.iSet(org.eclipse.collections.impl.factory.Iterables.iSet) MaxSizeFunction(org.eclipse.collections.impl.block.function.MaxSizeFunction) ImmutableList(org.eclipse.collections.api.list.ImmutableList) BagMultimap(org.eclipse.collections.api.multimap.bag.BagMultimap) ObjectIntProcedures(org.eclipse.collections.impl.block.factory.ObjectIntProcedures) Sets(org.eclipse.collections.impl.factory.Sets) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) MapIterable(org.eclipse.collections.api.map.MapIterable) PartitionIterable(org.eclipse.collections.api.partition.PartitionIterable) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) Assert(org.junit.Assert) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum)

Example 3 with Function3

use of org.eclipse.collections.api.block.function.Function3 in project eclipse-collections by eclipse.

the class IterableIterateTest method injectIntoWith.

@Test
public void injectIntoWith() {
    Sum result = new IntegerSum(0);
    Iterable<Integer> iterable = new IterableAdapter<>(Interval.oneTo(5));
    Function3<Sum, Integer, Integer, Sum> function = (sum, element, withValue) -> sum.add(element.intValue() * withValue.intValue());
    Sum sumOfDoubledValues = Iterate.injectIntoWith(result, iterable, function, 2);
    Assert.assertEquals(30, sumOfDoubledValues.getValue().intValue());
}
Also used : Iterables.mList(org.eclipse.collections.impl.factory.Iterables.mList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) Sum(org.eclipse.collections.impl.math.Sum) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) Function3(org.eclipse.collections.api.block.function.Function3) Interval(org.eclipse.collections.impl.list.Interval) LinkedList(java.util.LinkedList) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) Iterator(java.util.Iterator) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) Collection(java.util.Collection) Twin(org.eclipse.collections.api.tuple.Twin) Test(org.junit.Test) Iterate(org.eclipse.collections.impl.utility.Iterate) ListIterate(org.eclipse.collections.impl.utility.ListIterate) Objects(java.util.Objects) List(java.util.List) MaxSizeFunction(org.eclipse.collections.impl.block.function.MaxSizeFunction) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) MinSizeFunction(org.eclipse.collections.impl.block.function.MinSizeFunction) Iterables.iList(org.eclipse.collections.impl.factory.Iterables.iList) ImmutableList(org.eclipse.collections.api.list.ImmutableList) Lists(org.eclipse.collections.impl.factory.Lists) ObjectIntProcedures(org.eclipse.collections.impl.block.factory.ObjectIntProcedures) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Optional(java.util.Optional) PartitionIterable(org.eclipse.collections.api.partition.PartitionIterable) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) Assert(org.junit.Assert) Collections(java.util.Collections) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Test(org.junit.Test)

Example 4 with Function3

use of org.eclipse.collections.api.block.function.Function3 in project eclipse-collections by eclipse.

the class IterableIterateTest method injectIntoWithOver30.

@Test
public void injectIntoWithOver30() {
    Sum result = new IntegerSum(0);
    Integer parameter = 2;
    List<Integer> integers = Interval.oneTo(31);
    Function3<Sum, Integer, Integer, Sum> function = (sum, element, withValue) -> sum.add((element.intValue() - element.intValue()) * withValue.intValue());
    Sum sumOfDoubledValues = Iterate.injectIntoWith(result, integers, function, parameter);
    Assert.assertEquals(0, sumOfDoubledValues.getValue().intValue());
}
Also used : Iterables.mList(org.eclipse.collections.impl.factory.Iterables.mList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) Sum(org.eclipse.collections.impl.math.Sum) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) Function3(org.eclipse.collections.api.block.function.Function3) Interval(org.eclipse.collections.impl.list.Interval) LinkedList(java.util.LinkedList) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) Iterator(java.util.Iterator) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) Collection(java.util.Collection) Twin(org.eclipse.collections.api.tuple.Twin) Test(org.junit.Test) Iterate(org.eclipse.collections.impl.utility.Iterate) ListIterate(org.eclipse.collections.impl.utility.ListIterate) Objects(java.util.Objects) List(java.util.List) MaxSizeFunction(org.eclipse.collections.impl.block.function.MaxSizeFunction) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) MinSizeFunction(org.eclipse.collections.impl.block.function.MinSizeFunction) Iterables.iList(org.eclipse.collections.impl.factory.Iterables.iList) ImmutableList(org.eclipse.collections.api.list.ImmutableList) Lists(org.eclipse.collections.impl.factory.Lists) ObjectIntProcedures(org.eclipse.collections.impl.block.factory.ObjectIntProcedures) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Optional(java.util.Optional) PartitionIterable(org.eclipse.collections.api.partition.PartitionIterable) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) Assert(org.junit.Assert) Collections(java.util.Collections) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 List (java.util.List)4 Function3 (org.eclipse.collections.api.block.function.Function3)4 MutableList (org.eclipse.collections.api.list.MutableList)4 Twin (org.eclipse.collections.api.tuple.Twin)4 ObjectIntProcedures (org.eclipse.collections.impl.block.factory.ObjectIntProcedures)4 Predicates (org.eclipse.collections.impl.block.factory.Predicates)4 Predicates2 (org.eclipse.collections.impl.block.factory.Predicates2)4 AddFunction (org.eclipse.collections.impl.block.function.AddFunction)4 MaxSizeFunction (org.eclipse.collections.impl.block.function.MaxSizeFunction)4 MinSizeFunction (org.eclipse.collections.impl.block.function.MinSizeFunction)4 Iterables.iList (org.eclipse.collections.impl.factory.Iterables.iList)4 Iterables.mList (org.eclipse.collections.impl.factory.Iterables.mList)4 Lists (org.eclipse.collections.impl.factory.Lists)4 Interval (org.eclipse.collections.impl.list.Interval)4 FastList (org.eclipse.collections.impl.list.mutable.FastList)4 IntegerSum (org.eclipse.collections.impl.math.IntegerSum)4 Sum (org.eclipse.collections.impl.math.Sum)4