net.sf.ivmaidns.util
Class UnsignedInt

java.lang.Object
  extended by java.lang.Number
      extended by net.sf.ivmaidns.util.UnsignedInt
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Immutable, ReallyCloneable, Sortable

public final class UnsignedInt
extends java.lang.Number
implements Immutable, ReallyCloneable, Sortable

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).

Version:
2.0
Author:
Ivan Maidanski
See Also:
UnsignedLong, IntVector, ByteVector, PseudoRandom, JavaConsts, Serialized Form

Field 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

ROMAN_DIGITS

public static final java.lang.String ROMAN_DIGITS
The Roman digits string specifier. This constant string (not 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).

Since:
2.0
See Also:
toRomanString(int, boolean, int), parseRoman(java.lang.String, int, int), Constant Field Values

unsignedValue

protected int unsignedValue
The wrapped (encapsulated) unsigned int value. Important notes: this value is constant.

See Also:
UnsignedInt(int), valueOf(java.lang.String), clone(), hashCode(), intValue(), longValue(), floatValue(), doubleValue(), equals(java.lang.Object), greaterThan(java.lang.Object), toString()
Constructor Detail

UnsignedInt

public UnsignedInt(int unsignedValue)
Constructs a new object that represents the specified primitive unsigned int value.

Parameters:
unsignedValue - the unsigned value to be wrapped.
See Also:
valueOf(java.lang.String), clone(), intValue(), longValue(), equals(java.lang.Object), greaterThan(java.lang.Object), toString()
Method Detail

greater

public static final boolean greater(int unsignedA,
                                    int unsignedB)
Tests whether the first specified unsigned integer is greater than the second one.

Parameters:
unsignedA - the first compared unsigned value.
unsignedB - the second compared unsigned value.
Returns:
true if and only if unsignedA is greater than unsignedB (in the unsigned manner).
See Also:
greaterOrEqual(int, int), compare(int, int), min(int, int), max(int, int), median(int, int, int), greaterThan(java.lang.Object)

greaterOrEqual

public static final boolean greaterOrEqual(int unsignedA,
                                           int unsignedB)
Tests whether the first specified unsigned integer is greater or equal to the second one.

Parameters:
unsignedA - the first compared unsigned value.
unsignedB - the second compared unsigned value.
Returns:
true if and only if unsignedA is not less than unsignedB (in the unsigned manner).
See Also:
greater(int, int), compare(int, int), min(int, int), max(int, int), median(int, int, int), equals(java.lang.Object), greaterThan(java.lang.Object)

compare

public static final int compare(int unsignedA,
                                int unsignedB)
Compares two given unsigned integer values. This method returns a signed integer indicating 'less-equal-greater' relation between the specified int values.

Parameters:
unsignedA - the first compared unsigned value.
unsignedB - the second compared unsigned value.
Returns:
a negative integer, zero, or a positive integer as valueA is less than, equal to, or greater than valueB (in the unsigned manner).
See Also:
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)

signedCompare

public static final int signedCompare(int valueA,
                                      int valueB)
Compares two given (signed) integer values. This method returns a signed integer indicating 'less-equal-greater' relation between the specified int values.

Parameters:
valueA - the first compared (signed) value.
valueB - the second compared (signed) value.
Returns:
a negative integer, zero, or a positive integer as valueA is less than, equal to, or greater than valueB.
Since:
2.0
See Also:
compare(int, int), signedMedian(int, int, int)

min

public static final int min(int unsignedA,
                            int unsignedB)
Returns the minimum of two given unsigned integer values.

Parameters:
unsignedA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
unsignedA if unsignedA is less (in the unsigned manner) than unsignedB, else unsignedB.
See Also:
max(int, int), median(int, int, int), greater(int, int), greaterOrEqual(int, int), compare(int, int)

max

public static final int max(int unsignedA,
                            int unsignedB)
Returns the maximum of two given unsigned integer values.

