Class Value

java.lang.Object
org.praxislive.core.Value
Direct Known Subclasses:
ComponentAddress, ComponentType, ControlAddress, PArray, PArray.ArrayBasedValue, PBoolean, PBytes, PError, PMap, PMap.MapBasedValue, PNumber, PortAddress, PReference, PResource, PString

public abstract class Value extends Object
Abstract base class of all types used in messaging inside PraxisCORE. All Value sub-types are guaranteed to be immutable.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Value.Type<T extends Value>
    The type of a Value.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract boolean
    Values must override the default equals method.
    boolean
    Indicates whether some other Value is equivalent to this one.
    abstract int
    Values must override the default hashcode method.
    Use this method to return an ArgumentInfo argument that can be used to refer to ANY Value subclass.
    boolean
    Check whether this Value is an empty value and has a zero length string representation.
    static Value
    Convert the provided Object into a Value.
    abstract String
    Values must override the default method to return a string representation that is immutable.
    Access the Value.Type of this value.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Value

      public Value()
  • Method Details

    • toString

      public abstract String toString()
      Values must override the default method to return a string representation that is immutable.
      Overrides:
      toString in class Object
      Returns:
      String representation
    • hashCode

      public abstract int hashCode()
      Values must override the default hashcode method.
      Overrides:
      hashCode in class Object
      Returns:
      int hashcode
    • equals

      public abstract boolean equals(Object obj)
      Values must override the default equals method. This method should only return true if the supplied Object is of the same type as the implementing Value. Values of an unknown type should be coerced before calling this method. This method does not have to guarantee that this.equals(that) == this.toString().equals(that.toString())
      Overrides:
      equals in class Object
      Parameters:
      obj -
      Returns:
      boolean
    • isEmpty

      public boolean isEmpty()
      Check whether this Value is an empty value and has a zero length string representation. Subclasses may wish to override this for efficiency if the String representation is lazily created.
      Returns:
      boolean true if empty
    • equivalent

      public boolean equivalent(Value value)
      Indicates whether some other Value is equivalent to this one. Unlike equals(java.lang.Object) this method is not symmetric - a value of a different type might be equivalent to this without the other type considering the reverse to be true.

      The default implementation uses identity or String equality.

      Parameters:
      value - value to test for equivalence
      Returns:
      true if value is equivalent to this
    • type

      public Value.Type<?> type()
      Access the Value.Type of this value.
      Returns:
      type
    • info

      public static ArgumentInfo info()
      Use this method to return an ArgumentInfo argument that can be used to refer to ANY Value subclass. Usually, you will want to get an ArgumentInfo object directly from a specific Value subclass.
      Returns:
      ArgumentInfo info
    • ofObject

      public static Value ofObject(Object obj)
      Convert the provided Object into a Value. This is a lightweight conversion, primarily to map Java literals to the right Value type, rather than a general purpose mapping API.

      Any instance of a Value subclass is returned as is. Booleans are converted to PBoolean. Numbers are converted to PNumber. null is converted to PString.EMPTY. All other types are converted to a PString of their String representation.

      Parameters:
      obj - object to convert
      Returns:
      value