java.lang.Object
com.marginallyclever.nodegraphcore.NodeVariable<T>

public class NodeVariable<T>
extends java.lang.Object
Describes an input or output connection with for a Node and stores the value at that connection.
Since:
2022-02-01
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int DEFAULT_HEIGHT
    Dimensions used for bounds calculations and intersection tests.
    static int DEFAULT_WIDTH
    Dimensions used for bounds calculations and intersection tests.
    protected boolean hasInput
    does this variable have an input?
    protected boolean hasOutput
    does this variable have an output?
    protected boolean isDirty
    is this variable dirty?
    protected java.lang.String name
    The name of this variable.
    protected java.awt.Rectangle rectangle
    bounding rectangle of this variable.
    protected java.lang.Class<T> type
    The type of the value stored in this variable.
    protected T value
    The value within this variable
  • Method Summary

    Modifier and Type Method Description
    NodeVariable<T> createInverse()
    Creates a copy of this NodeVariable, while flipping hasInput and hasOutput
    boolean getHasInput()
    Returns true if this variable has an input
    boolean getHasOutput()
    Returns true if this variable has an output
    java.awt.Point getInPosition()
    Returns the center of the input connection point of this variable
    boolean getIsDirty()
    Returns the dirty state.
    java.lang.String getName()
    Returns the name
    java.awt.Point getOutPosition()
    Returns the center of the output connection point of this variable
    java.awt.Rectangle getRectangle()
    Returns the bounding rectangle.
    java.lang.Class<T> getTypeClass()
    Returns the class of this value type.
    java.lang.String getTypeName()
    Returns the simple name of the class of this value type.
    T getValue()
    Returns the value.
    boolean isValidType​(java.lang.Object arg0)
    Returns true if the given item is an instance of this value's type.
    static <T> NodeVariable<T> newInstance​(java.lang.String name, java.lang.Class<T> clazz, T startingValue, boolean hasInput, boolean hasOutput)
    Called to create a new instance of a NodeVariable.
    void setIsDirty​(boolean state)
    Sets the dirty state.
    void setValue​(java.lang.Object arg0)
    Sets the value.
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • DEFAULT_WIDTH

      public static final int DEFAULT_WIDTH
      Dimensions used for bounds calculations and intersection tests.
      See Also:
      Constant Field Values
    • DEFAULT_HEIGHT

      public static final int DEFAULT_HEIGHT
      Dimensions used for bounds calculations and intersection tests.
      See Also:
      Constant Field Values
    • value

      protected T value
      The value within this variable
    • type

      protected final java.lang.Class<T> type
      The type of the value stored in this variable.
    • name

      protected java.lang.String name
      The name of this variable. Change this value in production and serialization will break!
    • hasInput

      protected boolean hasInput
      does this variable have an input?
    • hasOutput

      protected boolean hasOutput
      does this variable have an output?
    • isDirty

      protected boolean isDirty
      is this variable dirty?
    • rectangle

      protected final java.awt.Rectangle rectangle
      bounding rectangle of this variable.
  • Method Details

    • newInstance

      public static <T> NodeVariable<T> newInstance​(java.lang.String name, java.lang.Class<T> clazz, T startingValue, boolean hasInput, boolean hasOutput)
      Called to create a new instance of a NodeVariable.
      Type Parameters:
      T - the class type.
      Parameters:
      name - the variable name
      clazz - the variable type
      startingValue - the starting value
      hasInput - does this variable have an input?
      hasOutput - does this variable have an input?
      Returns:
      the new instance.
    • createInverse

      public NodeVariable<T> createInverse()
      Creates a copy of this NodeVariable, while flipping hasInput and hasOutput
      Returns:
      an inverted copy of this NodeVariable.
    • getRectangle

      public java.awt.Rectangle getRectangle()
      Returns the bounding rectangle.
      Returns:
      the bounding rectangle.
    • getName

      public java.lang.String getName()
      Returns the name
      Returns:
      the name
    • setValue

      public void setValue​(java.lang.Object arg0)
      Sets the value. Casts to this variable's type.
      Parameters:
      arg0 - the new value to set.
    • getTypeClass

      public java.lang.Class<T> getTypeClass()
      Returns the class of this value type.
      Returns:
      the class of this value type.
    • getTypeName

      public java.lang.String getTypeName()
      Returns the simple name of the class of this value type.
      Returns:
      the simple name of the class of this value type.
    • isValidType

      public boolean isValidType​(java.lang.Object arg0)
      Returns true if the given item is an instance of this value's type.
      Parameters:
      arg0 - the given item
      Returns:
      true if the given item is an instance of this value's type.
    • getValue

      public T getValue()
      Returns the value.
      Returns:
      the value.
    • setIsDirty

      public void setIsDirty​(boolean state)
      Sets the dirty state.
      Parameters:
      state - the new dirty state.
    • getIsDirty

      public boolean getIsDirty()
      Returns the dirty state.
      Returns:
      the dirty state.
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • getHasOutput

      public boolean getHasOutput()
      Returns true if this variable has an output
      Returns:
      true if this variable has an output
    • getHasInput

      public boolean getHasInput()
      Returns true if this variable has an input
      Returns:
      true if this variable has an input
    • getInPosition

      public java.awt.Point getInPosition()
      Returns the center of the input connection point of this variable
      Returns:
      the center of the input connection point of this variable
    • getOutPosition

      public java.awt.Point getOutPosition()
      Returns the center of the output connection point of this variable
      Returns:
      the center of the output connection point of this variable