Parameters:
unsignedA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
unsignedA if unsignedA is greater (in the unsigned manner) than unsignedB, else unsignedB.
See Also:
min(int, int), median(int, int, int), greater(int, int), greaterOrEqual(int, int), compare(int, int)

median

public static final int median(int unsignedA,
                               int unsignedB,
                               int unsignedC)
Returns the 'median' (middle value) of three given unsigned integer values.

Parameters:
unsignedA - the first unsigned value.
unsignedB - the second unsigned value.
unsignedC - the third unsigned value.
Returns:
unsignedA, unsignedB or unsignedC according to which one of these values is between (in the unsigned manner) the other values.
Since:
1.1
See Also:
signedMedian(int, int, int), min(int, int), max(int, int), greater(int, int), greaterOrEqual(int, int), compare(int, int)

signedMedian

public static final int signedMedian(int valueA,
                                     int valueB,
                                     int valueC)
Returns the 'median' (middle value) of three given (signed) integer values.

Parameters:
valueA - the first (signed) value.
valueB - the second (signed) value.
valueC - the third (signed) value.
Returns:
valueA, valueB or valueC according to which one of these values is between the other values.
Since:
1.1
See Also:
median(int, int, int), signedCompare(int, int)

mulHigh

public static final int mulHigh(int unsignedA,
                                int unsignedB)
Returns the highest half of 'long' (full) product of two given unsigned integers.

Parameters:
unsignedA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the (unsigned) top half of unsignedA multiplied by unsignedB.
See Also:
divHigh(int, int, int), mulLow(int, int), mul(int, int), mulDiv(int, int, int, boolean), mulMod(int, int, int), power(int, int), factorial(int)

mulLow

public static final int mulLow(int unsignedA,
                               int unsignedB)
Returns the lowest half of 'long' (full) product of two given unsigned integers.

Parameters:
unsignedA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the (unsigned) bottom half of unsignedA multiplied by unsignedB.
See Also:
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)

mul

public static final long mul(int unsignedA,
                             int unsignedB)
Returns the product of two given unsigned int values extended to long type.

Parameters:
unsignedA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the unsigned long result of unsignedA multiplied by unsignedB.
See Also:
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)

div

public static final int div(int unsignedA,
                            int unsignedB)
                     throws java.lang.ArithmeticException
Returns the result of integer division of one given unsigned value by another one.

Parameters:
unsignedA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the unsigned result of unsignedA divided by unsignedB.
Throws:
java.lang.ArithmeticException - if unsignedB is 0.
See Also:
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)

div

public static final long div(long unsignedLongA,
                             int unsignedB)
                      throws java.lang.ArithmeticException
Returns the result of integer division of one given unsigned long value by another unsigned int value.

Parameters:
unsignedLongA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the unsigned result of unsignedLongA divided by unsignedB.
Throws:
java.lang.ArithmeticException - if unsignedB is 0.
Since:
1.1
See Also:
div(int, int), mul(int, int), rem(long, int), divHigh(long, int), divLow(long, int)

divHigh

public static final int divHigh(int unsignedHighA,
                                int unsignedLowA,
                                int unsignedB)
                         throws java.lang.ArithmeticException
Returns the highest half of the result of integer division of join of two given halves of unsigned value by another one. The result is the same as of div(unsignedHighA, unsignedB).

Parameters:
unsignedHighA - the top half of the first unsigned value.
unsignedLowA - the bottom half of the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the top half of the unsigned result of joined unsignedHighA:unsignedLowA divided by unsignedB.
Throws:
java.lang.ArithmeticException - if unsignedB is 0.
See Also:
divLow(int, int, int), mulHigh(int, int), mulLow(int, int), div(int, int), div(long, int), divHigh(long, int), mulDiv(int, int, int, boolean)

divHigh

public static final int divHigh(long unsignedLongA,
                                int unsignedB)
                         throws java.lang.ArithmeticException
