Class AbstractPersistedTree<S,T>
- java.lang.Object
-
- org.protelis.lang.interpreter.impl.AbstractProtelisAST<T>
-
- org.protelis.lang.interpreter.impl.AbstractPersistedTree<S,T>
-
- Type Parameters:
S
- Superscript typeT
- Annotation type
- All Implemented Interfaces:
java.io.Serializable
,ProtelisAST<T>
,WithBytecode
public abstract class AbstractPersistedTree<S,T> extends AbstractProtelisAST<T>
Basic implementation of a persisted tree.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractPersistedTree(Metadata metadata, java.util.List<ProtelisAST<?>> branches)
protected
AbstractPersistedTree(Metadata metadata, ProtelisAST<?>... branches)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected S
loadState(ExecutionContext context, java.util.function.Supplier<S> ifAbsent)
Retrieves the function state from last round, or produces a new state otherwise.protected void
saveState(ExecutionContext context, S obj)
Stores the function state for the next round.abstract java.lang.String
toString()
-
Methods inherited from class org.protelis.lang.interpreter.impl.AbstractProtelisAST
branchesToString, branchesToString, eval, evaluate, forEach, forEachWithIndex, getBranch, getBranches, getBranchesNumber, getMetadata, getName, isNullable, stringFor
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.protelis.lang.interpreter.util.WithBytecode
getBytecode
-
-
-
-
Constructor Detail
-
AbstractPersistedTree
protected AbstractPersistedTree(Metadata metadata, ProtelisAST<?>... branches)
- Parameters:
metadata
- AMetadata
object containing information about the code that generated this AST node.branches
- branches of thisAbstractPersistedTree
-
AbstractPersistedTree
protected AbstractPersistedTree(Metadata metadata, java.util.List<ProtelisAST<?>> branches)
- Parameters:
metadata
- AMetadata
object containing information about the code that generated this AST node.branches
- branches of thisAbstractPersistedTree
-
-
Method Detail
-
loadState
protected final S loadState(ExecutionContext context, java.util.function.Supplier<S> ifAbsent)
Retrieves the function state from last round, or produces a new state otherwise.- Parameters:
context
- theExecutionContext
ifAbsent
- a 0-ary function producing the value if none is stored- Returns:
- the previous state, if present, or the state computed by ifAbsent otherwise
-
saveState
protected final void saveState(ExecutionContext context, S obj)
Stores the function state for the next round.- Parameters:
context
- theExecutionContext
obj
- the state
-
toString
public abstract java.lang.String toString()
- Overrides:
toString
in classAbstractProtelisAST<T>
-
-