Search in sources :

Example 1 with Function

use of org.eclipse.collections.api.block.function.Function 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 Function

use of org.eclipse.collections.api.block.function.Function 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 Function

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

the class AbstractParallelIterable method count.

@Override
public int count(Predicate<? super T> predicate) {
    Function<Batch<T>, Integer> map = batch -> batch.count(predicate);
    Counter state = new Counter();
    this.collectCombineUnordered(map, Counter::add, state);
    return state.getCount();
}
Also used : Predicate(org.eclipse.collections.api.block.predicate.Predicate) Predicate2(org.eclipse.collections.api.block.predicate.Predicate2) CompositeFastList(org.eclipse.collections.impl.list.mutable.CompositeFastList) MutableBag(org.eclipse.collections.api.bag.MutableBag) MutableList(org.eclipse.collections.api.list.MutableList) Functions2(org.eclipse.collections.impl.block.factory.Functions2) CompletionService(java.util.concurrent.CompletionService) MutableSortedMap(org.eclipse.collections.api.map.sorted.MutableSortedMap) MutableSet(org.eclipse.collections.api.set.MutableSet) Future(java.util.concurrent.Future) MutatingAggregationProcedure(org.eclipse.collections.impl.block.procedure.MutatingAggregationProcedure) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) DoubleFunction(org.eclipse.collections.api.block.function.primitive.DoubleFunction) NonMutatingAggregationProcedure(org.eclipse.collections.impl.block.procedure.NonMutatingAggregationProcedure) Comparators(org.eclipse.collections.impl.block.factory.Comparators) LongFunction(org.eclipse.collections.api.block.function.primitive.LongFunction) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) CheckedProcedure2(org.eclipse.collections.impl.block.procedure.checked.CheckedProcedure2) Set(java.util.Set) MutableSortedBag(org.eclipse.collections.api.bag.sorted.MutableSortedBag) Procedures(org.eclipse.collections.impl.block.factory.Procedures) MutableSortedSet(org.eclipse.collections.api.set.sorted.MutableSortedSet) TreeSortedSet(org.eclipse.collections.impl.set.sorted.mutable.TreeSortedSet) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) FloatFunction(org.eclipse.collections.api.block.function.primitive.FloatFunction) ConcurrentHashMap(org.eclipse.collections.impl.map.mutable.ConcurrentHashMap) Beta(org.eclipse.collections.api.annotation.Beta) Function(org.eclipse.collections.api.block.function.Function) Callable(java.util.concurrent.Callable) Procedure(org.eclipse.collections.api.block.procedure.Procedure) SetAdapter(org.eclipse.collections.impl.set.mutable.SetAdapter) FastList(org.eclipse.collections.impl.list.mutable.FastList) ParallelIterable(org.eclipse.collections.api.ParallelIterable) LazyIterable(org.eclipse.collections.api.LazyIterable) Function0(org.eclipse.collections.api.block.function.Function0) MutableMap(org.eclipse.collections.api.map.MutableMap) Function2(org.eclipse.collections.api.block.function.Function2) TreeBag(org.eclipse.collections.impl.bag.sorted.mutable.TreeBag) NoSuchElementException(java.util.NoSuchElementException) ExecutorService(java.util.concurrent.ExecutorService) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Counter(org.eclipse.collections.impl.Counter) TreeSortedMap(org.eclipse.collections.impl.map.sorted.mutable.TreeSortedMap) IOException(java.io.IOException) IntFunction(org.eclipse.collections.api.block.function.primitive.IntFunction) ExecutionException(java.util.concurrent.ExecutionException) DoubleSumResultHolder(org.eclipse.collections.impl.block.procedure.DoubleSumResultHolder) MapCollectProcedure(org.eclipse.collections.impl.block.procedure.MapCollectProcedure) ConcurrentHashMapUnsafe(org.eclipse.collections.impl.map.mutable.ConcurrentHashMapUnsafe) MapIterable(org.eclipse.collections.api.map.MapIterable) Comparator(java.util.Comparator) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) Counter(org.eclipse.collections.impl.Counter)

Aggregations

Collections (java.util.Collections)3 Function (org.eclipse.collections.api.block.function.Function)3 MutableList (org.eclipse.collections.api.list.MutableList)3 Predicates (org.eclipse.collections.impl.block.factory.Predicates)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Function3 (org.eclipse.collections.api.block.function.Function3)2 MutableMultimap (org.eclipse.collections.api.multimap.MutableMultimap)2 Pair (org.eclipse.collections.api.tuple.Pair)2 Twin (org.eclipse.collections.api.tuple.Twin)2 ObjectIntProcedures (org.eclipse.collections.impl.block.factory.ObjectIntProcedures)2 Predicates2 (org.eclipse.collections.impl.block.factory.Predicates2)2 PrimitiveFunctions (org.eclipse.collections.impl.block.factory.PrimitiveFunctions)2 AddFunction (org.eclipse.collections.impl.block.function.AddFunction)2 MaxSizeFunction (org.eclipse.collections.impl.block.function.MaxSizeFunction)2 MinSizeFunction (org.eclipse.collections.impl.block.function.MinSizeFunction)2 CollectionAddProcedure (org.eclipse.collections.impl.block.procedure.CollectionAddProcedure)2 Iterables.iList (org.eclipse.collections.impl.factory.Iterables.iList)2 Iterables.mList (org.eclipse.collections.impl.factory.Iterables.mList)2