Returns the highest half of the result of integer division of one given unsigned long value by another unsigned int value.

Parameters:
unsignedLongA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the top half of the unsigned result of unsignedLongA divided by unsignedB.
Throws:
java.lang.ArithmeticException - if unsignedB is 0.
Since:
1.1
See Also:
divHigh(int, int, int), divLow(long, int), mul(int, int), div(long, int), rem(long, int)

divLow

public static final int divLow(int unsignedHighA,
                               int unsignedLowA,
                               int unsignedB)
                        throws java.lang.ArithmeticException
Returns the lowest half of the result of integer division of join of two given halves of unsigned value by another one.

Parameters:
unsignedHighA - the top half of the first unsigned value.
unsignedLowA - the bottom half of the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the bottom half of the unsigned result of joined unsignedHighA:unsignedLowA divided by unsignedB.
Throws:
java.lang.ArithmeticException - if unsignedB is 0.
See Also:
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)

divLow

public static final int divLow(long unsignedLongA,
                               int unsignedB)
                        throws java.lang.ArithmeticException
Returns the lowest half of the result of integer division of one given unsigned long value by another unsigned int value. The result is the same as of (int)div(unsignedLongA, unsignedB).

Parameters:
unsignedLongA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the bottom half of the unsigned result of unsignedLongA divided by unsignedB.
Throws:
java.lang.ArithmeticException - if unsignedB is 0.
Since:
1.1
See Also:
divLow(int, int, int), divHigh(long, int), mul(int, int), div(long, int), rem(long, int)

rem

public static final int rem(int unsignedA,
                            int unsignedB)
                     throws java.lang.ArithmeticException
Returns the remainder of integer division of one given unsigned value by another one. The result is the same as of (unsignedA - div(unsignedA, unsignedB) * unsignedB).

Parameters:
unsignedA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the unsigned remainder when unsignedA is divided by unsignedB.
Throws:
java.lang.ArithmeticException - if unsignedB is 0.
See Also:
mulLow(int, int), div(int, int), rem(long, int), remLow(int, int, int), inverseMod(int, int)

rem

public static final int rem(long unsignedLongA,
                            int unsignedB)
                     throws java.lang.ArithmeticException
Returns the remainder of integer division of one given unsigned long value by another unsigned int value.

Parameters:
unsignedLongA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the unsigned remainder when unsignedLongA is divided by unsignedB.
Throws:
java.lang.ArithmeticException - if unsignedB is 0.
Since:
1.1
See Also:
rem(int, int), remLow(int, int, int), mul(int, int), div(long, int)

remLow

public static final int remLow(int unsignedHighA,
                               int unsignedLowA,
                               int unsignedB)
                        throws java.lang.ArithmeticException
Returns the remainder of integer division of join of two given halves of unsigned value by another one.

Parameters:
unsignedHighA - the top half of the first unsigned value.
unsignedLowA - the bottom half of the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the unsigned remainder when joined unsignedHighA:unsignedLowA is divided by unsignedB.
Throws:
java.lang.ArithmeticException - if unsignedB is 0.
See Also:
rem(int, int), rem(long, int), divLow(int, int, int), mulHigh(int, int), mulLow(int, int), mulMod(int, int, int)

power

public static final int power(int value,
                              int degree)
Returns a given value involved to the power of the specified degree. Overflow is not checked. If degree is negative then 0 is returned. Important notes: value may be signed or unsigned.

Parameters:
value - the signed/unsigned value to be involved to the power.
degree - the degree of the power.
Returns:
the signed/unsigned result of involving value to the power of degree.
Since:
1.1
See Also:
mulLow(int, int), binLog(int), factorial(int)

binLog

public static final int binLog(int unsignedValue)
Returns the integer part of binary logarithm of a given unsigned value. If unsignedValue is zero then -1 is returned, else the result is in the range from 0 to (JavaConsts INT_SIZE - 1), inclusive.

