Class Define

java.lang.Object
org.moeaframework.util.tree.Node
org.moeaframework.util.tree.Define

public class Define extends Node
The node for defining a callable, named function. Once a named function is defined, it can be invoked using Call. The behavior (body) of this function can be mutated. For immutable functions, see Lambda.
See Also:
  • Constructor Details

    • Define

      public Define(String functionName, Class<?> returnType)
      Constructs a new node for defining a function that takes no arguments.
      Parameters:
      functionName - the name of the function
      returnType - the return type of the function
    • Define

      public Define(String functionName, Class<?> returnType, String variableName, Class<?> variableType)
      Constructs a new node for defining a function that takes one argument.
      Parameters:
      functionName - the name of the function
      returnType - the return type of the function
      variableName - the name of the argument
      variableType - the type of the argument
    • Define

      public Define(String functionName, Class<?> returnType, String name1, Class<?> type1, String name2, Class<?> type2)
      Constructs a new node for defining a function that takes two arguments.
      Parameters:
      functionName - the name of the function
      returnType - the return type of the function
      name1 - the name of the first argument
      type1 - the type of the first argument
      name2 - the name of the second argument
      type2 - the type of the second argument
    • Define

      public Define(String functionName, Class<?> returnType, String[] variableNames, Class<?>[] variableTypes)
      Constructs a new node for defining a function that takes a user-defined number of arguments.
      Parameters:
      functionName - the name of the function
      returnType - the return type of the function
      variableNames - the names of the arguments to the function
      variableTypes - the types of the arguments to the function
  • Method Details

    • getFunctionName

      public String getFunctionName()
      Returns the name of this function.
      Returns:
      the name of this function
    • getVariableNames

      public String[] getVariableNames()
      Returns the names of the arguments to this function.
      Returns:
      the names of the arguments to this function
    • getVariableTypes

      public Class<?>[] getVariableTypes()
      Returns the types of the arguments to this function.
      Returns:
      the types of the arguments to this function
    • copyNode

      public Node copyNode()
      Description copied from class: Node
      Returns a copy of this node, but without any children or parents assigned.
      Specified by:
      copyNode in class Node
      Returns:
      a copy of this node, but without any children or parents assigned
    • evaluate

      public Void evaluate(Environment environment)
      Description copied from class: Node
      Evaluates this node in the context of the specified environment.
      Specified by:
      evaluate in class Node
      Parameters:
      environment - the execution environment
      Returns:
      the result of evaluating this node
    • toString

      public String toString()
      Overrides:
      toString in class Node