Class NamedInteger

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected NamedInteger​(long value)
      Constructs an integer without an associated name.
      protected NamedInteger​(long value, String description)
      Constructs an integer with an associated name.
    • Constructor Detail

      • NamedInteger

        protected NamedInteger​(long value,
                               String description)
        Constructs an integer with an associated name.
        Parameters:
        value - integer
        description - name
      • NamedInteger

        protected NamedInteger​(long value)
        Constructs an integer without an associated name. One can think of the decimal representation of the integer as being its default name.
        Parameters:
        value - integer
    • Method Detail

      • clone

        public Object clone()
        Description copied from interface: DataObject
        Perform a deep copy of this object. Read-only state of the object is not copied; the new object will be read-write by default.

        Inherently immutable objects may optionally return the same object without modification from clone(), rather than constructing a new instance.

        Specified by:
        clone in interface DataObject
        Overrides:
        clone in class Object
        Returns:
        a new object that is a deep copy of this object; for immutable objects, the same object may optionally be returned.
      • setReadOnly

        public void setReadOnly()
        Description copied from interface: DataObject
        Set this object to be "read-only". Any subsequent attempt to modify this object will throw IllegalStateException. Once an object has been made read-only, it cannot be later set to read-write - this is a "one-way" operation.

        Note that a read-only object is not necessarily immutable; if reference types are returned from accessors, then callers could theoretically mutate those objects even if the top-level object is marked as read-only. The ability to make objects read-only is intended to catch programming errors (e.g. attempting to modify a data object passed as part of a SLEE event), not to provide an absolute guarantee of immutability.

        Calling setReadOnly() on an object that is already read-only is a no-op.

        Some DataObject implementations may be inherently immutable. In those cases, they are considered always read-only.

        Specified by:
        setReadOnly in interface DataObject
      • isReadOnly

        public boolean isReadOnly()
        Description copied from interface: DataObject
        Check if this object has been set read-only.
        Specified by:
        isReadOnly in interface DataObject
        Returns:
        true if the object is read-only or inherently immutable
        See Also:
        DataObject.setReadOnly()
      • byteValue

        public byte byteValue()
        Returns the value of this number as a byte.
        Overrides:
        byteValue in class Number
        Returns:
        byte
      • doubleValue

        public double doubleValue()
        Returns the value of this number as a double.
        Specified by:
        doubleValue in class Number
        Returns:
        double
      • floatValue

        public float floatValue()
        Returns the value of this number as a float.
        Specified by:
        floatValue in class Number
        Returns:
        float
      • intValue

        public int intValue()
        Returns the value of this number as an int.
        Specified by:
        intValue in class Number
        Returns:
        int
      • longValue

        public long longValue()
        Returns the value of this number as a long.
        Specified by:
        longValue in class Number
        Returns:
        long
      • shortValue

        public short shortValue()
        Returns the value of this number as a short.
        Overrides:
        shortValue in class Number
        Returns:
        short
      • toString

        public String toString()
        Returns either the name of this number if it has a name, or a string formed from the decimal digits of the number.
        Overrides:
        toString in class Object
        Returns:
        String describing this object
      • equals

        public boolean equals​(Object obj)
        Compares some other object to this one for equality by value (not reference). For two NamedIntegers to be equal, they shall have both the same numeric value and also be of the same subclass of NamedInteger.
        Overrides:
        equals in class Object
        Parameters:
        obj - other object
        Returns:
        whether this object has the same value as obj
      • hashCode

        public int hashCode()
        Gets a hash code value for this object.
        Overrides:
        hashCode in class Object
        Returns:
        exclusive or of top four bytes and bottom four bytes of value
      • valueOf

        public static <T extends NamedInteger> T valueOf​(Class<T> namedIntegerType,
                                                         String name)
        Gets the NamedInteger of the given type that has the given name.
        Parameters:
        namedIntegerType - the class of the result
        name - the name of the result
        Returns:
        the named static instance
        Throws:
        IllegalArgumentException - if name isn't found, or namedIntegerType does not meet the contract for NamedInteger subtypes
        NullPointerException - if namedIntegerType or name is null