- java.lang.Object
-
- org.praxislive.core.Value
-
- Direct Known Subclasses:
ArgumentInfo
,ComponentAddress
,ComponentInfo
,ComponentType
,ControlAddress
,ControlInfo
,PArray
,PBoolean
,PBytes
,PError
,PMap
,PNumber
,PortAddress
,PortInfo
,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 Value()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
equals(Object obj)
Values must override the default equals method.boolean
equivalent(Value value)
Indicates whether some other Value is equivalent to this one.abstract int
hashCode()
Values must override the default hashcode method.static ArgumentInfo
info()
Use this method to return an ArgumentInfo argument that can be used to refer to ANY Value subclass.boolean
isEmpty()
Check whether this Value is an empty value and has a zero length string representation.static Value
ofObject(Object obj)
Convert the provided Object into a Value.abstract String
toString()
Values must override the default method to return a string representation that is immutable.Value.Type<?>
type()
Access theValue.Type
of this value.
-
-
-
Method Detail
-
toString
public abstract String toString()
Values must override the default method to return a string representation that is immutable.
-
hashCode
public abstract int hashCode()
Values must override the default hashcode method.
-
equals
public abstract boolean equals(Object obj)
Values must override the default equals method. This method should only returntrue
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 thatthis.equals(that) == this.toString().equals(that.toString())
-
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. Unlikeequals(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 theValue.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 toPString.EMPTY
. All other types are converted to a PString of their String representation.- Parameters:
obj
- object to convert- Returns:
- value
-
-