Parameters:
unsignedValue - the unsigned argument of the logarithm.
Returns:
the result of logarithm computation for unsignedValue.
Since:
1.2
See Also:
power(int, int), factorial(int)

factorial

public static final int factorial(int value)
Computes the factorial of a given value. Overflow is not checked. If value is negative or zero then 0 is returned.

Parameters:
value - the factorial argument.
Returns:
the unsigned result of the factorial computation for value.
Since:
1.1
See Also:
mulLow(int, int), power(int, int), binLog(int)

gcd

public static final int gcd(int unsignedA,
                            int unsignedB)
Computes the greatest 'common divisor' (gcd) of two given unsigned non-zero values. Important notes: zero value (for any argument or result) is treated as the largest unsigned int value plus one.

Parameters:
unsignedA - the first unsigned value.
unsignedB - the second unsigned value.
Returns:
the unsigned greatest common divisor of both unsignedA and unsignedB.
Since:
1.1
See Also:
inverseMod(int, int), mulMod(int, int, int), mulDiv(int, int, int, boolean), binLog(int)

inverseMod

public static final int inverseMod(int unsignedA,
                                   int unsignedMax)
Computes the modular 'inversion' of a given unsigned value. It is the inverse operation for modular multiplication. That is, if both unsignedA and unsignedMax are non-zero and 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.

Parameters:
unsignedA - the unsigned value to inverse.
unsignedMax - the unsigned maximum for modular multiplication.
Returns:
the unsigned result (not zero) of modular inversion of unsignedA with respect to unsignedMax.
Since:
1.1
See Also:
mulMod(int, int, int), gcd(int, int), div(int, int), rem(int, int)

mulMod

public static final int mulMod(int unsignedA,
                               int unsignedB,
                               int unsignedMax)
Computes the modular 'multiplication' of two given unsigned values. This method returns the remainder of the result of integer division of 'long' (full) product of unsignedA and unsignedB by (unsignedMax plus one). The result is in the range from 0 to unsignedMax, inclusive.

Parameters:
unsignedA - the first unsigned value to multiply.
unsignedB - the second unsigned value to multiply.
unsignedMax - the unsigned maximum value for the result to have.
Returns:
the unsigned result of modular multiplication of unsignedA and unsignedB with respect to unsignedMax.
Since:
1.1
See Also:
inverseMod(int, int), gcd(int, int), mulDiv(int, int, int, boolean), mulHigh(int, int), remLow(int, int, int)

mulDiv

public static final 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. Important notes: zero value (for any argument) is treated as the largest unsigned int value plus one.

Parameters:
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.
Returns:
the bottom half of the unsigned result of unsignedA multiplied by unsignedB and divided by unsignedC.
See Also:
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)

putToByteArray

public static final void putToByteArray(byte[] bytes,
                                        int offset,
                                        int unsignedValue,
                                        int len)
                                 throws java.lang.NullPointerException,
                                        java.lang.ArrayIndexOutOfBoundsException
Puts a given value into the specified byte array. This method splits unsignedValue to separate bytes and puts them into bytes array sequentially (the last put byte is the lowest of unsignedValue), starting at offset. Negative len is treated as zero. If an exception is thrown then bytes remains changed. Else bytes content is altered. Important notes: if len is greater than JavaConsts INT_LENGTH then unsignedValue is zero-extended.

Parameters:
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.
Throws:
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).
Since:
1.1
See Also:
toByteArray(int, int), getFromByteArray(byte[], int, int), putToIntelArray(byte[], int, int, int), writeBits(java.io.OutputStream, int, int)

toByteArray

public static final byte[] toByteArray(int unsignedValue,
                                       int len)
Converts a given value into a byte array. This method splits unsignedValue to separate bytes and sequentially puts them into a newly created byte array (the last put byte is the lowest of unsignedValue) of len length. Negative len is treated as zero. Important notes: if len is greater than JavaConsts INT_LENGTH then unsignedValue is zero-extended.

