Class ExpressionTrees
java.lang.Object
org.cyclops.integrateddynamics.core.evaluate.expression.tree.ExpressionTrees
Helpers for expression trees: serialization, path navigation and queries.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum tree depth accepted when deserializing, to protect against malicious or corrupt data.static final intMaximum length of a parameter name. -
Method Summary
Modifier and TypeMethodDescriptionstatic int[]append(int[] path, int index) static ExpressionNode.OperatorasRoot(ExpressionNode node) The root of an expression is an operator, so a value, parameter, reference or empty slot as a whole expression is the input of the identity operator, which is not written in its text.static booleancontainsParam(ExpressionNode node, int index) static intcountEmpty(ExpressionNode node) static intcountNodes(ExpressionNode node) static intcountOperators(ExpressionNode node) static intdepth(ExpressionNode node) static Expressiondeserialize(net.minecraft.world.level.storage.ValueInput input) static Expressiondeserialize(ValueDeseralizationContext context, net.minecraft.nbt.CompoundTag tag) static ExpressionNodedeserializeNode(net.minecraft.world.level.storage.ValueInput input, int depth, int parameterCount) static <T extends IValue>
TdeserializeValue(ValueDeseralizationContext context, IValueType<T> valueType, net.minecraft.nbt.CompoundTag tag) static ExpressionfromPlainOperator(IOperator operator, int[] variableIds) static ExpressionNodeget(ExpressionNode root, int[] path) static int[]getPlainOperatorVariableIds(Expression expression) static it.unimi.dsi.fastutil.ints.IntListgetRefIds(ExpressionNode node) static ExpressionNodegetRootValue(ExpressionNode root) static booleanisOperatorPath(ExpressionNode root, int[] path) static booleanisPlainOperator(Expression expression) Check if the given expression can be stored as a plain operator variable, which is the case for a single operator without parameters and only variable references as inputs.static int[]parent(int[] path) static ExpressionNoderemoveParam(ExpressionNode node, int removedIndex) static ExpressionNodereplace(ExpressionNode root, int[] path, ExpressionNode replacement) static voidserialize(net.minecraft.world.level.storage.ValueOutput output, Expression expression) static net.minecraft.nbt.CompoundTagserialize(ValueDeseralizationContext context, Expression expression) static voidserializeNode(net.minecraft.world.level.storage.ValueOutput output, ExpressionNode node) static net.minecraft.nbt.CompoundTagserializeValue(ValueDeseralizationContext context, IValue value)
-
Field Details
-
MAX_DEPTH
public static final int MAX_DEPTHMaximum tree depth accepted when deserializing, to protect against malicious or corrupt data.- See Also:
-
MAX_PARAMETER_NAME_LENGTH
public static final int MAX_PARAMETER_NAME_LENGTHMaximum length of a parameter name.- See Also:
-
-
Method Details
-
serialize
public static net.minecraft.nbt.CompoundTag serialize(ValueDeseralizationContext context, Expression expression) -
serialize
public static void serialize(net.minecraft.world.level.storage.ValueOutput output, Expression expression) -
deserialize
public static Expression deserialize(ValueDeseralizationContext context, net.minecraft.nbt.CompoundTag tag) throws EvaluationException - Throws:
EvaluationException
-
deserialize
public static Expression deserialize(net.minecraft.world.level.storage.ValueInput input) throws EvaluationException - Throws:
EvaluationException
-
serializeNode
public static void serializeNode(net.minecraft.world.level.storage.ValueOutput output, ExpressionNode node) -
deserializeNode
public static ExpressionNode deserializeNode(net.minecraft.world.level.storage.ValueInput input, int depth, int parameterCount) throws EvaluationException - Throws:
EvaluationException
-
serializeValue
public static net.minecraft.nbt.CompoundTag serializeValue(ValueDeseralizationContext context, IValue value) - Parameters:
context- For serializing the value.value- A value.- Returns:
- The value as its type writes it.
-
deserializeValue
public static <T extends IValue> T deserializeValue(ValueDeseralizationContext context, IValueType<T> valueType, net.minecraft.nbt.CompoundTag tag) - Parameters:
context- For deserializing the value.valueType- The type of the value.tag- The value as its type writes it.- Returns:
- The value.
- Throws:
RuntimeException- If the tag is not a value of the type.
-
asRoot
The root of an expression is an operator, so a value, parameter, reference or empty slot as a whole expression is the input of the identity operator, which is not written in its text.- Parameters:
node- A whole expression.- Returns:
- The root for it.
-
getRootValue
- Parameters:
root- The root of an expression.- Returns:
- The input of the identity operator if the root was made by
asRoot(ExpressionNode)for a node that is not an operator, which is the whole expression in its text, otherwise null.
-
get
- Parameters:
root- A root node.path- A path of child indexes.- Returns:
- The node at the given path, or null if the path is invalid.
-
replace
- Parameters:
root- A root node.path- A valid path of child indexes.replacement- The node to put at the given path.- Returns:
- A new root node.
-
isOperatorPath
- Parameters:
root- A root node.path- A path.- Returns:
- If the path points to an operator node.
-
append
public static int[] append(int[] path, int index) -
parent
public static int[] parent(int[] path) -
countEmpty
-
depth
- Parameters:
node- A node.- Returns:
- The depth, where a leaf has depth 0.
-
countNodes
-
countOperators
- Parameters:
node- A node.- Returns:
- The number of operator nodes in it, not counting operators used as values.
-
getRefIds
- Parameters:
node- A node.- Returns:
- All referenced variable ids, in order of first occurrence.
-
containsParam
-
removeParam
- Parameters:
node- A node.removedIndex- A removed parameter index.- Returns:
- The node where params referring to the removed index become empty, and higher indexes shift down.
-
isPlainOperator
Check if the given expression can be stored as a plain operator variable, which is the case for a single operator without parameters and only variable references as inputs.- Parameters:
expression- An expression.- Returns:
- If it is equivalent to a plain operator variable.
-
getPlainOperatorVariableIds
- Parameters:
expression- A plain operator expression, seeisPlainOperator(Expression).- Returns:
- The referenced variable ids.
-
fromPlainOperator
- Parameters:
operator- An operator.variableIds- Variable ids.- Returns:
- An expression for a plain operator variable.
-