Package org.joou

Class UByte

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<UByte>

    public final class UByte
    extends UNumber
    implements java.lang.Comparable<UByte>
    The unsigned byte type
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static UByte MAX
      A constant holding the maximum value an unsigned byte can have as UByte, 28-1.
      static short MAX_VALUE
      A constant holding the maximum value an unsigned byte can have, 28-1.
      static UByte MIN
      A constant holding the minimum value an unsigned byte can have as UByte, 0.
      static short MIN_VALUE
      A constant holding the minimum value an unsigned byte can have, 0.
      private static long serialVersionUID
      Generated UID
      private short value
      The value modelling the content of this unsigned byte
      private static UByte[] VALUES
      Cached values
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private UByte​(byte value)
      Create an unsigned byte by masking it with 0xFF i.e.
      private UByte​(int value)
      Create an unsigned byte
      private UByte​(long value)
      Create an unsigned byte
      private UByte​(short value)
      Create an unsigned byte
      private UByte​(java.lang.String value)
      Create an unsigned byte
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      UByte add​(int val)  
      UByte add​(UByte val)  
      int compareTo​(UByte o)  
      double doubleValue()  
      boolean equals​(java.lang.Object obj)  
      float floatValue()  
      int hashCode()  
      int intValue()  
      long longValue()  
      private static UByte[] mkValues()
      Generate a cached value for each byte value.
      private static short rangeCheck​(int value)
      Throw exception if value out of range (int version)
      private static short rangeCheck​(long value)
      Throw exception if value out of range (long version)
      private static short rangeCheck​(short value)
      Throw exception if value out of range (short version)
      private java.lang.Object readResolve()
      Replace version read through deserialization with cached version.
      UByte subtract​(int val)  
      UByte subtract​(UByte val)  
      java.math.BigInteger toBigInteger()
      Get this number as a BigInteger.
      java.lang.String toString()  
      static UByte valueOf​(byte value)
      Get an instance of an unsigned byte by masking it with 0xFF i.e.
      static UByte valueOf​(int value)
      Get an instance of an unsigned byte
      static UByte valueOf​(long value)
      Get an instance of an unsigned byte
      static UByte valueOf​(short value)
      Get an instance of an unsigned byte
      static UByte valueOf​(java.lang.String value)
      Get an instance of an unsigned byte
      private static UByte valueOfUnchecked​(short value)
      Get the value of a short without checking the value.
      • Methods inherited from class java.lang.Number

        byteValue, shortValue
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Generated UID
        See Also:
        Constant Field Values
      • VALUES

        private static final UByte[] VALUES
        Cached values
      • MIN_VALUE

        public static final short MIN_VALUE
        A constant holding the minimum value an unsigned byte can have, 0.
        See Also:
        Constant Field Values
      • MAX_VALUE

        public static final short MAX_VALUE
        A constant holding the maximum value an unsigned byte can have, 28-1.
        See Also:
        Constant Field Values
      • MIN

        public static final UByte MIN
        A constant holding the minimum value an unsigned byte can have as UByte, 0.
      • MAX

        public static final UByte MAX
        A constant holding the maximum value an unsigned byte can have as UByte, 28-1.
      • value

        private final short value
        The value modelling the content of this unsigned byte
    • Constructor Detail

      • UByte

        private UByte​(long value)
               throws java.lang.NumberFormatException
        Create an unsigned byte
        Throws:
        java.lang.NumberFormatException - If value is not in the range of an unsigned byte
      • UByte

        private UByte​(int value)
               throws java.lang.NumberFormatException
        Create an unsigned byte
        Throws:
        java.lang.NumberFormatException - If value is not in the range of an unsigned byte
      • UByte

        private UByte​(short value)
               throws java.lang.NumberFormatException
        Create an unsigned byte
        Throws:
        java.lang.NumberFormatException - If value is not in the range of an unsigned byte
      • UByte

        private UByte​(byte value)
        Create an unsigned byte by masking it with 0xFF i.e. (byte) -1 becomes (ubyte) 255
      • UByte

        private UByte​(java.lang.String value)
               throws java.lang.NumberFormatException
        Create an unsigned byte
        Throws:
        java.lang.NumberFormatException - If value does not contain a parsable unsigned byte.
    • Method Detail

      • mkValues

        private static final UByte[] mkValues()
        Generate a cached value for each byte value.
        Returns:
        Array of cached values for UByte.
      • valueOf

        public static UByte valueOf​(java.lang.String value)
                             throws java.lang.NumberFormatException
        Get an instance of an unsigned byte
        Throws:
        java.lang.NumberFormatException - If value does not contain a parsable unsigned byte.
      • valueOf

        public static UByte valueOf​(byte value)
        Get an instance of an unsigned byte by masking it with 0xFF i.e. (byte) -1 becomes (ubyte) 255
      • valueOfUnchecked

        private static UByte valueOfUnchecked​(short value)
                                       throws java.lang.NumberFormatException
        Get the value of a short without checking the value.
        Throws:
        java.lang.NumberFormatException
      • valueOf

        public static UByte valueOf​(short value)
                             throws java.lang.NumberFormatException
        Get an instance of an unsigned byte
        Throws:
        java.lang.NumberFormatException - If value is not in the range of an unsigned byte
      • valueOf

        public static UByte valueOf​(int value)
                             throws java.lang.NumberFormatException
        Get an instance of an unsigned byte
        Throws:
        java.lang.NumberFormatException - If value is not in the range of an unsigned byte
      • valueOf

        public static UByte valueOf​(long value)
                             throws java.lang.NumberFormatException
        Get an instance of an unsigned byte
        Throws:
        java.lang.NumberFormatException - If value is not in the range of an unsigned byte
      • rangeCheck

        private static short rangeCheck​(short value)
                                 throws java.lang.NumberFormatException
        Throw exception if value out of range (short version)
        Parameters:
        value - Value to check
        Returns:
        value if it is in range
        Throws:
        java.lang.NumberFormatException - if value is out of range
      • rangeCheck

        private static short rangeCheck​(int value)
                                 throws java.lang.NumberFormatException
        Throw exception if value out of range (int version)
        Parameters:
        value - Value to check
        Returns:
        value if it is in range
        Throws:
        java.lang.NumberFormatException - if value is out of range
      • rangeCheck

        private static short rangeCheck​(long value)
                                 throws java.lang.NumberFormatException
        Throw exception if value out of range (long version)
        Parameters:
        value - Value to check
        Returns:
        value if it is in range
        Throws:
        java.lang.NumberFormatException - if value is out of range
      • readResolve

        private java.lang.Object readResolve()
                                      throws java.io.ObjectStreamException
        Replace version read through deserialization with cached version. Note that this does not use the valueOfUnchecked(short) as we have no guarantee that the value from the stream is valid.
        Returns:
        cached instance of this object's value
        Throws:
        java.io.ObjectStreamException
      • intValue

        public int intValue()
        Specified by:
        intValue in class java.lang.Number
      • longValue

        public long longValue()
        Specified by:
        longValue in class java.lang.Number
      • floatValue

        public float floatValue()
        Specified by:
        floatValue in class java.lang.Number
      • doubleValue

        public double doubleValue()
        Specified by:
        doubleValue in class java.lang.Number
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(UByte o)
        Specified by:
        compareTo in interface java.lang.Comparable<UByte>
      • toBigInteger

        public java.math.BigInteger toBigInteger()
        Description copied from class: UNumber
        Get this number as a BigInteger. This is a convenience method for calling new BigInteger(toString())
        Overrides:
        toBigInteger in class UNumber
      • add

        public UByte add​(UByte val)
                  throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • add

        public UByte add​(int val)
                  throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • subtract

        public UByte subtract​(int val)