org.at4j.support.lang
Class UnsignedLong

java.lang.Object
  extended by org.at4j.support.lang.UnsignedLong
All Implemented Interfaces:
Serializable, Comparable<UnsignedLong>

public final class UnsignedLong
extends Object
implements Serializable, Comparable<UnsignedLong>

This object represents an unsigned long (eight bytes or 64 bits) with a value between {code 0} and 18446744073709551615. It is immutable.

Unsigned longs are created by calling any of the static creation methods of this class.

Since:
1.0
Author:
Karl Gustafsson
See Also:
SignedLong, UnsignedByte, UnsignedShort, UnsignedInteger, Serialized Form

Field Summary
static BigInteger MAX_VALUE
          The maximum allowed value (18446744073709551615).
static BigInteger MIN_VALUE
          The minimum allowed value (0).
static UnsignedLong ONE
          The value one.
static UnsignedLong ZERO
          The value zero.
 
Method Summary
 BigInteger bigIntValue()
          Get the unsigned long value as a BigInteger.
 int compareTo(UnsignedLong l2)
           
 boolean equals(Object o)
           
static UnsignedLong fromBigEndianByteArray(byte[] barr)
          Create an unsigned long value from a eight bytes long, big-endian byte array.
static UnsignedLong fromBigEndianByteArray(byte[] barr, int offset)
          Create an unsigned long value from eight bytes read from the given offset position in the supplied byte array.
 byte[] getBigEndianByteArray()
          Get the unsigned long value as a big-endian, eight bytes long byte array.
 int hashCode()
           
 long longValue()
          Return the value as a signed long.
static UnsignedLong readBigEndian(InputStream is)
          Create an unsigned long value from eight bytes read from the stream.
static UnsignedLong readBigEndian(RandomAccess ra)
          Create an unsigned long value from eight bytes read starting from the current position in the supplied RandomAccess.
 String toString()
           
static UnsignedLong valueOf(BigInteger value)
          Create an unsigned long value from the supplied BigInteger value which must be in the range 0 to 18446744073709551615 (inclusive)
static UnsignedLong valueOf(long value)
          Create an unsigned long.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_VALUE

public static final BigInteger MIN_VALUE
The minimum allowed value (0).


MAX_VALUE

public static final BigInteger MAX_VALUE
The maximum allowed value (18446744073709551615).


ZERO

public static final UnsignedLong ZERO
The value zero.


ONE

public static final UnsignedLong ONE
The value one.

Method Detail

valueOf

public static UnsignedLong valueOf(long value)
Create an unsigned long. The supplied value is treated as an unsigned long, which means that negative argument values will result in unsigned long values between 9223372036854775808 and 18446744073709551615 (inclusive).

Parameters:
value - The value.
Returns:
An unsigned long value.

valueOf

public static UnsignedLong valueOf(BigInteger value)
                            throws IllegalArgumentException
Create an unsigned long value from the supplied BigInteger value which must be in the range 0 to 18446744073709551615 (inclusive)

Parameters:
value - The value.
Returns:
An unsigned long value.
Throws:
IllegalArgumentException - If the supplied value is negative or if it is greater than MAX_VALUE.

bigIntValue

public BigInteger bigIntValue()
Get the unsigned long value as a BigInteger.

Returns:
The unsigned long value as a BigInteger.

longValue

public long longValue()
Return the value as a signed long. If the value is less than Long.MAX_VALUE, it is returned as a positive long. If not, it is returned as a negative long.

Returns:
The value as a signed long value.

getBigEndianByteArray

public byte[] getBigEndianByteArray()
Get the unsigned long value as a big-endian, eight bytes long byte array.

Returns:
The value represented as a big-endian byte array.

fromBigEndianByteArray

public static UnsignedLong fromBigEndianByteArray(byte[] barr)
                                           throws IllegalArgumentException
Create an unsigned long value from a eight bytes long, big-endian byte array.

Parameters:
barr - The byte array. It must be eight bytes long.
Returns:
The unsigned long.
Throws:
IllegalArgumentException - If the supplied byte array is not eight bytes long.
See Also:
fromBigEndianByteArray(byte[], int)

fromBigEndianByteArray

public static UnsignedLong fromBigEndianByteArray(byte[] barr,
                                                  int offset)
                                           throws ArrayIndexOutOfBoundsException
Create an unsigned long value from eight bytes read from the given offset position in the supplied byte array. The most significant byte is the last byte read.

Parameters:
barr - The byte array to read from.
offset - The offset in the byte array where the least significant (first) byte is.
Returns:
An unsigned long.
Throws:
ArrayIndexOutOfBoundsException - If the supplied array is too short or if the offset is negative.
See Also:
fromBigEndianByteArray(byte[])

readBigEndian

public static UnsignedLong readBigEndian(RandomAccess ra)
                                  throws UnexpectedEofException,
                                         WrappedIOException
Create an unsigned long value from eight bytes read starting from the current position in the supplied RandomAccess. The most significant byte is the last byte read.

Parameters:
ra - The RandomAccess to read from. The current position is advanced eight positions by this method.
Returns:
An unsigned long.
Throws:
UnexpectedEofException - If the end of the file is reached before eight bytes have been read.
WrappedIOException - On I/O errors.

readBigEndian

public static UnsignedLong readBigEndian(InputStream is)
                                  throws UnexpectedEofException,
                                         WrappedIOException
Create an unsigned long value from eight bytes read from the stream. The most significant byte is the last byte read.

Parameters:
is - The stream to read from.
Returns:
An unsigned long.
Throws:
UnexpectedEofException - If the end of the stream is reached before eight bytes have been read.
WrappedIOException - On I/O errors.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(UnsignedLong l2)
Specified by:
compareTo in interface Comparable<UnsignedLong>

toString

public String toString()
Overrides:
toString in class Object