public class DefaultTraversalSideEffects extends Object implements TraversalSideEffects
TraversalSideEffects.Exceptions| Modifier and Type | Field and Description |
|---|---|
protected Set<String> |
keys |
protected Map<String,Object> |
objectMap |
protected Map<String,BinaryOperator> |
reducerMap |
protected Supplier |
sackInitialValue |
protected BinaryOperator |
sackMergeOperator |
protected UnaryOperator |
sackSplitOperator |
protected Map<String,Supplier> |
supplierMap |
| Constructor and Description |
|---|
DefaultTraversalSideEffects() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(String key,
Object value)
Add a value to the global side-effect value.
|
DefaultTraversalSideEffects |
clone()
Cloning is used to duplicate the sideEffects typically in distributed execution environments.
|
boolean |
exists(String key)
Return true if the key is a registered side-effect.
|
<V> V |
get(String key)
Get the sideEffect associated with the provided key.
|
<V> V |
getOrCreate(String key,
Supplier<V> orCreate)
Deprecated.
|
<V> BinaryOperator<V> |
getReducer(String key)
Get the reducer associated with the side-effect key.
|
<V> Optional<Supplier<V>> |
getRegisteredSupplier(String key)
Deprecated.
|
<S> Supplier<S> |
getSackInitialValue()
If sacks are enabled, get the initial value of the
Traverser sack. |
<S> BinaryOperator<S> |
getSackMerger()
If sacks are enabled and a merge function has been specified, then get it (else get
null). |
<S> UnaryOperator<S> |
getSackSplitter()
If sacks are enabled and a split operator has been specified, then get it (else get
null). |
<V> Supplier<V> |
getSupplier(String key)
Get the supplier associated with the side-effect key.
|
Set<String> |
keys()
The keys of the sideEffect which includes registered
Supplier keys. |
void |
mergeInto(TraversalSideEffects sideEffects)
Add the current
TraversalSideEffects values, suppliers, and reducers to the provided TraversalSideEffects. |
<V> void |
register(String key,
Supplier<V> initialValue,
BinaryOperator<V> reducer)
|
<V> void |
registerIfAbsent(String key,
Supplier<V> initialValue,
BinaryOperator<V> reducer)
|
void |
registerSupplier(String key,
Supplier supplier)
Deprecated.
|
void |
registerSupplierIfAbsent(String key,
Supplier supplier)
Deprecated.
|
void |
remove(String key)
Remove both the value and registered
Supplier associated with provided key. |
void |
set(String key,
Object value)
Set the specified key to the specified value.
|
<S> void |
setSack(Supplier<S> initialValue,
UnaryOperator<S> splitOperator,
BinaryOperator<S> mergeOperator)
Set the initial value of each
Traverser "sack" along with the operators for splitting and merging sacks. |
String |
toString() |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitclose, forEach, isEmptyprotected Map<String,BinaryOperator> reducerMap
protected UnaryOperator sackSplitOperator
protected BinaryOperator sackMergeOperator
protected Supplier sackInitialValue
public boolean exists(String key)
exists in interface TraversalSideEffectskey - the key to check for existencepublic <V> V get(String key) throws IllegalArgumentException
Supplier for that key, generate the object, store the object in the sideEffects, and return it.get in interface TraversalSideEffectsV - the type of the value to retrievekey - the key to get the value forIllegalArgumentException - if the key does not reference an object or a registered supplier.public void set(String key, Object value) throws IllegalArgumentException
TraversalSideEffects.add(String, Object).
This method is only safe when there is only one representation of the side-effect and thus, not distributed across threads or machines.set in interface TraversalSideEffectskey - the key they key of the side-effectvalue - the value the new value for the side-effectIllegalArgumentException - if the key does not reference a registered side-effect.public void add(String key, Object value) throws IllegalArgumentException
TraversalSideEffects.set(String, Object) should only be used in single-threaded systems or by a master traversal in a distributed environment.add in interface TraversalSideEffectskey - the key of the side-effect.value - the partital value (to be merged) of the side-effect.IllegalArgumentException - if no side-effect exists for the provided keypublic <V> void register(String key, Supplier<V> initialValue, BinaryOperator<V> reducer)
TraversalSideEffects providing a Supplier and a BinaryOperator.
If a null value is provided for the supplier or reducer, then it no supplier or reducer is registered.register in interface TraversalSideEffectsV - the type of the side-effect valuekey - the key of the side-effect valueinitialValue - the initial value supplierreducer - the reducer to use for merging a distributed side-effect value into a single valuepublic <V> void registerIfAbsent(String key, Supplier<V> initialValue, BinaryOperator<V> reducer)
TraversalSideEffects providing a Supplier and a BinaryOperator.
The registration will only overwrite a supplier or reducer if no supplier or reducer existed prior.
If a null value is provided for the supplier or reducer, then it no supplier or reducer is registered.registerIfAbsent in interface TraversalSideEffectsV - the type of the side-effect valuekey - the key of the side-effect valueinitialValue - the initial value supplierreducer - the reducer to use for merging a distributed side-effect value into a single valuepublic <V> BinaryOperator<V> getReducer(String key) throws IllegalArgumentException
Operator.assign is provided.getReducer in interface TraversalSideEffectsV - the type of the side-effect valuekey - the key of the side-effectIllegalArgumentException - if no side-effect exists for the provided keypublic <V> Supplier<V> getSupplier(String key) throws IllegalArgumentException
ConstantSupplier is provided.getSupplier in interface TraversalSideEffectsV - the type of the side-effect valuekey - the key of the side-effectIllegalArgumentException - if no side-effect exists for the provided keypublic <S> void setSack(Supplier<S> initialValue, UnaryOperator<S> splitOperator, BinaryOperator<S> mergeOperator)
Traverser "sack" along with the operators for splitting and merging sacks.
If no split operator is provided, then a direct memory copy is assumed (this is typically good for primitive types and strings).
If no merge operator is provided, then traversers with sacks will not be merged.setSack in interface TraversalSideEffectsS - the sack typeinitialValue - the initial value supplier of the traverser sacksplitOperator - the split operator for splitting traverser sacksmergeOperator - the merge operator for merging traverser sackspublic <S> Supplier<S> getSackInitialValue()
Traverser sack.
If its not enabled, then null is returned.getSackInitialValue in interface TraversalSideEffectsS - the sack typepublic <S> UnaryOperator<S> getSackSplitter()
null).
The split operator is used to split a sack when a bifurcation in a Traverser happens.getSackSplitter in interface TraversalSideEffectsS - the sack typepublic <S> BinaryOperator<S> getSackMerger()
null).
The merge function is used to merge two sacks when two Traversers converge.getSackMerger in interface TraversalSideEffectsS - the sack typepublic void remove(String key)
Supplier associated with provided key.remove in interface TraversalSideEffectskey - the key of the value and registered supplier to removepublic Set<String> keys()
Supplier keys.
In essence, that which is possible to get().keys in interface TraversalSideEffectspublic void mergeInto(TraversalSideEffects sideEffects)
TraversalSideEffects values, suppliers, and reducers to the provided TraversalSideEffects.
The implementation should (under the hood), use TraversalSideEffects.registerIfAbsent(String, Supplier, BinaryOperator) so that
if the argument TraversalSideEffects already has a registered supplier or binary operator, then don't overwrite it.mergeInto in interface TraversalSideEffectssideEffects - the sideEffects to add this traversal's sideEffect data to.public DefaultTraversalSideEffects clone()
clone in interface TraversalSideEffectsclone in class Object@Deprecated public void registerSupplier(String key, Supplier supplier)
Supplier with the provided key.
When sideEffects get() are called, if no object exists and there exists a registered supplier for the key, the object is generated.
Registered suppliers are used for the lazy generation of sideEffect data.registerSupplier in interface TraversalSideEffectskey - the key to register the supplier withsupplier - the supplier that will generate an object when get() is called if it hasn't already been created@Deprecated public void registerSupplierIfAbsent(String key, Supplier supplier)
Supplier if it has not already been registered.registerSupplierIfAbsent in interface TraversalSideEffectskey - the key of the supplier to registersupplier - the supplier to register if the key has not already been registered@Deprecated public <V> Optional<Supplier<V>> getRegisteredSupplier(String key)
Supplier associated with the specified key.getRegisteredSupplier in interface TraversalSideEffectsV - The object type of the supplierkey - the key associated with the supplier@Deprecated public <V> V getOrCreate(String key, Supplier<V> orCreate)
Supplier.getOrCreate in interface TraversalSideEffectsV - the return type of the objectkey - the key of the object to getorCreate - if the object doesn't exist as an object or suppliable object, then generate it with the specified supplierCopyright © 2013–2016 Apache Software Foundation. All rights reserved.