Class ValueWrapper

  • All Implemented Interfaces:
    java.io.Serializable

    public final class ValueWrapper
    extends java.lang.Object
    implements java.io.Serializable
    Serializable representation of a value that was used in an assertion.

    This class only stores the value if it implements Serializable. In any case, it stores its runtime type, identity hash code and string representation, i.e. the result of invoking Object.toString().

    The toString() method returns the string representation of the value along with its type and identity hash code.

    Since:
    1.0
    Author:
    Marc Philipp, Sam Brannen
    See Also:
    System.identityHashCode(java.lang.Object), Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static ValueWrapper create​(java.lang.Object value)
      Factory for creating a new ValueWrapper for the supplied value.
      int getIdentityHashCode()
      Returns the value's identity hash code, i.e.
      java.lang.String getStringRepresentation()
      Returns the value's string representation, i.e.
      java.lang.Class<?> getType()
      Returns the value's runtime type in case it wasn't null; otherwise, null.
      java.io.Serializable getValue()
      Returns the value as passed to the constructor in case it implemented Serializable; otherwise, null.
      java.lang.String toString()
      Returns the value's string representation along with its type and identity hash code.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • create

        public static ValueWrapper create​(java.lang.Object value)
        Factory for creating a new ValueWrapper for the supplied value.

        If the supplied value is null, this method will return a cached ValueWrapper suitable for all null values.

        Parameters:
        value - the value to wrap
        Returns:
        a wrapper for the supplied value
      • getValue

        public java.io.Serializable getValue()
        Returns the value as passed to the constructor in case it implemented Serializable; otherwise, null.
      • getType

        public java.lang.Class<?> getType()
        Returns the value's runtime type in case it wasn't null; otherwise, null.
      • getStringRepresentation

        public java.lang.String getStringRepresentation()
        Returns the value's string representation, i.e. the result of invoking Object.toString() at the time this object's constructor was called. Returns "null" if the value was null.
      • getIdentityHashCode

        public int getIdentityHashCode()
        Returns the value's identity hash code, i.e. the result of invoking System.identityHashCode(java.lang.Object) at the time this object's constructor was called. Returns 0 if the value was null.
      • toString

        public java.lang.String toString()
        Returns the value's string representation along with its type and identity hash code.
        Overrides:
        toString in class java.lang.Object