@Status(stage=PRODUCTION, unitTests=COMPLETE) @Review(by="Kees Schotanus", at="2009-09-28") @ThreadSafety(level=IMMUTABLE) public final class CInteger extends Number implements Comparable<CInteger>
Integer
is that
this class has support for arithmetic operations that protect against both
underflow and overflow.Integer
is final so this class extends
class Number
instead. This class is immutable and contains private
constructors in combination with static factory methods as suggested by
Joshua Bloch (Effective Java, Second Edition, item 15).Modifier and Type | Method and Description |
---|---|
CInteger |
add(int value)
Adds the supplied value to this value.
|
static int |
add(int x,
int y)
Adds y to x.
|
byte |
byteValue()
Returns the value of this CInteger as a byte.
|
int |
compareTo(CInteger object)
Compares two CInteger objects numerically.
|
CInteger |
divide(int value)
Divides this value by the supplied value.
|
static int |
divide(int x,
int y)
Divides x by y.
|
CInteger |
divideAndFloor(int value)
Divides this value by the supplied value and floors the result.
|
static int |
divideAndFloor(int x,
int y)
Divides x by y and floors the result.
|
double |
doubleValue()
Returns the value of this CInteger as a double.
|
boolean |
equals(Object object)
Determines whether this object and the supplied object are the same.
|
float |
floatValue()
Returns the value of this CInteger as a float.
|
int |
hashCode()
Computes the hash code value for this object.
|
int |
intValue()
Returns the value of this CInteger as an integer.
|
long |
longValue()
Returns the value of this CInteger as a long.
|
CInteger |
multiply(int value)
Multiplies this value by the supplied value.
|
static int |
multiply(int x,
int y)
Multiplies x by y.
|
static int |
random0(int maximum)
Computes a zero based random integer up to but not including the supplied
maximum.
|
static int |
random1(int maximum)
Computes a one based random integer up to and including the supplied
maximum.
|
short |
shortValue()
Returns the value of this CInteger as a short.
|
CInteger |
subtract(int value)
Subtracts the supplied value from this value.
|
static int |
subtract(int x,
int y)
Subtracts y from x.
|
String |
toString()
Converts the stored primitive integer value to a String.
|
static CInteger |
valueOf(int value)
Returns a CInteger object holding the value of the supplied value.
|
static CInteger |
valueOf(long value)
Returns a CInteger object holding the value of the supplied value.
|
static CInteger |
valueOf(Number value)
Returns a CInteger object holding the value of the supplied value.
|
static CInteger |
valueOf(String value)
Returns a CInteger object holding the parsed value of the supplied value.
|
public byte byteValue()
public short shortValue()
shortValue
in class Number
public int intValue()
public long longValue()
public float floatValue()
floatValue
in class Number
public double doubleValue()
doubleValue
in class Number
public static CInteger valueOf(int value)
value
- The integer value.public static CInteger valueOf(long value)
value
- The long value.IllegalArgumentException
- When the supplied value is not in the
range: [Integer.MIN_VALUE
to Integer.MAX_VALUE
].public static CInteger valueOf(Number value)
value
- The Number that holds the value.NullPointerException
- When the supplied value is null.IllegalArgumentException
- When the supplied value is not in the
range: [Integer.MIN_VALUE
to Integer.MAX_VALUE
].public static CInteger valueOf(String value)
value
- The String that is parsed.IllegalArgumentException
- When the supplied value (after parsing)
is not in the range:
[Integer.MIN_VALUE
to Integer.MAX_VALUE
].NumberFormatException
- When the supplied value does not contain a
parsable int (this includes a null or empty value).Integer.parseInt(String)
public boolean equals(Object object)
public int hashCode()
public int compareTo(CInteger object)
compareTo
in interface Comparable<CInteger>
object
- CInteger object to compare with this object.NullPointerException
- When the supplied object is null.Comparable
public CInteger add(int value)
value
- Value to add to the stored value.ArithmeticException
- When an arithmetic underflow or overflow
occurs.add(int, int)
public static int add(int x, int y)
x
- Operand one.y
- Operand two.ArithmeticException
- When an arithmetic underflow or overflow
occurs.public CInteger subtract(int value)
value
- Value to subtract from the stored value.ArithmeticException
- When an arithmetic underflow or overflow
occurs.subtract(int, int)
public static int subtract(int x, int y)
x
- Operand one.y
- operand two.ArithmeticException
- When an arithmetic underflow or overflow
occurs.public CInteger multiply(int value)
value
- Value to multiply by the stored value.ArithmeticException
- When an arithmetic underflow or overflow
occurs.multiply(int, int)
public static int multiply(int x, int y)
x
- Operand one.y
- Operand two.ArithmeticException
- When an arithmetic underflow or overflow
occurs.public CInteger divide(int value)
value
- Value by which this value will be divided.ArithmeticException
- When an arithmetic overflow occurs or when
the supplied value is 0.divide(int, int)
public static int divide(int x, int y)
x
- Operand one.y
- Operand two.ArithmeticException
- When an arithmetic overflow occurs or when
the supplied y value is 0.public CInteger divideAndFloor(int value)
value
- Value by which this value will be divided.ArithmeticException
- When an arithmetic overflow occurs or when
the supplied value is 0.divideAndFloor(int, int)
public static int divideAndFloor(int x, int y)
x
- Operand one.y
- Operand two.ArithmeticException
- When an arithmetic overflow occurs or when
the supplied y value is 0.public static int random0(int maximum)
maximum
- The maximum integer (exclusive) to return.IllegalArgumentException
- When the supplied maximum is less than
one.public static int random1(int maximum)
int dice = CInteger.random1(6);
maximum
- The maximum integer (inclusive) to return.IllegalArgumentException
- When the supplied maximum is less than
two.Copyright © 2008–2018. All rights reserved.