Parameters:
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).
Returns:
a newly created byte array (not null, with length the same as non-negative len), containing the bytes of unsignedValue.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
Since:
1.1
See Also:
putToByteArray(byte[], int, int, int), getFromByteArray(byte[], int, int), toIntelArray(int, int), writeBits(java.io.OutputStream, int, int)

getFromByteArray

public static final int getFromByteArray(byte[] bytes,
                                         int offset,
                                         int len)
                                  throws java.lang.NullPointerException,
                                         java.lang.ArrayIndexOutOfBoundsException
Converts the specified region of a given byte array into an unsigned value. This method gets the elements of bytes array sequentially starting at offset and joins them into an unsigned value (the last got byte is the lowest of the result). Negative len is treated as zero. bytes content is not modified.

Parameters:
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.
Returns:
an unsigned value, containing the got bytes (in its lowest part).
Throws:
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).
Since:
1.1
See Also:
putToByteArray(byte[], int, int, int), toByteArray(int, int), getFromIntelArray(byte[], int, int), readBits(java.io.InputStream, int)

putToIntelArray

public static final void putToIntelArray(byte[] bytes,
                                         int offset,
                                         int unsignedValue,
                                         int len)
                                  throws java.lang.NullPointerException,
                                         java.lang.ArrayIndexOutOfBoundsException
Puts a given value into the specified byte array in the reversed order. This method splits unsignedValue to separate bytes and puts them into bytes array sequentially but in the reversed ('Intel') order (the first put byte is the lowest of unsignedValue), starting at offset (and moving forward). Negative len is treated as zero. If an exception is thrown then bytes remains changed. Else bytes content is altered. Important notes: if len is greater than JavaConsts INT_LENGTH then unsignedValue is zero-extended.

Parameters:
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.
Throws:
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).
Since:
2.0
See Also:
toIntelArray(int, int), getFromIntelArray(byte[], int, int), putToByteArray(byte[], int, int, int)

toIntelArray

public static final byte[] toIntelArray(int unsignedValue,
                                        int len)
Converts a given value in the reversed order into a byte array. This method splits unsignedValue to separate bytes and sequentially puts them into a newly created byte array but in the reversed ('Intel') order (the first put byte is the lowest of unsignedValue) of len length. Negative len is treated as zero. Important notes: if len is greater than JavaConsts INT_LENGTH then unsignedValue is zero-extended.

Parameters:
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).
Returns:
a newly created byte array (not null, with length the same as non-negative len), containing the bytes of unsignedValue.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
Since:
2.0
See Also:
putToIntelArray(byte[], int, int, int), getFromIntelArray(byte[], int, int), toByteArray(int, int)

getFromIntelArray

public static final int getFromIntelArray(byte[] bytes,
                                          int offset,
                                          int len)
                                   throws java.lang.NullPointerException,
                                          java.lang.ArrayIndexOutOfBoundsException
Converts the specified region of a given byte array into an unsigned value in the reversed order. This method gets the elements of bytes array sequentially but in the reversed ('Intel') order, starting at offset (and moving forward) and joins them into an unsigned value (the first got byte is the lowest of the result). Negative len is treated as zero. bytes content is not modified.

Parameters:
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.
Returns:
an unsigned value, containing the got bytes (in its lowest part).
Throws:
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).
Since:
2.0
See Also:
putToIntelArray(byte[], int, int, int), toIntelArray(int, int), getFromByteArray(byte[], int, int)

writeBits

public static final void writeBits(java.io.OutputStream out,
                                   int unsignedValue,
                                   int count)
                            throws java.lang.NullPointerException,
                                   java.io.IOException
Writes a group of bits to a given output stream. Negative count is treated as zero. Important notes: if count is greater than 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.

Parameters:
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.
Throws:
java.lang.NullPointerException - if out is null.
java.io.IOException - if an I/O error occurs.
Since:
1.1
See Also:
readBits(java.io.InputStream, int), readByte(java.io.InputStream)

