net.sourceforge.juint
Class Int32

java.lang.Object
  extended by java.lang.Number
      extended by net.sourceforge.juint.Int32
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, Bitwise<Int32>

public class Int32
extends java.lang.Number
implements java.io.Serializable, java.lang.Comparable, Bitwise<Int32>

Signed 32-bit integer.

See Also:
Serialized Form

Field Summary
static int MAX_VALUE
          The largest possible value.
static int MIN_VALUE
          The smallest possible value.
 
Constructor Summary
Int32(byte[] doubleWord)
          Creates a new instance from a byte array.
Int32(int doubleWord)
          Creates a new instance from an int.
Int32(long doubleWord)
          Creates a new instance from a long.
Int32(short doubleWord)
          Creates a new instance from a short.
 
Method Summary
 Int32 addBitmask(Int32 bitmask)
          Sets the bits in the given bitmask.
 Int32 and(Int32 number)
          Logical and.
 int compareTo(java.lang.Object object)
          Compares this Int32 to another Int32 for order.
 double doubleValue()
          Gets the value as a double.
 boolean equals(java.lang.Object object)
          Gets the value as a byte array.
 float floatValue()
          Gets the value as a float.
 boolean hasBitmask(Int32 bitmask)
          Determines if this number has the given bitmask.
 int hashCode()
          Gets the hash code.
 int int32Value()
          Gets the value as a signed 32-bit integer.
 int intValue()
          Gets the value as an int.
 long longValue()
          Gets the value as a long.
 Int32 not()
          Logical not.
 Int32 or(Int32 number)
          Logical or.
 Int32 removeBitmask(Int32 bitmask)
          Unsets the bits in the given bitmask.
 byte[] toBigEndian()
          Gets the value as a byte array.
 byte[] toLittleEndian()
          Gets the value as a byte array.
 java.lang.String toString()
          Gets the value as a String.
static Int32 valueOfBigEndian(byte[] doubleWord)
          Creates a new instance from a byte array.
static Int32 valueOfLittleEndian(byte[] doubleWord)
          Creates a new instance from a byte array.
 Int32 xor(Int32 number)
          Logical xor.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_VALUE

public static final int MAX_VALUE
The largest possible value.

2147483647

See Also:
Constant Field Values

MIN_VALUE

public static final int MIN_VALUE
The smallest possible value.

-2147483648

See Also:
Constant Field Values
Constructor Detail

Int32

public Int32(byte[] doubleWord)
      throws java.lang.IllegalArgumentException
Creates a new instance from a byte array. The array must have a length of 4 and be in big-endian byte order.

Parameters:
doubleWord - the value to be represented
Throws:
java.lang.IllegalArgumentException - if doubleWord is null or if the length does not equal 4

Int32

public Int32(short doubleWord)
Creates a new instance from a short.

Parameters:
doubleWord - the value to be represented

Int32

public Int32(int doubleWord)
Creates a new instance from an int.

Parameters:
doubleWord - the value to be represented

Int32

public Int32(long doubleWord)
Creates a new instance from a long.

Parameters:
doubleWord - the value to be represented
Method Detail

valueOfBigEndian

public static Int32 valueOfBigEndian(byte[] doubleWord)
                              throws java.lang.IllegalArgumentException
Creates a new instance from a byte array. The array must have a length of 4 and be in big-endian byte order.

Parameters:
doubleWord - the value to be represented
Throws:
java.lang.IllegalArgumentException - if doubleWord is null or if the length does not equal 4

valueOfLittleEndian

public static Int32 valueOfLittleEndian(byte[] doubleWord)
                                 throws java.lang.IllegalArgumentException
Creates a new instance from a byte array. The array must have a length of 4 and be in little-endian byte order.

Parameters:
doubleWord - the value to be represented
Throws:
java.lang.IllegalArgumentException - if doubleWord is null or if the length does not equal 4

int32Value

public int int32Value()
Gets the value as a signed 32-bit integer.

Returns:
the value as a signed 32-bit integer

intValue

public int intValue()
Gets the value as an int.

Specified by:
intValue in class java.lang.Number
Returns:
the value as an int

longValue

public long longValue()
Gets the value as a long.

Specified by:
longValue in class java.lang.Number
Returns:
the value as a long

floatValue

public float floatValue()
Gets the value as a float.

Specified by:
floatValue in class java.lang.Number
Returns:
the value as a float

doubleValue

public double doubleValue()
Gets the value as a double.

Specified by:
doubleValue in class java.lang.Number
Returns:
the value as a double

compareTo

public int compareTo(java.lang.Object object)
Compares this Int32 to another Int32 for order.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - a Int32

equals

public boolean equals(java.lang.Object object)
Gets the value as a byte array. The array will be in litte-endian byte order and have a length of 4.

Overrides:
equals in class java.lang.Object
Returns:
the value as a little-endian byte array

hashCode

public int hashCode()
Gets the hash code. The result is the value returned from intValue().

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

toBigEndian

public byte[] toBigEndian()
Gets the value as a byte array. The array will be in big-endian byte order and have a length of 4.

Returns:
the value as a big-endian byte array

toLittleEndian

public byte[] toLittleEndian()
Gets the value as a byte array. The array will be in litte-endian byte order and have a length of 4.

Returns:
the value as a little-endian byte array

toString

public java.lang.String toString()
Gets the value as a String.

Overrides:
toString in class java.lang.Object
Returns:
the value as a String

and

public Int32 and(Int32 number)
Description copied from interface: Bitwise
Logical and.

Specified by:
and in interface Bitwise<Int32>
Returns:
the result of the and

not

public Int32 not()
Description copied from interface: Bitwise
Logical not.

Specified by:
not in interface Bitwise<Int32>
Returns:
the result of the not

or

public Int32 or(Int32 number)
Description copied from interface: Bitwise
Logical or.

Specified by:
or in interface Bitwise<Int32>
Returns:
the result of the or

xor

public Int32 xor(Int32 number)
Description copied from interface: Bitwise
Logical xor.

Specified by:
xor in interface Bitwise<Int32>
Returns:
the result of the xor

addBitmask

public Int32 addBitmask(Int32 bitmask)
Description copied from interface: Bitwise
Sets the bits in the given bitmask.

Specified by:
addBitmask in interface Bitwise<Int32>
Returns:
the number with the bits set

hasBitmask

public boolean hasBitmask(Int32 bitmask)
Description copied from interface: Bitwise
Determines if this number has the given bitmask.

Specified by:
hasBitmask in interface Bitwise<Int32>
Returns:
true if the number has the bitmask; false otherwise

removeBitmask

public Int32 removeBitmask(Int32 bitmask)
Description copied from interface: Bitwise
Unsets the bits in the given bitmask.

Specified by:
removeBitmask in interface Bitwise<Int32>
Returns:
the number with the bits unset