@Status(stage=PRODUCTION, unitTests=COMPLETE) @Review(by="Kees Schotanus", at="2009-09-28") @ThreadSafety(level=IMMUTABLE) public final class CByte extends Number implements Comparable<CByte>
Byte
is that this class has support for arithmetic operations
that protect against both underflow and overflow.Byte
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 | Field and Description |
---|---|
static int |
BITS_5_TO_8_MASK
Masks the four rightmost bits.
|
static int |
BITS_FOR_ONE_HEX_CHARACTER
Number of bits that represent a single hexadecimal character.
|
static int |
BITS_IN_BYTE
Number of bits in a single byte.
|
static int |
GIGA_BYTE
Number of bytes in a gigabyte.
|
static int |
KILO_BYTE
Number of bytes in a kilobyte.
|
static int |
MEGA_BYTE
Number of bytes in a megabyte.
|
static int |
TERA_BYTE
Number of bytes in a terabyte.
|
Modifier and Type | Method and Description |
---|---|
CByte |
add(byte value)
Adds the supplied value to this value.
|
static byte |
add(byte x,
byte y)
Adds y to x.
|
byte |
byteValue()
Returns the value of this CByte as a byte.
|
int |
compareTo(CByte object)
Compares two CByte objects numerically.
|
CByte |
divide(byte value)
Divides this value by the supplied value.
|
static byte |
divide(byte x,
byte y)
Divides x by y.
|
CByte |
divideAndFloor(byte value)
Divides this value by the supplied value and floors the result.
|
static byte |
divideAndFloor(byte x,
byte y)
Divides x by y and floors the result.
|
double |
doubleValue()
Returns the value of this CByte 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 CByte as a float.
|
int |
hashCode()
Computes the hash code value for this object.
|
int |
intValue()
Returns the value of this CByte as an int.
|
long |
longValue()
Returns the value of this CByte as a long.
|
CByte |
multiply(byte value)
Multiplies this value by the supplied value.
|
static byte |
multiply(byte x,
byte y)
Multiplies x by y.
|
short |
shortValue()
Returns the value of this CByte as a short.
|
CByte |
subtract(byte value)
Subtracts the supplied value from this value.
|
static byte |
subtract(byte x,
byte y)
Subtracts y from x.
|
static String |
toHexadecimalCharacters(byte value)
Converts the supplied value to two hexadecimal characters.
|
static String |
toHexadecimalCharacters(byte[] values)
Converts the supplied byte array value to hexadecimal characters.
|
String |
toString()
Converts the stored primitive byte value to a String.
|
static CByte |
valueOf(byte value)
Returns a CByte object holding the value of the supplied value.
|
static CByte |
valueOf(long value)
Returns a CByte object holding the value of the supplied value.
|
static CByte |
valueOf(Number value)
Returns a CByte object holding the value of the supplied value.
|
static CByte |
valueOf(String value)
Returns a CByte object holding the parsed value of the supplied value.
|
public static final int BITS_IN_BYTE
public static final int KILO_BYTE
public static final int MEGA_BYTE
public static final int GIGA_BYTE
public static final int TERA_BYTE
public static final int BITS_FOR_ONE_HEX_CHARACTER
public static final int BITS_5_TO_8_MASK
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 CByte valueOf(byte value)
value
- The byte value.public static CByte valueOf(long value)
value
- The long value.IllegalArgumentException
- When the supplied value is not in the range:
[Byte.MIN_VALUE
to Byte.MAX_VALUE
].public static CByte 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:
[Byte.MIN_VALUE
to Byte.MAX_VALUE
].public static CByte valueOf(String value)
value
- The String that is parsed.IllegalArgumentException
- When the supplied value (after parsing) is not in the range:
[Byte.MIN_VALUE
to Byte.MAX_VALUE
].NumberFormatException
- When the supplied value does not contain a parsable byte
(this includes a null or empty value).Byte.parseByte(String)
public boolean equals(Object object)
public int hashCode()
public int compareTo(CByte object)
compareTo
in interface Comparable<CByte>
object
- CByte object to compare with this object.NullPointerException
- When the supplied object is null.Comparable
public CByte add(byte value)
value
- Value to add to the stored value.ArithmeticException
- When an arithmetic underflow or overflow occurs.add(byte, byte)
public static byte add(byte x, byte y)
x
- Operand one.y
- Operand two.ArithmeticException
- When an arithmetic underflow or overflow occurs.public CByte subtract(byte value)
value
- Value to subtract from the stored value.ArithmeticException
- When an arithmetic underflow or overflow occurs.subtract(byte, byte)
public static byte subtract(byte x, byte y)
x
- Operand one.y
- operand two.ArithmeticException
- When an arithmetic underflow or overflow occurs.public CByte multiply(byte value)
value
- Value to multiply by the stored value.ArithmeticException
- When an arithmetic underflow or overflow occurs.multiply(byte, byte)
public static byte multiply(byte x, byte y)
x
- Operand one.y
- Operand two.ArithmeticException
- When an arithmetic underflow or overflow occurs.public CByte divide(byte value)
value
- Value by which this value will be divided.ArithmeticException
- When an arithmetic overflow occurs or when the supplied value is 0.divide(byte, byte)
public static byte divide(byte x, byte y)
x
- Operand one.y
- Operand two.ArithmeticException
- When an arithmetic overflow occurs or when the supplied y value is 0.public CByte divideAndFloor(byte value)
value
- Value by which this value will be divided.ArithmeticException
- When an arithmetic overflow occurs or when the supplied value is 0.divideAndFloor(byte, byte)
public static byte divideAndFloor(byte x, byte y)
x
- Operand one.y
- Operand two.ArithmeticException
- When an arithmetic overflow occurs or when the supplied y value is 0.public static String toHexadecimalCharacters(byte value)
value
- The value to convert to two hexadecimal characters.public static String toHexadecimalCharacters(byte[] values)
values
- The byte array value to convert to hexadecimal characters.Copyright © 2008–2018. All rights reserved.