readBits

public static final int readBits(java.io.InputStream in,
                                 int count)
                          throws java.lang.NullPointerException,
                                 java.io.IOException
Reads a group of bits from a given input stream. Negative count is treated as zero. If the end-of-stream is detected then 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.

Parameters:
in - the stream (must be non-null) to read from.
count - the amount of bits to be read.
Returns:
an unsigned value, containing read bits (in its lowest part, the highest part of the result is set to zero if count is less than JavaConsts INT_SIZE).
Throws:
java.lang.NullPointerException - if in is null.
java.io.IOException - if the end-of-stream has been reached or an I/O error occurs.
Since:
1.1
See Also:
writeBits(java.io.OutputStream, int, int), readByte(java.io.InputStream)

readByte

public static final int readByte(java.io.InputStream in)
                          throws java.lang.NullPointerException,
                                 java.io.IOException
Reads one input byte as an unsigned value. If the end-of-stream is detected then EOFException (subclass of IOException) is thrown.

Parameters:
in - the stream (must be non-null) to read from.
Returns:
an unsigned value read from the stream in the range from 0 to JavaConsts BYTE_MASK, inclusive.
Throws:
java.lang.NullPointerException - if in is null.
java.io.IOException - if the end-of-stream has been reached or an I/O error occurs.
See Also:
writeBits(java.io.OutputStream, int, int), readBits(java.io.InputStream, int)

toString

public static final 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. value is unsigned only if isUnsigned and not forceSign. If forceSign then result always has a sign (if isUnsigned then the positive sign is space else '+' character) else result has a sign ('-' character) if value is negative. The result is left-padded with spaces (before the sign prefix) if minLength is negative else with '0' characters (after the sign prefix). The absolute value of minLength specifies the minimal length of the result (anyhow, the result contains at least one digit). The full digits character set is '0' through '9', 'A' through 'Z' and 'a' through 'z'. If the specified radix is invalid (less than two or too big) then it is corrected to the nearest valid one.

Parameters:
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).
Returns:
the string representation (not null, with length() not less than max(abs(minLength), 1)) of value in the specified radix.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
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)

toString

public static final java.lang.String toString(int value,
                                              boolean isUnsigned)
Converts a given signed/unsigned value into its decimal string representation.

Parameters:
value - the signed/unsigned value to be converted.
isUnsigned - true if value must be treated as an unsigned value, else value is signed.
Returns:
the string representation (not null, with non-zero length()) of value in the decimal radix.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
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)

toBinaryString

public static final java.lang.String toBinaryString(int unsignedValue,
                                                    int minLength)
Converts a given unsigned value into its binary string representation. The result is left-padded with spaces if minLength is negative else with '0' characters. The absolute value of minLength specifies the minimal length of the result (anyhow, the result contains at least one digit).

Parameters:
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).
Returns:
the string representation (not null, with length() not less than max(abs(minLength), 1)) of unsignedValue in the binary radix.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
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)

toOctalString

public static final java.lang.String toOctalString(int unsignedValue,
                                                   int minLength)
Converts a given unsigned value into its octal string representation. The result is left-padded with spaces if minLength is negative else with '0' characters. The absolute value of minLength specifies the minimal length of the result (anyhow, the result contains at least one digit).

Parameters:
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).
Returns:
the string representation (not null, with length() not less than max(abs(minLength), 1)) of unsignedValue in the octal radix.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
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)

toHexString

public static final java.lang.String toHexString(int unsignedValue,
                                                 boolean upperCase,
                                                 int minLength)
Converts a given unsigned value into its hexadecimal string representation. The result is left-padded with spaces if minLength is negative else with '0' characters. The absolute value of minLength specifies the minimal length of the result (anyhow, the result contains at least one digit).

Parameters:
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).
Returns:
the string representation (not null, with length() not less than max(abs(minLength), 1)) of unsignedValue in the hexadecimal radix.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
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)

