|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Number net.sf.ivmaidns.util.UnsignedInt
public final class UnsignedInt
Class for unsigned integer wrappers.
This class wraps a primitive unsigned int
value
(like Integer
class). The class also contains
static
methods for the unsigned integer arithmetic:
comparison, median, multiplication (simple and modular),
division, remainder, power, logarithm, factorial, modular
inversion, 'greatest common divisor', conversion to/from a byte
array (in the direct and reversed orders), stream bits
writing/reading, conversion to/from a string (in some given
radix, using Roman notation, or according to a given list of
mnemonics/abbreviations).
UnsignedLong
,
IntVector
,
ByteVector
,
PseudoRandom
,
JavaConsts
,
Serialized FormField Summary | |
---|---|
static java.lang.String |
ROMAN_DIGITS
The Roman digits string specifier. |
protected int |
unsignedValue
The wrapped (encapsulated) unsigned int value. |
Constructor Summary | |
---|---|
UnsignedInt(int unsignedValue)
Constructs a new object that represents the specified primitive unsigned int value. |
Method Summary | |
---|---|
static int |
binLog(int unsignedValue)
Returns the integer part of binary logarithm of a given unsigned value. |
java.lang.Object |
clone()
Creates and returns a copy of this object. |
static int |
compare(int unsignedA,
int unsignedB)
Compares two given unsigned integer values. |
static int |
decode(java.lang.String str,
int beginIndex,
int endIndex)
Decodes a given string region as an unsigned octal/decimal/hexadecimal integer value. |
static int |
div(int unsignedA,
int unsignedB)
Returns the result of integer division of one given unsigned value by another one. |
static long |
div(long unsignedLongA,
int unsignedB)
Returns the result of integer division of one given unsigned long value by another unsigned int
value. |
static int |
divHigh(int unsignedHighA,
int unsignedLowA,
int unsignedB)
Returns the highest half of the result of integer division of join of two given halves of unsigned value by another one. |
static int |
divHigh(long unsignedLongA,
int unsignedB)
Returns the highest half of the result of integer division of one given unsigned long value by another unsigned
int value. |
static int |
divLow(int unsignedHighA,
int unsignedLowA,
int unsignedB)
Returns the lowest half of the result of integer division of join of two given halves of unsigned value by another one. |
static int |
divLow(long unsignedLongA,
int unsignedB)
Returns the lowest half of the result of integer division of one given unsigned long value by another unsigned
int value. |
double |
doubleValue()
Returns the value of this number as
double . |
boolean |
equals(java.lang.Object obj)
Indicates whether this object is equal to the
specified one. |
static int |
factorial(int value)
Computes the factorial of a given value. |
static java.lang.String |
filledString(char ch,
int len)
Constructs and returns a string filled with a given character. |
float |
floatValue()
Returns the value of this number as
float . |
static int |
gcd(int unsignedA,
int unsignedB)
Computes the greatest 'common divisor' (gcd) of two given unsigned non-zero values. |
static int |
getFromByteArray(byte[] bytes,
int offset,
int len)
Converts the specified region of a given byte array into an unsigned value. |
static int |
getFromIntelArray(byte[] bytes,
int offset,
int len)
Converts the specified region of a given byte array into an unsigned value in the reversed order. |
static boolean |
greater(int unsignedA,
int unsignedB)
Tests whether the first specified unsigned integer is greater than the second one. |
static boolean |
greaterOrEqual(int unsignedA,
int unsignedB)
Tests whether the first specified unsigned integer is greater or equal to the second one. |
boolean |
greaterThan(java.lang.Object obj)
Tests for being semantically greater than the argument. |
int |
hashCode()
Returns a hash code value for the object. |
int |
intValue()
Returns the value of this number as
int . |
static int |
inverseMod(int unsignedA,
int unsignedMax)
Computes the modular 'inversion' of a given unsigned value. |
long |
longValue()
Returns the value of this number as
long . |
static int |
max(int unsignedA,
int unsignedB)
Returns the maximum of two given unsigned integer values. |
static int |
median(int unsignedA,
int unsignedB,
int unsignedC)
Returns the 'median' (middle value) of three given unsigned integer values. |
static int |
min(int unsignedA,
int unsignedB)
Returns the minimum of two given unsigned integer values. |
static long |
mul(int unsignedA,
int unsignedB)
Returns the product of two given unsigned int values
extended to long type. |
static int |
mulDiv(int unsignedA,
int unsignedB,
int unsignedC,
boolean roundUp)
Returns the lowest half of the result of integer division of 'long' (full) product of the first two given unsigned non-zero values by the third given unsigned non-zero value. |
static int |
mulHigh(int unsignedA,
int unsignedB)
Returns the highest half of 'long' (full) product of two given unsigned integers. |
static int |
mulLow(int unsignedA,
int unsignedB)
Returns the lowest half of 'long' (full) product of two given unsigned integers. |
static int |
mulMod(int unsignedA,
int unsignedB,
int unsignedMax)
Computes the modular 'multiplication' of two given unsigned values. |
static int |
parse(java.lang.String str,
int beginIndex,
int endIndex,
boolean isUnsigned,
int radix)
Parses a given string region as a signed/unsigned integer in the specified radix. |
static int |
parseAbbreviation(java.lang.String str,
int beginIndex,
int endIndex,
java.lang.String sortedRefAbbrevsList)
Parses a given string region as an integer value abbreviation according to the specified packed list of abbreviations. |
static int |
parseRoman(java.lang.String str,
int beginIndex,
int endIndex)
Parses a given string region as an integer in the Roman notation. |
static int |
power(int value,
int degree)
Returns a given value involved to the power of the specified degree. |
static void |
putToByteArray(byte[] bytes,
int offset,
int unsignedValue,
int len)
Puts a given value into the specified byte array. |
static void |
putToIntelArray(byte[] bytes,
int offset,
int unsignedValue,
int len)
Puts a given value into the specified byte array in the reversed order. |
static int |
readBits(java.io.InputStream in,
int count)
Reads a group of bits from a given input stream. |
static int |
readByte(java.io.InputStream in)
Reads one input byte as an unsigned value. |
static int |
rem(int unsignedA,
int unsignedB)
Returns the remainder of integer division of one given unsigned value by another one. |
static int |
rem(long unsignedLongA,
int unsignedB)
Returns the remainder of integer division of one given unsigned long value by another unsigned int
value. |
static int |
remLow(int unsignedHighA,
int unsignedLowA,
int unsignedB)
Returns the remainder of integer division of join of two given halves of unsigned value by another one. |
static int |
signedCompare(int valueA,
int valueB)
Compares two given (signed) integer values. |
static int |
signedMedian(int valueA,
int valueB,
int valueC)
Returns the 'median' (middle value) of three given (signed) integer values. |
static java.lang.String |
toAbbreviation(int value,
java.lang.String paddedAbbrevsList)
Converts a given value into its abbreviation according to the specified packed list of abbreviations. |
static java.lang.String |
toBinaryString(int unsignedValue,
int minLength)
Converts a given unsigned value into its binary string representation. |
static byte[] |
toByteArray(int unsignedValue,
int len)
Converts a given value into a byte array. |
static java.lang.String |
toHexString(int unsignedValue,
boolean upperCase,
int minLength)
Converts a given unsigned value into its hexadecimal string representation. |
static byte[] |
toIntelArray(int unsignedValue,
int len)
Converts a given value in the reversed order into a byte array. |
static java.lang.String |
toOctalString(int unsignedValue,
int minLength)
Converts a given unsigned value into its octal string representation. |
static java.lang.String |
toRomanString(int value,
boolean upperCase,
int minLength)
Converts a given value into its Roman notation. |
java.lang.String |
toString()
Converts this object to its 'in-line' string
representation. |
static java.lang.String |
toString(int value,
boolean isUnsigned)
Converts a given signed/unsigned value into its decimal string representation. |
static java.lang.String |
toString(int value,
boolean isUnsigned,
boolean forceSign,
int radix,
boolean upperCase,
int minLength)
Converts a given signed/unsigned value into its string representation in the specified radix. |
static UnsignedInt |
valueOf(java.lang.String str)
Converts a given string to an instance of this class. |
static void |
writeBits(java.io.OutputStream out,
int unsignedValue,
int count)
Writes a group of bits to a given output stream. |
Methods inherited from class java.lang.Number |
---|
byteValue, shortValue |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ROMAN_DIGITS
null
) is used internally
by the corresponding conversion methods. Important notes: the
digits are all latin upper-case characters; the digits are
specified starting from the most significant one (the last digit
has the weight of 1
, the previous one has the weight
of (('9' - '0') / 2 + 1)
, the digit before it has
the weight of ('9' - '0' + 1)
, and so on).
toRomanString(int, boolean, int)
,
parseRoman(java.lang.String, int, int)
,
Constant Field Valuesprotected int unsignedValue
int
value.
Important notes: this value is constant.
UnsignedInt(int)
,
valueOf(java.lang.String)
,
clone()
,
hashCode()
,
intValue()
,
longValue()
,
floatValue()
,
doubleValue()
,
equals(java.lang.Object)
,
greaterThan(java.lang.Object)
,
toString()
Constructor Detail |
---|
public UnsignedInt(int unsignedValue)
int
value.
unsignedValue
- the unsigned value to be wrapped.valueOf(java.lang.String)
,
clone()
,
intValue()
,
longValue()
,
equals(java.lang.Object)
,
greaterThan(java.lang.Object)
,
toString()
Method Detail |
---|
public static final boolean greater(int unsignedA, int unsignedB)
unsignedA
- the first compared unsigned value.unsignedB
- the second compared unsigned value.
true
if and only if unsignedA is greater
than unsignedB (in the unsigned manner).greaterOrEqual(int, int)
,
compare(int, int)
,
min(int, int)
,
max(int, int)
,
median(int, int, int)
,
greaterThan(java.lang.Object)
public static final boolean greaterOrEqual(int unsignedA, int unsignedB)
unsignedA
- the first compared unsigned value.unsignedB
- the second compared unsigned value.
true
if and only if unsignedA is not less
than unsignedB (in the unsigned manner).greater(int, int)
,
compare(int, int)
,
min(int, int)
,
max(int, int)
,
median(int, int, int)
,
equals(java.lang.Object)
,
greaterThan(java.lang.Object)
public static final int compare(int unsignedA, int unsignedB)
int
values.
unsignedA
- the first compared unsigned value.unsignedB
- the second compared unsigned value.
signedCompare(int, int)
,
greater(int, int)
,
greaterOrEqual(int, int)
,
min(int, int)
,
max(int, int)
,
median(int, int, int)
,
equals(java.lang.Object)
,
greaterThan(java.lang.Object)
public static final int signedCompare(int valueA, int valueB)
int
values.
valueA
- the first compared (signed) value.valueB
- the second compared (signed) value.
compare(int, int)
,
signedMedian(int, int, int)
public static final int min(int unsignedA, int unsignedB)
unsignedA
- the first unsigned value.unsignedB
- the second unsigned value.
max(int, int)
,
median(int, int, int)
,
greater(int, int)
,
greaterOrEqual(int, int)
,
compare(int, int)
public static final int max(int unsignedA, int unsignedB)
unsignedA
- the first unsigned value.unsignedB
- the second unsigned value.
min(int, int)
,
median(int, int, int)
,
greater(int, int)
,
greaterOrEqual(int, int)
,
compare(int, int)
public static final int median(int unsignedA, int unsignedB, int unsignedC)
unsignedA
- the first unsigned value.unsignedB
- the second unsigned value.unsignedC
- the third unsigned value.
signedMedian(int, int, int)
,
min(int, int)
,
max(int, int)
,
greater(int, int)
,
greaterOrEqual(int, int)
,
compare(int, int)
public static final int signedMedian(int valueA, int valueB, int valueC)
valueA
- the first (signed) value.valueB
- the second (signed) value.valueC
- the third (signed) value.
median(int, int, int)
,
signedCompare(int, int)
public static final int mulHigh(int unsignedA, int unsignedB)
unsignedA
- the first unsigned value.unsignedB
- the second unsigned value.
divHigh(int, int, int)
,
mulLow(int, int)
,
mul(int, int)
,
mulDiv(int, int, int, boolean)
,
mulMod(int, int, int)
,
power(int, int)
,
factorial(int)
public static final int mulLow(int unsignedA, int unsignedB)
unsignedA
- the first unsigned value.unsignedB
- the second unsigned value.
divLow(int, int, int)
,
remLow(int, int, int)
,
mulHigh(int, int)
,
mul(int, int)
,
mulDiv(int, int, int, boolean)
,
mulMod(int, int, int)
,
power(int, int)
,
factorial(int)
public static final long mul(int unsignedA, int unsignedB)
int
values
extended to long
type.
unsignedA
- the first unsigned value.unsignedB
- the second unsigned value.
long
result of unsignedA
multiplied by unsignedB.div(long, int)
,
divHigh(long, int)
,
divLow(long, int)
,
rem(long, int)
,
mulHigh(int, int)
,
mulLow(int, int)
,
mulDiv(int, int, int, boolean)
,
mulMod(int, int, int)
public static final int div(int unsignedA, int unsignedB) throws java.lang.ArithmeticException
unsignedA
- the first unsigned value.unsignedB
- the second unsigned value.
java.lang.ArithmeticException
- if unsignedB is 0
.mulLow(int, int)
,
rem(int, int)
,
div(long, int)
,
divHigh(int, int, int)
,
divLow(int, int, int)
,
mulDiv(int, int, int, boolean)
,
gcd(int, int)
,
inverseMod(int, int)
public static final long div(long unsignedLongA, int unsignedB) throws java.lang.ArithmeticException
long
value by another unsigned int
value.
unsignedLongA
- the first unsigned value.unsignedB
- the second unsigned value.
java.lang.ArithmeticException
- if unsignedB is 0
.div(int, int)
,
mul(int, int)
,
rem(long, int)
,
divHigh(long, int)
,
divLow(long, int)
public static final int divHigh(int unsignedHighA, int unsignedLowA, int unsignedB) throws java.lang.ArithmeticException
div(unsignedHighA, unsignedB)
.
unsignedHighA
- the top half of the first unsigned value.unsignedLowA
- the bottom half of the first unsigned value.unsignedB
- the second unsigned value.
java.lang.ArithmeticException
- if unsignedB is 0
.divLow(int, int, int)
,
mulHigh(int, int)
,
mulLow(int, int)
,
div(int, int)
,
div(long, int)
,
divHigh(long, int)
,
mulDiv(int, int, int, boolean)
public static final int divHigh(long unsignedLongA, int unsignedB) throws java.lang.ArithmeticException
long
value by another unsigned
int
value.
unsignedLongA
- the first unsigned value.unsignedB
- the second unsigned value.
java.lang.ArithmeticException
- if unsignedB is 0
.divHigh(int, int, int)
,
divLow(long, int)
,
mul(int, int)
,
div(long, int)
,
rem(long, int)
public static final int divLow(int unsignedHighA, int unsignedLowA, int unsignedB) throws java.lang.ArithmeticException
unsignedHighA
- the top half of the first unsigned value.unsignedLowA
- the bottom half of the first unsigned value.unsignedB
- the second unsigned value.
java.lang.ArithmeticException
- if unsignedB is 0
.divHigh(int, int, int)
,
remLow(int, int, int)
,
mulHigh(int, int)
,
mulLow(int, int)
,
div(int, int)
,
div(long, int)
,
divLow(long, int)
,
mulDiv(int, int, int, boolean)
,
gcd(int, int)
public static final int divLow(long unsignedLongA, int unsignedB) throws java.lang.ArithmeticException
long
value by another unsigned
int
value.
The result is the same as of
(int)div(unsignedLongA, unsignedB)
.
unsignedLongA
- the first unsigned value.unsignedB
- the second unsigned value.
java.lang.ArithmeticException
- if unsignedB is 0
.divLow(int, int, int)
,
divHigh(long, int)
,
mul(int, int)
,
div(long, int)
,
rem(long, int)
public static final int rem(int unsignedA, int unsignedB) throws java.lang.ArithmeticException
(unsignedA - div(unsignedA, unsignedB) * unsignedB)
.
unsignedA
- the first unsigned value.unsignedB
- the second unsigned value.
java.lang.ArithmeticException
- if unsignedB is 0
.mulLow(int, int)
,
div(int, int)
,
rem(long, int)
,
remLow(int, int, int)
,
inverseMod(int, int)
public static final int rem(long unsignedLongA, int unsignedB) throws java.lang.ArithmeticException
long
value by another unsigned int
value.
unsignedLongA
- the first unsigned value.unsignedB
- the second unsigned value.
java.lang.ArithmeticException
- if unsignedB is 0
.rem(int, int)
,
remLow(int, int, int)
,
mul(int, int)
,
div(long, int)
public static final int remLow(int unsignedHighA, int unsignedLowA, int unsignedB) throws java.lang.ArithmeticException
unsignedHighA
- the top half of the first unsigned value.unsignedLowA
- the bottom half of the first unsigned value.unsignedB
- the second unsigned value.
java.lang.ArithmeticException
- if unsignedB is 0
.rem(int, int)
,
rem(long, int)
,
divLow(int, int, int)
,
mulHigh(int, int)
,
mulLow(int, int)
,
mulMod(int, int, int)
public static final int power(int value, int degree)
0
is returned. Important notes: value may
be signed or unsigned.
value
- the signed/unsigned value to be involved to the power.degree
- the degree of the power.
mulLow(int, int)
,
binLog(int)
,
factorial(int)
public static final int binLog(int unsignedValue)
-1
is
returned, else the result is in the range from 0
to
(JavaConsts INT_SIZE - 1)
, inclusive.
unsignedValue
- the unsigned argument of the logarithm.
power(int, int)
,
factorial(int)
public static final int factorial(int value)
0
is returned.
value
- the factorial argument.
mulLow(int, int)
,
power(int, int)
,
binLog(int)
public static final int gcd(int unsignedA, int unsignedB)
int
value plus one.
unsignedA
- the first unsigned value.unsignedB
- the second unsigned value.
inverseMod(int, int)
,
mulMod(int, int, int)
,
mulDiv(int, int, int, boolean)
,
binLog(int)
public static final int inverseMod(int unsignedA, int unsignedMax)
gcd(unsignedA, unsignedMax + 1) == 1
then mulMod(result, unsignedA, unsignedMax)
is
1
. The result of modular inversion is in the range
from 1
to max(unsignedMax, 1)
,
inclusive.
unsignedA
- the unsigned value to inverse.unsignedMax
- the unsigned maximum for modular multiplication.
mulMod(int, int, int)
,
gcd(int, int)
,
div(int, int)
,
rem(int, int)
public static final int mulMod(int unsignedA, int unsignedB, int unsignedMax)
0
to
unsignedMax, inclusive.
unsignedA
- the first unsigned value to multiply.unsignedB
- the second unsigned value to multiply.unsignedMax
- the unsigned maximum value for the result to have.
inverseMod(int, int)
,
gcd(int, int)
,
mulDiv(int, int, int, boolean)
,
mulHigh(int, int)
,
remLow(int, int, int)
public static final int mulDiv(int unsignedA, int unsignedB, int unsignedC, boolean roundUp)
int
value plus one.
unsignedA
- the first unsigned value.unsignedB
- the second unsigned value.unsignedC
- the unsigned divisor value.roundUp
- true
if the result of division is rounded upwards
(to the nearest greater integer value), else it is rounded
towards zero.
mul(int, int)
,
mulHigh(int, int)
,
mulLow(int, int)
,
divLow(long, int)
,
divLow(int, int, int)
,
gcd(int, int)
,
mulMod(int, int, int)
,
inverseMod(int, int)
public static final void putToByteArray(byte[] bytes, int offset, int unsignedValue, int len) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
JavaConsts INT_LENGTH
then unsignedValue is zero-extended.
bytes
- the byte array (must be non-null
) to put to.offset
- the first array index (must be in the range) to put at.unsignedValue
- the value, containing the bytes (in its lowest part) to be put.len
- the amount of bytes to put.
java.lang.NullPointerException
- if bytes is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of bytes minus
len).toByteArray(int, int)
,
getFromByteArray(byte[], int, int)
,
putToIntelArray(byte[], int, int, int)
,
writeBits(java.io.OutputStream, int, int)
public static final byte[] toByteArray(int unsignedValue, int len)
JavaConsts INT_LENGTH
then unsignedValue
is zero-extended.
unsignedValue
- the value, containing the bytes (in its lowest part) to be put.len
- the amount of bytes to put (length
of the array to
create).
null
, with
length
the same as non-negative len),
containing the bytes of unsignedValue.
java.lang.OutOfMemoryError
- if there is not enough memory.putToByteArray(byte[], int, int, int)
,
getFromByteArray(byte[], int, int)
,
toIntelArray(int, int)
,
writeBits(java.io.OutputStream, int, int)
public static final int getFromByteArray(byte[] bytes, int offset, int len) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
bytes
- the byte array (must be non-null
) to get from.offset
- the first array index (must be in the range) to get at.len
- the amount of bytes to get.
java.lang.NullPointerException
- if bytes is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of bytes minus
len).putToByteArray(byte[], int, int, int)
,
toByteArray(int, int)
,
getFromIntelArray(byte[], int, int)
,
readBits(java.io.InputStream, int)
public static final void putToIntelArray(byte[] bytes, int offset, int unsignedValue, int len) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
JavaConsts INT_LENGTH
then unsignedValue is zero-extended.
bytes
- the byte array (must be non-null
) to put to.offset
- the first array index (must be in the range) to put at.unsignedValue
- the value, containing the bytes (in its lowest part) to be put.len
- the amount of bytes to put.
java.lang.NullPointerException
- if bytes is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of bytes minus
len).toIntelArray(int, int)
,
getFromIntelArray(byte[], int, int)
,
putToByteArray(byte[], int, int, int)
public static final byte[] toIntelArray(int unsignedValue, int len)
JavaConsts INT_LENGTH
then unsignedValue is zero-extended.
unsignedValue
- the value, containing the bytes (in its lowest part) to be put.len
- the amount of bytes to put (length
of the array to
create).
null
, with
length
the same as non-negative len),
containing the bytes of unsignedValue.
java.lang.OutOfMemoryError
- if there is not enough memory.putToIntelArray(byte[], int, int, int)
,
getFromIntelArray(byte[], int, int)
,
toByteArray(int, int)
public static final int getFromIntelArray(byte[] bytes, int offset, int len) throws java.lang.NullPointerException, java.lang.ArrayIndexOutOfBoundsException
bytes
- the byte array (must be non-null
) to get from.offset
- the first array index (must be in the range) to get at.len
- the amount of bytes to get.
java.lang.NullPointerException
- if bytes is null
.
java.lang.ArrayIndexOutOfBoundsException
- if len is positive and (offset is negative
or is greater than length
of bytes minus
len).putToIntelArray(byte[], int, int, int)
,
toIntelArray(int, int)
,
getFromByteArray(byte[], int, int)
public static final void writeBits(java.io.OutputStream out, int unsignedValue, int count) throws java.lang.NullPointerException, java.io.IOException
JavaConsts INT_SIZE
then the specified value (containing the bits to write) is
zero-extended; out is a byte-oriented stream, so given
bits are padded with zeros (on the most significant side); the
bits are written starting from the most significant one.
out
- the stream (must be non-null
) to write to.unsignedValue
- the unsigned value, containing bits (in its lowest part) to be
written.count
- the amount of bits to be written.
java.lang.NullPointerException
- if out is null
.
java.io.IOException
- if an I/O error occurs.readBits(java.io.InputStream, int)
,
readByte(java.io.InputStream)
public static final int readBits(java.io.InputStream in, int count) throws java.lang.NullPointerException, java.io.IOException
EOFException
(subclass of IOException
) is thrown. Important
notes: if count is greater than
JavaConsts INT_SIZE
then the result contains only
tail (the least significant) read bits portion fit the result;
in is a byte-oriented stream, so padding bits are read
but set to zero (on the most significant side); the bits are read
starting from the most significant one.
in
- the stream (must be non-null
) to read from.count
- the amount of bits to be read.
JavaConsts INT_SIZE
).
java.lang.NullPointerException
- if in is null
.
java.io.IOException
- if the end-of-stream has been reached or an I/O error occurs.writeBits(java.io.OutputStream, int, int)
,
readByte(java.io.InputStream)
public static final int readByte(java.io.InputStream in) throws java.lang.NullPointerException, java.io.IOException
byte
as an unsigned value.
If the end-of-stream is detected then EOFException
(subclass of IOException
) is thrown.
in
- the stream (must be non-null
) to read from.
0
to JavaConsts BYTE_MASK
, inclusive.
java.lang.NullPointerException
- if in is null
.
java.io.IOException
- if the end-of-stream has been reached or an I/O error occurs.writeBits(java.io.OutputStream, int, int)
,
readBits(java.io.InputStream, int)
public static final java.lang.String toString(int value, boolean isUnsigned, boolean forceSign, int radix, boolean upperCase, int minLength)
value
- the signed/unsigned value to be converted.isUnsigned
- true
if value must be treated as an
unsigned value (but only if not forceSign), else
value is signed.forceSign
- true
if and only if the result must always have a
sign (positive or negative).radix
- the radix (any value) to be used as a base of the value string
format.upperCase
- true
if and only if (digit) characters in the result
are in the upper case.minLength
- the minimal length of the result (absolute value) and pad prefix
specifier (if negative then space padding else zero padding).
null
, with
length()
not less than
max(abs(minLength), 1)
) of value in the
specified radix.
java.lang.OutOfMemoryError
- if there is not enough memory.toBinaryString(int, int)
,
toOctalString(int, int)
,
toString(int, boolean)
,
toHexString(int, boolean, int)
,
toRomanString(int, boolean, int)
,
toAbbreviation(int, java.lang.String)
,
filledString(char, int)
,
parse(java.lang.String, int, int, boolean, int)
,
decode(java.lang.String, int, int)
public static final java.lang.String toString(int value, boolean isUnsigned)
value
- the signed/unsigned value to be converted.isUnsigned
- true
if value must be treated as an
unsigned value, else value is signed.
null
, with non-zero
length()
) of value in the decimal radix.
java.lang.OutOfMemoryError
- if there is not enough memory.toString(int, boolean, boolean, int, boolean, int)
,
toBinaryString(int, int)
,
toOctalString(int, int)
,
toHexString(int, boolean, int)
,
toRomanString(int, boolean, int)
,
toAbbreviation(int, java.lang.String)
,
filledString(char, int)
,
parse(java.lang.String, int, int, boolean, int)
,
decode(java.lang.String, int, int)
public static final java.lang.String toBinaryString(int unsignedValue, int minLength)
unsignedValue
- the unsigned value to be converted.minLength
- the minimal length of the result (absolute value) and pad prefix
specifier (if negative then space padding else zero padding).
null
, with
length()
not less than
max(abs(minLength), 1)
) of unsignedValue
in the binary radix.
java.lang.OutOfMemoryError
- if there is not enough memory.toString(int, boolean, boolean, int, boolean, int)
,
toOctalString(int, int)
,
toString(int, boolean)
,
toHexString(int, boolean, int)
,
parse(java.lang.String, int, int, boolean, int)
public static final java.lang.String toOctalString(int unsignedValue, int minLength)
unsignedValue
- the unsigned value to be converted.minLength
- the minimal length of the result (absolute value) and pad prefix
specifier (if negative then space padding else zero padding).
null
, with
length()
not less than
max(abs(minLength), 1)
) of unsignedValue
in the octal radix.
java.lang.OutOfMemoryError
- if there is not enough memory.toString(int, boolean, boolean, int, boolean, int)
,
toBinaryString(int, int)
,
toString(int, boolean)
,
toHexString(int, boolean, int)
,
parse(java.lang.String, int, int, boolean, int)
,
decode(java.lang.String, int, int)
public static final java.lang.String toHexString(int unsignedValue, boolean upperCase, int minLength)
unsignedValue
- the unsigned value to be converted.upperCase
- true
if and only if (digit) characters in the result
are in the upper case.minLength
- the minimal length of the result (absolute value) and pad prefix
specifier (if negative then space padding else zero padding).
null
, with
length()
not less than
max(abs(minLength), 1)
) of unsignedValue
in the hexadecimal radix.
java.lang.OutOfMemoryError
- if there is not enough memory.toString(int, boolean, boolean, int, boolean, int)
,
toBinaryString(int, int)
,
toOctalString(int, int)
,
toString(int, boolean)
,
parse(java.lang.String, int, int, boolean, int)
,
decode(java.lang.String, int, int)
public static final int parse(java.lang.String str, int beginIndex, int endIndex, boolean isUnsigned, int radix) throws java.lang.NullPointerException, java.lang.StringIndexOutOfBoundsException, ParserException
ParserException
is thrown if overflow occurs). If the specified radix is invalid
(less than two or too big) then it is corrected to the nearest
valid one. Important notes: use ('9' - '0' + 1)
to
parse a decimal number.
str
- the string (must be non-null
), which region to
parse.beginIndex
- the string region beginning index (must be in the range),
inclusive.endIndex
- the string region ending index (must be in the range), exclusive.isUnsigned
- true
if and only if the result must be an unsigned
value.radix
- the radix (any value) to be used as a base of the value string
format.
java.lang.NullPointerException
- if str is null
.
java.lang.StringIndexOutOfBoundsException
- if beginIndex is negative, or if endIndex
is less than beginIndex or is greater than
length()
of str.
ParserException
- if str region cannot be parsed as a signed/unsigned
integer (error is set to 1
,
2
or 3
in the exception, meaning an
illegal character is found, number overflow occurs or unexpected
end of region is encountered at index, respectively).toString(int, boolean, boolean, int, boolean, int)
,
toBinaryString(int, int)
,
toOctalString(int, int)
,
toString(int, boolean)
,
toHexString(int, boolean, int)
,
decode(java.lang.String, int, int)
,
valueOf(java.lang.String)
,
parseRoman(java.lang.String, int, int)
,
parseAbbreviation(java.lang.String, int, int,
java.lang.String)
public static final int decode(java.lang.String str, int beginIndex, int endIndex) throws java.lang.NullPointerException, java.lang.StringIndexOutOfBoundsException, ParserException
int
value formats are
accepted: decimal, hexadecimal (with '0x', '0X' or '#' prefix)
and octal (with '0' prefix). Leading spaces (before the prefix)
are ignored. Sign prefix is not permitted. Leading '0' characters
(after the prefix) are ignored too.
str
- the string (must be non-null
), which region to
parse.beginIndex
- the string region beginning index (must be in the range),
inclusive.endIndex
- the string region ending index (must be in the range), exclusive.
java.lang.NullPointerException
- if str is null
.
java.lang.StringIndexOutOfBoundsException
- if beginIndex is negative, or if endIndex
is less than beginIndex or is greater than
length()
of str.
ParserException
- if str region cannot be parsed (decoded) as an
unsigned integer (error is set to 1
,
2
or 3
in the exception, meaning an
illegal character is found, number overflow occurs or unexpected
end of region is encountered at index, respectively).parse(java.lang.String, int, int, boolean, int)
,
toString(int, boolean, boolean, int, boolean, int)
,
toOctalString(int, int)
,
toString(int, boolean)
,
toHexString(int, boolean, int)
,
valueOf(java.lang.String)
,
parseRoman(java.lang.String, int, int)
,
parseAbbreviation(java.lang.String, int, int,
java.lang.String)
public static final java.lang.String toRomanString(int value, boolean upperCase, int minLength)
ROMAN_DIGITS
built-in constant string
(the digits are ordered by their weight in it).
value
- the signed value to be converted.upperCase
- true
if and only if (digit) characters in the result
are in the upper case.minLength
- the minimal length of the result (absolute value).
null
, with
length()
not less than
max(abs(minLength), 1)
) of value.
java.lang.OutOfMemoryError
- if there is not enough memory.ROMAN_DIGITS
,
parseRoman(java.lang.String, int, int)
,
toString(int, boolean, boolean, int, boolean, int)
,
toString(int, boolean)
,
toAbbreviation(int, java.lang.String)
public static final int parseRoman(java.lang.String str, int beginIndex, int endIndex) throws java.lang.NullPointerException, java.lang.StringIndexOutOfBoundsException, ParserException
ROMAN_DIGITS
). The
order checking for the digits (in the string region) is relaxed
here. But number overflow is checked properly
(ParserException
is thrown if overflow occurs).
str
- the string (must be non-null
), which region to
parse.beginIndex
- the string region beginning index (must be in the range),
inclusive.endIndex
- the string region ending index (must be in the range), exclusive.
java.lang.NullPointerException
- if str is null
.
java.lang.StringIndexOutOfBoundsException
- if beginIndex is negative, or if endIndex
is less than beginIndex or is greater than
length()
of str.
ParserException
- if str region cannot be parsed as an integer value in
the Roman notation (error is set to 1
,
2
or 3
in the exception, meaning an
illegal character is found, number overflow occurs or unexpected
end of region is encountered at index, respectively).ROMAN_DIGITS
,
toRomanString(int, boolean, int)
,
parse(java.lang.String, int, int, boolean, int)
,
decode(java.lang.String, int, int)
,
parseAbbreviation(java.lang.String, int, int,
java.lang.String)
public static final java.lang.String toAbbreviation(int value, java.lang.String paddedAbbrevsList) throws java.lang.NullPointerException
value
- the signed value to be converted.paddedAbbrevsList
- the string (must be non-null
), which specifies
abbreviations list (in the form of concatenation of right-padded
abbreviations ordered by value).
null
,
with non-zero length()
) of value.
java.lang.NullPointerException
- if paddedAbbrevsList is null
.
java.lang.OutOfMemoryError
- if there is not enough memory.toString(int, boolean, boolean, int, boolean, int)
,
toRomanString(int, boolean, int)
,
filledString(char, int)
,
parse(java.lang.String, int, int, boolean, int)
,
decode(java.lang.String, int, int)
,
parseAbbreviation(java.lang.String, int, int,
java.lang.String)
public static final int parseAbbreviation(java.lang.String str, int beginIndex, int endIndex, java.lang.String sortedRefAbbrevsList) throws java.lang.NullPointerException, java.lang.StringIndexOutOfBoundsException, ParserException
toAbbreviation(int, String)
method. Leading spaces are ignored. All abbreviations are
case-insensitive. If the specified string region is recognized as
an abbreviation (specified in sortedRefAbbrevsList)
then its integer value (which stands for it) is returned, else
the string region is tried to be parsed as a signed decimal
integer representation with (or without) the prefix string and
with (or without) the postfix string (specified in
sortedRefAbbrevsList too) - its value is returned on
success, ParserException
is thrown otherwise. As
mentioned, all abbreviations are specified in a single
sortedRefAbbrevsList string which either has the same
format as paddedAbbrevsList for
toAbbreviation(int, String)
method or has the
following preferred format (which allows fast binary search of an
abbreviation). sortedRefAbbrevsList consists of zero
or more 'blocks' concatenated together. All the blocks have the
same some length. The first block is as follows: its first
character denotes the separator character (used to pad/align
abbreviations), the next (zero or more) characters till
(exclusively) the next separator specifies the prefix string for
values without an assigned abbreviation, the following (zero or
more) characters till (exclusively) the next separator specifies
the postfix string (again, for values without an assigned
abbreviation), the next (zero or more) separators are appended to
pad the block. The second block (if present) must contain at the
beginning at least one non-separator character (the offset of
this character is, in fact, the length of each block). Every
block (except for the first one) starts with a single
abbreviation (which the block specifies) followed with one or
more separator characters (to pad the block), and ends with a
non-negative decimal integer number (which stands for the denoted
abbreviation) followed with a single separator character. All the
blocks (except for the first one) are ordered alphabetically
ignoring characters case. Important notes:
sortedRefAbbrevsList string is checked to be of one of
these two described formats, if the format string is bad then the
specified string region is only tried to be parsed as a signed
decimal integer representation.
str
- the string (must be non-null
), which region to
parse.beginIndex
- the string region beginning index (must be in the range),
inclusive.endIndex
- the string region ending index (must be in the range), exclusive.sortedRefAbbrevsList
- the string (must be non-null
), which specifies valid
abbreviations list (in the form of concatenation of right-padded
abbreviations ordered by value or in the form of concatenation of
center-padded abbreviation-value pairs sorted alphabetically
ignoring case).
java.lang.NullPointerException
- if str is null
or
sortedRefAbbrevsList is null
.
java.lang.StringIndexOutOfBoundsException
- if beginIndex is negative, or if endIndex
is less than beginIndex or is greater than
length()
of str.
ParserException
- if str region cannot be parsed as one among the
specified abbreviations or as a signed integer (error
is set to 1
, 2
or 3
in the
exception, meaning an unknown abbreviation is encountered, number
overflow occurs or unexpected end of region is encountered at
index, respectively).toAbbreviation(int, java.lang.String)
,
toString(int, boolean, boolean, int, boolean, int)
,
parse(java.lang.String, int, int, boolean, int)
,
decode(java.lang.String, int, int)
,
parseRoman(java.lang.String, int, int)
public static final java.lang.String filledString(char ch, int len)
arraycopy(Object, int, Object, int, int)
method of
System
class is used to fill the content of the
string.
ch
- the character to fill the string with.len
- the length of the string which is created and filled.
null
, with
length()
equal to max(len, 0)
).
java.lang.OutOfMemoryError
- if there is not enough memory.toString(int, boolean)
,
toBinaryString(int, int)
,
toOctalString(int, int)
,
toHexString(int, boolean, int)
,
toAbbreviation(int, java.lang.String)
public static UnsignedInt valueOf(java.lang.String str) throws java.lang.NullPointerException, ParserException
UnsignedInt
object
initialized to the unsigned decimal integer value of the
specified string.
str
- the string (must be non-null
, representing a valid
unsigned decimal integer) to be parsed.
UnsignedInt
instance (not
null
) initialized to the value represented by
str.
java.lang.NullPointerException
- if str is null
.
ParserException
- if str cannot be parsed as an unsigned integer
(error is set to 1
, 2
or
3
in the exception, meaning an illegal character is
found, number overflow occurs or unexpected end of string is
encountered at index, respectively).
java.lang.OutOfMemoryError
- if there is not enough memory.UnsignedInt(int)
,
parse(java.lang.String, int, int, boolean, int)
,
decode(java.lang.String, int, int)
,
intValue()
,
toString()
public int intValue()
this
number as
int
.
intValue
in class java.lang.Number
int
value represented by the object.UnsignedInt(int)
,
longValue()
,
floatValue()
,
doubleValue()
,
toString()
public long longValue()
this
number as
long
.
The result is the same as of
(intValue() & JavaConsts INT_LMASK)
.
longValue
in class java.lang.Number
long
value represented by the object.UnsignedInt(int)
,
intValue()
,
floatValue()
,
doubleValue()
,
toString()
public float floatValue()
this
number as
float
.
The result is the same as of (float)doubleValue()
.
Important notes: this may involve rounding; the result is always
non-negative.
floatValue
in class java.lang.Number
float
value represented by the object.UnsignedInt(int)
,
intValue()
,
longValue()
,
doubleValue()
,
toString()
public double doubleValue()
this
number as
double
.
Important notes: the result is always non-negative.
doubleValue
in class java.lang.Number
double
value represented by the object.UnsignedInt(int)
,
intValue()
,
longValue()
,
floatValue()
,
toString()
public java.lang.Object clone()
this
object.
The result is the same as of
new UnsignedInt(intValue())
.
clone
in interface ReallyCloneable
clone
in class java.lang.Object
null
and != this
) of
this
instance.
java.lang.OutOfMemoryError
- if there is not enough memory.UnsignedInt(int)
,
valueOf(java.lang.String)
,
intValue()
,
equals(java.lang.Object)
public int hashCode()
int
value represented by this object.
hashCode
in class java.lang.Object
this
object.intValue()
,
equals(java.lang.Object)
public boolean equals(java.lang.Object obj)
this
object is equal to the
specified one.
This method returns true
if and only if
obj is instance of this
class, and the
wrapped values of this
and of obj are
equal.
equals
in class java.lang.Object
obj
- the second compared object (may be null
).
true
if and only if this
value is the
same as obj value.compare(int, int)
,
intValue()
,
hashCode()
,
greaterThan(java.lang.Object)
public boolean greaterThan(java.lang.Object obj)
true
if and only if obj is
instance of this
class and the wrapped value of
this
object is greater (in the unsigned manner) than
the wrapped value of the specified object.
greaterThan
in interface Sortable
obj
- the second compared object (may be null
).
true
if obj is comparable with
this
and this
object is greater than
obj, else false
.greater(int, int)
,
compare(int, int)
,
intValue()
,
equals(java.lang.Object)
public java.lang.String toString()
this
object to its 'in-line' string
representation.
The wrapped value is converted to its unsigned decimal
representation and returned as a string, exactly as by
toString(intValue(), true)
.
toString
in class java.lang.Object
null
, with non-zero
length()
) of this
object.
java.lang.OutOfMemoryError
- if there is not enough memory.UnsignedInt(int)
,
intValue()
,
toString(int, boolean)
,
toString(int, boolean, boolean, int, boolean, int)
,
toAbbreviation(int, java.lang.String)
,
valueOf(java.lang.String)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |