java.lang.Object
com.wyu4.snowberryjam.compiler.data.values.ValueHolder
Direct Known Subclasses:
InputHolder, InteractiveValueHolder, PublicFolderHolder, RandomHolder, TimeHolder, VariableReference

public class ValueHolder extends Object
A pointer to a stored value.
  • Field Details

  • Constructor Details

    • ValueHolder

      public ValueHolder()
      Creates a pointer to null. Flags as empty.
      See Also:
    • ValueHolder

      public ValueHolder(Object value)
      Creates a new pointer to a value
      Parameters:
      value - The value to point towards. Type should be compatible with the compiler.
  • Method Details

    • isPrimitive

      private static boolean isPrimitive(com.fasterxml.jackson.databind.JsonNode node)
      Check if a JsonNode is primitive, in the context of Snowberry Jam
      Parameters:
      node - Node
      Returns:
      true if the value is a String, Boolean, Double, or Array. Returns false otherwise.
      See Also:
      • JsonNode
    • fromNode

      public static ValueHolder fromNode(com.fasterxml.jackson.databind.JsonNode node)
      Manufacture a ValueHolder object from a JsonNode object. Uses the ID node to identify which type of ValueHolder should be created
      Parameters:
      node - Node containing Snowberry Jam Source code
      Returns:
      A ValueHolder object. Might be casted from child classes.
      See Also:
    • checkValueIsConditional

      public static ValueHolder checkValueIsConditional(ValueHolder condition) throws IllegalArgumentException
      Check if a ValueHolder object is conditional
      Parameters:
      condition - ValueHolder object to check
      Returns:
      The condition parameter, untouched.
      Throws:
      IllegalArgumentException - if the value holder is not conditional.
    • getValue

      public Object getValue()
      Get the value being pointed to casted as an Object. The contents being returned by this method are mutable.
      Returns:
      The value being pointed to, in its current state.
    • getPointer

      public Object getPointer()
      Get the unparsed pointer. Could be a primitive or non-primitive value.
      Returns:
      The value or the pointer to a value.
    • getArray

      public Object[] getArray()
      Get the stored value as an Object array. If the original value was already an Object array, it wil lremain untouched. Otherwise, it will take the string format of the value and return an array of all the characters (casted to String)
      Returns:
      Object array
      See Also:
    • getString

      public String getString()
      Get the stored value as a String
      Returns:
      The value casted to a String. If the value is an array, this method will take care of converting it into a string.
      See Also:
    • getType

      public Class<?> getType()
      Get the type being pointed to
      Returns:
      The class type
      See Also:
    • isType

      public boolean isType(Class<?> type)
      Check if the type being pointed to is the same as parameter type.
      Parameters:
      type - The other type
      Returns:
      true if tne value shares the same class. false if not.
    • notEmpty

      public boolean notEmpty()
      Check if this holder doesn't point to null
      Returns:
      true if this points to a value, false if it points to null
    • getSize

      public Double getSize()
      Get the value as a number. If the value is numerical, it returns the value as a Double. If it's a String or an Array, it will return its length. If it's a Boolean, true will return 1, and false will return 0.
      Returns:
      Double representation of the value
    • getId

      public SourceId getId()
      Get the ID of the value holder
      Returns:
      Corresponding SourceId
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • superEquals

      public boolean superEquals(Object obj)
    • toString

      public String toString()
      Overrides:
      toString in class Object