parse

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
Parses a given string region as a signed/unsigned integer in the specified radix. Leading spaces (before the sign prefix) are ignored. Sign prefix ('+' or '-') is permitted only if not isUnsigned. Any leading '0' characters (after the sign prefix or leading spaces) are ignored too. The next characters in the string region must all be digits of the specified radix (the full digits character set is '0' through '9', 'A' through 'Z' and 'a' through 'z'). Number overflow is checked properly (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.

Parameters:
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.
Returns:
a signed/unsigned integer value represented by str region.
Throws:
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).
See Also:
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)

decode

public static final int decode(java.lang.String str,
                               int beginIndex,
                               int endIndex)
                        throws java.lang.NullPointerException,
                               java.lang.StringIndexOutOfBoundsException,
                               ParserException
Decodes a given string region as an unsigned octal/decimal/hexadecimal integer value. The following unsigned 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.

Parameters:
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.
Returns:
an unsigned integer value represented by str region.
Throws:
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).
See Also:
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)

toRomanString

public static final java.lang.String toRomanString(int value,
                                                   boolean upperCase,
                                                   int minLength)
Converts a given value into its Roman notation. Zero value is represented as a single "-". If value is negative then "-" is prepended before Roman digits. Spaces are prepended to the result if needed (according to the absolute value of minLength). The list of upper-case Roman digits is specified by ROMAN_DIGITS built-in constant string (the digits are ordered by their weight in it).

Parameters:
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).
Returns:
the Roman string representation (not null, with length() not less than max(abs(minLength), 1)) of value.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
Since:
2.0
See Also:
ROMAN_DIGITS, parseRoman(java.lang.String, int, int), toString(int, boolean, boolean, int, boolean, int), toString(int, boolean), toAbbreviation(int, java.lang.String)

parseRoman

public static final int parseRoman(java.lang.String str,
                                   int beginIndex,
                                   int endIndex)
                            throws java.lang.NullPointerException,
                                   java.lang.StringIndexOutOfBoundsException,
                                   ParserException
Parses a given string region as an integer in the Roman notation. Leading spaces (before a possible sign prefix) are ignored. The permitted sign prefix is only either '+' or '-'. The next characters (if present) in the string region must all be Roman digits (which are specified by 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).

Parameters:
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.
Returns:
a signed integer value represented by str region.
Throws:
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).
Since:
2.0
See Also:
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)

toAbbreviation

public static final java.lang.String toAbbreviation(int value,
                                                    java.lang.String paddedAbbrevsList)
                                             throws java.lang.NullPointerException
Converts a given value into its abbreviation according to the specified packed list of abbreviations. If value has the corresponding string abbreviation (specified in paddedAbbrevsList) then it is returned, else the decimal string representation for value (with '-' sign if negative) concatenated with the prefix and postfix (specified in paddedAbbrevsList too) is returned. As mentioned, all abbreviations are specified in a single paddedAbbrevsList string which consists of zero or more 'blocks' concatenated together. All blocks have the same some length (the blocks are padded on the right to be of the same 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 (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, which ends with the separator and does not start with the separator, specifies a single abbreviation for a non-negative integer equal to block number minus two. Important notes: paddedAbbrevsList string is checked for the described format, but no exception is thrown if the format string is bad (in this case, the ordinary signed decimal integer string representation is returned).

Parameters:
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).
Returns:
an abbreviation string representation (not null, with non-zero length()) of value.
Throws:
java.lang.NullPointerException - if paddedAbbrevsList is null.
java.lang.OutOfMemoryError - if there is not enough memory.
Since:
2.0
See Also:
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)

parseAbbreviation

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
Parses a given string region as an integer value abbreviation according to the specified packed list of abbreviations. This is the opposite to 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.

Parameters:
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).
Returns:
a signed integer value represented by str region.
Throws:
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).
Since:
2.0
See Also:
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)

filledString

