org.omnaest.utils.operation.foreach
Class ForEach<E,V>

java.lang.Object
  extended by org.omnaest.utils.operation.foreach.ForEach<E,V>
Type Parameters:
E - elements
V - result values
All Implemented Interfaces:
Operation<ForEach.Result<V>,Operation<V,E>>

public class ForEach<E,V>
extends Object
implements Operation<ForEach.Result<V>,Operation<V,E>>

A ForEach will iterate over a given Iterable instance and executes a given List of Operations.

Author:
Omnaest
See Also:
Operation, Iterable

Nested Class Summary
static class ForEach.Result<V>
          ForEach.Result of a ForEach Operation which is basically an unmodifiable List of all returned instances from the Operations.
 
Constructor Summary
ForEach(Iterable<E>... iterables)
           
ForEach(Iterable<E> iterable)
           
 
Method Summary
 ForEach<E,V> doExecuteInParallelUsing(ExecutorService executorService)
           
 ForEach<E,V> doIterateInParallelUsing(ExecutorService executorService, int numberOfThreads)
          If this option is used, the given Iterables have to have threadsafe Iterable.iterator() instances, since even the Iterators will be called from parallel running threads.
<O> V
execute(CollectionUtils.CollectionConverter<O,V> collectionConverter, Operation<O,E>... operations)
          Executes the given Operation and uses the given CollectionUtils.CollectionConverter to produce a single result value
 ForEach.Result<V> execute(Operation<V,E>... operations)
          Executes the ForEach Operation
 ForEach.Result<V> execute(Operation<V,E> operation)
          Executes the ForEach Operation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ForEach

public ForEach(Iterable<E>... iterables)
Parameters:
iterables -
See Also:
ForEach

ForEach

public ForEach(Iterable<E> iterable)
Parameters:
iterable -
See Also:
ForEach
Method Detail

execute

public <O> V execute(CollectionUtils.CollectionConverter<O,V> collectionConverter,
                     Operation<O,E>... operations)
Executes the given Operation and uses the given CollectionUtils.CollectionConverter to produce a single result value

Parameters:
collectionConverter -
operations -
Returns:

execute

public ForEach.Result<V> execute(Operation<V,E> operation)
Executes the ForEach Operation

Specified by:
execute in interface Operation<ForEach.Result<V>,Operation<V,E>>
Parameters:
operation -
Returns:

execute

public ForEach.Result<V> execute(Operation<V,E>... operations)
Executes the ForEach Operation

Parameters:
operations -
Returns:

doExecuteInParallelUsing

public ForEach<E,V> doExecuteInParallelUsing(ExecutorService executorService)
Parameters:
executorService - the executorService to set
Returns:
this

doIterateInParallelUsing

public ForEach<E,V> doIterateInParallelUsing(ExecutorService executorService,
                                             int numberOfThreads)
If this option is used, the given Iterables have to have threadsafe Iterable.iterator() instances, since even the Iterators will be called from parallel running threads.

Be aware that several default implementations like ArrayList do not provide thread safe iterators, so do only use this option, if you have special Iterators in place.

Parameters:
executorService - the executorService to set
numberOfThreads -
Returns:
this


Copyright © 2013. All Rights Reserved.