org.at4j.support.lang
Class UnsignedByte

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

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

This object represents an unsigned byte (eight bits) with a value between 0 and 255 (inclusive). It is immutable.

Unsigned byte instances are created by calling any of the static valueOf methods on this class.

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

Field Summary
static short MAX_VALUE
          The maximum value of an unsigned byte (255).
static short MIN_VALUE
          The minimum value of an unsigned byte (0).
static UnsignedByte ONE
          The value 1.
static UnsignedByte ZERO
          The value 0.
 
Method Summary
 byte byteValue()
          Get the unsigned byte value as a signed byte value between -128 and 127 (inclusive).
 int compareTo(UnsignedByte b2)
           
 boolean equals(Object o)
           
 int hashCode()
           
 int intValue()
          Get the unsigned byte value as an int.
 boolean isBitSet(int no)
          Is the specified bit set in the byte value?
static UnsignedByte read(InputStream is)
          Read an unsigned byte value from the supplied InputStream.
static UnsignedByte read(RandomAccess ra)
          Read an unsigned byte value from the supplied RandomAccess.
 short shortValue()
          Get the unsigned byte value as a short.
 String toString()
           
static UnsignedByte valueOf(byte value)
          Create an unsigned byte value from the supplied byte value.
static UnsignedByte valueOf(int value)
          Create a new unsigned byte value from the supplied int value which must be in the range 0 to 255 (inclusive).
static UnsignedByte valueOf(short value)
          Create a new unsigned byte value from the supplied short value which must be in the range 0 to 255 (inclusive).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_VALUE

public static final short MAX_VALUE
The maximum value of an unsigned byte (255).

See Also:
Constant Field Values

MIN_VALUE

public static final short MIN_VALUE
The minimum value of an unsigned byte (0).

See Also:
Constant Field Values

ZERO

public static final UnsignedByte ZERO
The value 0.


ONE

public static final UnsignedByte ONE
The value 1.

Method Detail

valueOf

public static UnsignedByte valueOf(byte value)
Create an unsigned byte value from the supplied byte value. The supplied value is treated as if it was unsigned, which means that negative argument values will result in unsigned byte values between 128 and 255.

Parameters:
value - The value.
Returns:
The unsigned byte value.
See Also:
valueOf(short), valueOf(int)

valueOf

public static UnsignedByte valueOf(short value)
                            throws IllegalArgumentException
Create a new unsigned byte value from the supplied short value which must be in the range 0 to 255 (inclusive).

Parameters:
value - The value.
Returns:
An unsigned byte value.
Throws:
IllegalArgumentException - If the supplied value is not in the permitted range.

valueOf

public static UnsignedByte valueOf(int value)
                            throws IllegalArgumentException
Create a new unsigned byte value from the supplied int value which must be in the range 0 to 255 (inclusive).

Parameters:
value - The value.
Returns:
An unsigned byte value.
Throws:
IllegalArgumentException - If the supplied value is not in the permitted range.

intValue

public int intValue()
Get the unsigned byte value as an int.

Returns:
The value.

shortValue

public short shortValue()
Get the unsigned byte value as a short.

Returns:
The value.

byteValue

public byte byteValue()
Get the unsigned byte value as a signed byte value between -128 and 127 (inclusive).

Returns:
The value.

isBitSet

public boolean isBitSet(int no)
                 throws IllegalArgumentException
Is the specified bit set in the byte value?

Parameters:
no - The index number of the bit. Bit 0 is the bit representing the value 1, bit 7 is the bit representing the value 128.
Returns:
true if the specified bit is set.
Throws:
IllegalArgumentException - If no is not in the range 0 <= no <= 7 (inclusive).

read

public static UnsignedByte read(RandomAccess ra)
                         throws UnexpectedEofException,
                                WrappedIOException
Read an unsigned byte value from the supplied RandomAccess. The file pointer is advanced one position by this method.

Parameters:
ra - The RandomAccess object to read from.
Returns:
An unsigned byte read from the file.
Throws:
UnexpectedEofException - If the file pointer is at the end of the file.
WrappedIOException - On I/O errors.

read

public static UnsignedByte read(InputStream is)
                         throws UnexpectedEofException,
                                WrappedIOException
Read an unsigned byte value from the supplied InputStream.

Parameters:
is - The stream to read from.
Returns:
An unsigned byte read from the stream.
Throws:
UnexpectedEofException - If no more data could be read from the stream.
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(UnsignedByte b2)
Specified by:
compareTo in interface Comparable<UnsignedByte>

toString

public String toString()
Overrides:
toString in class Object