public static final java.lang.String filledString(char ch,
                                                  int len)
Constructs and returns a string filled with a given character. The resulting string has the specified length and is entirely filled with the specified character. Negative len is treated as zero. Important notes: arraycopy(Object, int, Object, int, int) method of System class is used to fill the content of the string.

Parameters:
ch - the character to fill the string with.
len - the length of the string which is created and filled.
Returns:
the filled string (not null, with length() equal to max(len, 0)).
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
Since:
2.0
See Also:
toString(int, boolean), toBinaryString(int, int), toOctalString(int, int), toHexString(int, boolean, int), toAbbreviation(int, java.lang.String)

valueOf

public static UnsignedInt valueOf(java.lang.String str)
                           throws java.lang.NullPointerException,
                                  ParserException
Converts a given string to an instance of this class. This method returns a new UnsignedInt object initialized to the unsigned decimal integer value of the specified string.

Parameters:
str - the string (must be non-null, representing a valid unsigned decimal integer) to be parsed.
Returns:
a newly constructed UnsignedInt instance (not null) initialized to the value represented by str.
Throws:
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.
See Also:
UnsignedInt(int), parse(java.lang.String, int, int, boolean, int), decode(java.lang.String, int, int), intValue(), toString()

intValue

public int intValue()
Returns the value of this number as int.

Specified by:
intValue in class java.lang.Number
Returns:
the numeric int value represented by the object.
See Also:
UnsignedInt(int), longValue(), floatValue(), doubleValue(), toString()

longValue

public long longValue()
Returns the value of this number as long. The result is the same as of (intValue() & JavaConsts INT_LMASK).

Specified by:
longValue in class java.lang.Number
Returns:
the numeric long value represented by the object.
See Also:
UnsignedInt(int), intValue(), floatValue(), doubleValue(), toString()

floatValue

public float floatValue()
Returns the value of 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.

Specified by:
floatValue in class java.lang.Number
Returns:
the numeric float value represented by the object.
See Also:
UnsignedInt(int), intValue(), longValue(), doubleValue(), toString()

doubleValue

public double doubleValue()
Returns the value of this number as double. Important notes: the result is always non-negative.

Specified by:
doubleValue in class java.lang.Number
Returns:
the numeric double value represented by the object.
See Also:
UnsignedInt(int), intValue(), longValue(), floatValue(), toString()

clone

public java.lang.Object clone()
Creates and returns a copy of this object. The result is the same as of new UnsignedInt(intValue()).

Specified by:
clone in interface ReallyCloneable
Overrides:
clone in class java.lang.Object
Returns:
a copy (not null and != this) of this instance.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
UnsignedInt(int), valueOf(java.lang.String), intValue(), equals(java.lang.Object)

hashCode

public int hashCode()
Returns a hash code value for the object. The hash code value for this object is equal to the primitive int value represented by this object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.
See Also:
intValue(), equals(java.lang.Object)

equals

public boolean equals(java.lang.Object obj)
Indicates whether 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.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the second compared object (may be null).
Returns:
true if and only if this value is the same as obj value.
See Also:
compare(int, int), intValue(), hashCode(), greaterThan(java.lang.Object)

greaterThan

public boolean greaterThan(java.lang.Object obj)
Tests for being semantically greater than the argument. The result is 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.

Specified by:
greaterThan in interface Sortable
Parameters:
obj - the second compared object (may be null).
Returns:
true if obj is comparable with this and this object is greater than obj, else false.
Since:
2.0
See Also:
greater(int, int), compare(int, int), intValue(), equals(java.lang.Object)

toString

public java.lang.String toString()
Converts 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).

Overrides:
toString in class java.lang.Object
Returns:
the string representation (not null, with non-zero length()) of this object.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
UnsignedInt(int), intValue(), toString(int, boolean), toString(int, boolean, boolean, int, boolean, int), toAbbreviation(int, java.lang.String), valueOf(java.lang.String)