Class DefaultTraversalSideEffects
- java.lang.Object
- 
- org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalSideEffects
 
- 
- All Implemented Interfaces:
- Serializable,- AutoCloseable,- Cloneable,- TraversalSideEffects
 
 public class DefaultTraversalSideEffects extends Object implements TraversalSideEffects - Author:
- Marko A. Rodriguez (http://markorodriguez.com)
- See Also:
- Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffectsTraversalSideEffects.Exceptions
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected Set<String>keysprotected Map<String,Object>objectMapprotected Map<String,BinaryOperator>reducerMapprotected SuppliersackInitialValueprotected BinaryOperatorsackMergeOperatorprotected UnaryOperatorsackSplitOperatorprotected Map<String,Supplier>supplierMap
 - 
Constructor SummaryConstructors Constructor Description DefaultTraversalSideEffects()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(String key, Object value)Add a value to the global side-effect value.DefaultTraversalSideEffectsclone()Cloning is used to duplicate the sideEffects typically in distributed execution environments.booleanexists(String key)Return true if the key is a registered side-effect.<V> Vget(String key)Get the sideEffect associated with the provided key.<V> BinaryOperator<V>getReducer(String key)Get the reducer associated with the side-effect key.<S> Supplier<S>getSackInitialValue()If sacks are enabled, get the initial value of theTraversersack.<S> BinaryOperator<S>getSackMerger()If sacks are enabled and a merge function has been specified, then get it (else getnull).<S> UnaryOperator<S>getSackSplitter()If sacks are enabled and a split operator has been specified, then get it (else getnull).<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 registeredSupplierkeys.voidmergeInto(TraversalSideEffects sideEffects)Add the currentTraversalSideEffectsvalues, suppliers, and reducers to the providedTraversalSideEffects.<V> voidregister(String key, Supplier<V> initialValue, BinaryOperator<V> reducer)<V> voidregisterIfAbsent(String key, Supplier<V> initialValue, BinaryOperator<V> reducer)voidremove(String key)Remove both the value and registeredSupplierassociated with provided key.voidset(String key, Object value)Set the specified key to the specified value.<S> voidsetSack(Supplier<S> initialValue, UnaryOperator<S> splitOperator, BinaryOperator<S> mergeOperator)Set the initial value of eachTraverser"sack" along with the operators for splitting and merging sacks.StringtoString()- 
Methods inherited from class java.lang.Objectequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffectsclose, forEach, isEmpty
 
- 
 
- 
- 
- 
Field Detail- 
reducerMapprotected Map<String,BinaryOperator> reducerMap 
 - 
sackSplitOperatorprotected UnaryOperator sackSplitOperator 
 - 
sackMergeOperatorprotected BinaryOperator sackMergeOperator 
 - 
sackInitialValueprotected Supplier sackInitialValue 
 
- 
 - 
Method Detail- 
existspublic boolean exists(String key) Return true if the key is a registered side-effect.- Specified by:
- existsin interface- TraversalSideEffects
- Parameters:
- key- the key to check for existence
- Returns:
- whether the key exists or not
 
 - 
getpublic <V> V get(String key) throws IllegalArgumentException Get the sideEffect associated with the provided key. If the sideEffect contains an object for the key, return it. Else if the sideEffect has a registeredSupplierfor that key, generate the object, store the object in the sideEffects, and return it.- Specified by:
- getin interface- TraversalSideEffects
- Type Parameters:
- V- the type of the value to retrieve
- Parameters:
- key- the key to get the value for
- Returns:
- the value associated with key
- Throws:
- IllegalArgumentException- if the key does not reference an object or a registered supplier.
 
 - 
setpublic void set(String key, Object value) throws IllegalArgumentException Set the specified key to the specified value. This method should not be used in a distributed environment. Instead, useTraversalSideEffects.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.- Specified by:
- setin interface- TraversalSideEffects
- Parameters:
- key- the key they key of the side-effect
- value- the value the new value for the side-effect
- Throws:
- IllegalArgumentException- if the key does not reference a registered side-effect.
 
 - 
addpublic void add(String key, Object value) throws IllegalArgumentException Add a value to the global side-effect value. This should be used by steps to ensure that side-effects are merged properly in a distributed environment.TraversalSideEffects.set(String, Object)should only be used in single-threaded systems or by a master traversal in a distributed environment.- Specified by:
- addin interface- TraversalSideEffects
- Parameters:
- key- the key of the side-effect.
- value- the partital value (to be merged) of the side-effect.
- Throws:
- IllegalArgumentException- if no side-effect exists for the provided key
 
 - 
registerpublic <V> void register(String key, Supplier<V> initialValue, BinaryOperator<V> reducer) Register a side-effect with theTraversalSideEffectsproviding aSupplierand aBinaryOperator. If a null value is provided for the supplier or reducer, then it no supplier or reducer is registered.- Specified by:
- registerin interface- TraversalSideEffects
- Type Parameters:
- V- the type of the side-effect value
- Parameters:
- key- the key of the side-effect value
- initialValue- the initial value supplier
- reducer- the reducer to use for merging a distributed side-effect value into a single value
 
 - 
registerIfAbsentpublic <V> void registerIfAbsent(String key, Supplier<V> initialValue, BinaryOperator<V> reducer) Register a side-effect with theTraversalSideEffectsproviding aSupplierand aBinaryOperator. 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.- Specified by:
- registerIfAbsentin interface- TraversalSideEffects
- Type Parameters:
- V- the type of the side-effect value
- Parameters:
- key- the key of the side-effect value
- initialValue- the initial value supplier
- reducer- the reducer to use for merging a distributed side-effect value into a single value
 
 - 
getReducerpublic <V> BinaryOperator<V> getReducer(String key) throws IllegalArgumentException Get the reducer associated with the side-effect key. If no reducer was registered, thenOperator.assignis provided.- Specified by:
- getReducerin interface- TraversalSideEffects
- Type Parameters:
- V- the type of the side-effect value
- Parameters:
- key- the key of the side-effect
- Returns:
- the registered reducer
- Throws:
- IllegalArgumentException- if no side-effect exists for the provided key
 
 - 
getSupplierpublic <V> Supplier<V> getSupplier(String key) throws IllegalArgumentException Get the supplier associated with the side-effect key. If no supplier was registered, thenConstantSupplieris provided.- Specified by:
- getSupplierin interface- TraversalSideEffects
- Type Parameters:
- V- the type of the side-effect value
- Parameters:
- key- the key of the side-effect
- Returns:
- the registered supplier
- Throws:
- IllegalArgumentException- if no side-effect exists for the provided key
 
 - 
setSackpublic <S> void setSack(Supplier<S> initialValue, UnaryOperator<S> splitOperator, BinaryOperator<S> mergeOperator) Set the initial value of eachTraverser"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.- Specified by:
- setSackin interface- TraversalSideEffects
- Type Parameters:
- S- the sack type
- Parameters:
- initialValue- the initial value supplier of the traverser sack
- splitOperator- the split operator for splitting traverser sacks
- mergeOperator- the merge operator for merging traverser sacks
 
 - 
getSackInitialValuepublic <S> Supplier<S> getSackInitialValue() If sacks are enabled, get the initial value of theTraversersack. If its not enabled, thennullis returned.- Specified by:
- getSackInitialValuein interface- TraversalSideEffects
- Type Parameters:
- S- the sack type
- Returns:
- the supplier of the initial value of the traverser sack
 
 - 
getSackSplitterpublic <S> UnaryOperator<S> getSackSplitter() If sacks are enabled and a split operator has been specified, then get it (else getnull). The split operator is used to split a sack when a bifurcation in aTraverserhappens.- Specified by:
- getSackSplitterin interface- TraversalSideEffects
- Type Parameters:
- S- the sack type
- Returns:
- the operator for splitting a traverser sack
 
 - 
getSackMergerpublic <S> BinaryOperator<S> getSackMerger() If sacks are enabled and a merge function has been specified, then get it (else getnull). The merge function is used to merge two sacks when twoTraversers converge.- Specified by:
- getSackMergerin interface- TraversalSideEffects
- Type Parameters:
- S- the sack type
- Returns:
- the operator for merging two traverser sacks
 
 - 
removepublic void remove(String key) Remove both the value and registeredSupplierassociated with provided key.- Specified by:
- removein interface- TraversalSideEffects
- Parameters:
- key- the key of the value and registered supplier to remove
 
 - 
keyspublic Set<String> keys() The keys of the sideEffect which includes registeredSupplierkeys. In essence, that which is possible toTraversalSideEffects.get(String).- Specified by:
- keysin interface- TraversalSideEffects
- Returns:
- the keys of the sideEffect
 
 - 
mergeIntopublic void mergeInto(TraversalSideEffects sideEffects) Add the currentTraversalSideEffectsvalues, suppliers, and reducers to the providedTraversalSideEffects. The implementation should (under the hood), useTraversalSideEffects.registerIfAbsent(String, Supplier, BinaryOperator)so that if the argumentTraversalSideEffectsalready has a registered supplier or binary operator, then don't overwrite it.- Specified by:
- mergeIntoin interface- TraversalSideEffects
- Parameters:
- sideEffects- the sideEffects to add this traversal's sideEffect data to.
 
 - 
clonepublic DefaultTraversalSideEffects clone() Cloning is used to duplicate the sideEffects typically in distributed execution environments.- Specified by:
- clonein interface- TraversalSideEffects
- Overrides:
- clonein class- Object
- Returns:
- The cloned sideEffects
 
 
- 
 
-