- java.lang.Object
-
- java.lang.Number
-
- org.joou.UNumber
-
- org.joou.UInteger
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<UInteger>
public final class UInteger extends UNumber implements java.lang.Comparable<UInteger>
Theunsigned inttype- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Class<UInteger>CLASSprivate static java.lang.StringCLASS_NAMEprivate static intDEFAULT_PRECACHE_SIZEDefault size for the value cache.static UIntegerMAXA constant holding the maximum value anunsigned intcan have as UInteger, 232-1.static longMAX_VALUEA constant holding the maximum value anunsigned intcan have, 232-1.static UIntegerMINA constant holding the minimum value anunsigned intcan have as UInteger, 0.static longMIN_VALUEA constant holding the minimum value anunsigned intcan have, 0.private static java.lang.StringPRECACHE_PROPERTYSystem property name for the property to set the size of the pre-cache.private static longserialVersionUIDGenerated UIDprivate longvalueThe value modelling the content of thisunsigned intprivate static UInteger[]VALUESCached values
-
Constructor Summary
Constructors Modifier Constructor Description privateUInteger(int value)Create anunsigned intby masking it with0xFFFFFFFFi.e.privateUInteger(long value)Create anunsigned intprivateUInteger(long value, boolean unused)Unchecked internal constructor.privateUInteger(java.lang.String value)Create anunsigned int
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UIntegeradd(int val)UIntegeradd(UInteger val)intcompareTo(UInteger o)doubledoubleValue()booleanequals(java.lang.Object obj)floatfloatValue()private static UIntegergetCached(long value)Retrieve a cached value.private static intgetPrecacheSize()Figure out the size of the precache.inthashCode()intintValue()longlongValue()private static UInteger[]mkValues()Generate a cached value for initial unsigned integer values.private static longrangeCheck(long value)Throw exception if value out of range (long version)private java.lang.ObjectreadResolve()Replace version read through deserialization with cached version.UIntegersubtract(int val)UIntegersubtract(UInteger val)java.math.BigIntegertoBigInteger()Get this number as aBigInteger.java.lang.StringtoString()static UIntegervalueOf(int value)Create anunsigned intby masking it with0xFFFFFFFFi.e.static UIntegervalueOf(long value)Create anunsigned intstatic UIntegervalueOf(java.lang.String value)Create anunsigned intprivate static UIntegervalueOfUnchecked(long value)Get the value of a long without checking the value.
-
-
-
Field Detail
-
CLASS
private static final java.lang.Class<UInteger> CLASS
-
CLASS_NAME
private static final java.lang.String CLASS_NAME
-
PRECACHE_PROPERTY
private static final java.lang.String PRECACHE_PROPERTY
System property name for the property to set the size of the pre-cache.
-
DEFAULT_PRECACHE_SIZE
private static final int DEFAULT_PRECACHE_SIZE
Default size for the value cache.- See Also:
- Constant Field Values
-
serialVersionUID
private static final long serialVersionUID
Generated UID- See Also:
- Constant Field Values
-
VALUES
private static final UInteger[] VALUES
Cached values
-
MIN_VALUE
public static final long MIN_VALUE
A constant holding the minimum value anunsigned intcan have, 0.- See Also:
- Constant Field Values
-
MAX_VALUE
public static final long MAX_VALUE
A constant holding the maximum value anunsigned intcan have, 232-1.- See Also:
- Constant Field Values
-
MIN
public static final UInteger MIN
A constant holding the minimum value anunsigned intcan have as UInteger, 0.
-
MAX
public static final UInteger MAX
A constant holding the maximum value anunsigned intcan have as UInteger, 232-1.
-
value
private final long value
The value modelling the content of thisunsigned int
-
-
Constructor Detail
-
UInteger
private UInteger(long value, boolean unused)Unchecked internal constructor. This serves two purposes: first it allowsUInteger(long)to stay deprecated without warnings and second constructor without unnecessary value checks.- Parameters:
value- The value to wrapunused- Unused parameter to distinguish between this and the deprecated public constructor.
-
UInteger
private UInteger(long value) throws java.lang.NumberFormatExceptionCreate anunsigned int- Throws:
java.lang.NumberFormatException- Ifvalueis not in the range of anunsigned int
-
UInteger
private UInteger(int value)
Create anunsigned intby masking it with0xFFFFFFFFi.e.(int) -1becomes(uint) 4294967295
-
UInteger
private UInteger(java.lang.String value) throws java.lang.NumberFormatExceptionCreate anunsigned int- Throws:
java.lang.NumberFormatException- Ifvaluedoes not contain a parsableunsigned int.
-
-
Method Detail
-
getPrecacheSize
private static final int getPrecacheSize()
Figure out the size of the precache.- Returns:
- The parsed value of the system property
PRECACHE_PROPERTYorDEFAULT_PRECACHE_SIZEif the property is not set, not a number or retrieving results in aSecurityException. If the parsed value is zero or negative no cache will be created. If the value is larger thanInteger.MAX_VALUEthen Integer#MAX_VALUE will be used.
-
mkValues
private static final UInteger[] mkValues()
Generate a cached value for initial unsigned integer values.- Returns:
- Array of cached values for UInteger
-
getCached
private static UInteger getCached(long value)
Retrieve a cached value.- Parameters:
value- Cached value to retrieve- Returns:
- Cached value if one exists. Null otherwise.
-
valueOfUnchecked
private static UInteger valueOfUnchecked(long value)
Get the value of a long without checking the value.
-
valueOf
public static UInteger valueOf(java.lang.String value) throws java.lang.NumberFormatException
Create anunsigned int- Throws:
java.lang.NumberFormatException- Ifvaluedoes not contain a parsableunsigned int.
-
valueOf
public static UInteger valueOf(int value)
Create anunsigned intby masking it with0xFFFFFFFFi.e.(int) -1becomes(uint) 4294967295
-
valueOf
public static UInteger valueOf(long value) throws java.lang.NumberFormatException
Create anunsigned int- Throws:
java.lang.NumberFormatException- Ifvalueis not in the range of anunsigned byte
-
rangeCheck
private static long rangeCheck(long value) throws java.lang.NumberFormatExceptionThrow 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.ObjectStreamExceptionReplace version read through deserialization with cached version.- Returns:
- cached instance of this object's value if one exists, otherwise this object
- Throws:
java.io.ObjectStreamException
-
intValue
public int intValue()
- Specified by:
intValuein classjava.lang.Number
-
longValue
public long longValue()
- Specified by:
longValuein classjava.lang.Number
-
floatValue
public float floatValue()
- Specified by:
floatValuein classjava.lang.Number
-
doubleValue
public double doubleValue()
- Specified by:
doubleValuein classjava.lang.Number
-
toBigInteger
public java.math.BigInteger toBigInteger()
Description copied from class:UNumberGet this number as aBigInteger. This is a convenience method for callingnew BigInteger(toString())- Overrides:
toBigIntegerin classUNumber
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
compareTo
public int compareTo(UInteger o)
- Specified by:
compareToin interfacejava.lang.Comparable<UInteger>
-
add
public UInteger add(int val)
-
subtract
public UInteger subtract(int val)
-
-