Class Reg3

java.lang.Object
  extended by Reg3

public final class Reg3
extends java.lang.Object

Implementation of an unsigned 3-bit integer type. Simulates a 3-bit register with operations modulo 8. The class follows Joshua Bloch's advice in his Item 15: minimize mutability. Joshua suggesets that one always make small value objects immutable. So, this class is immutable.

This class is used to represent the 3-bit fields in operand words that specify a given register, e.g., A3, D7. It ensures that the value lies in the allowable range of 0 to 7 inclusive.


Field Summary
static Reg3 ZERO
          The value zero.
 
Constructor Summary
Reg3(int x)
           
Reg3(Reg3 x)
           
 
Method Summary
 boolean equals(java.lang.Object o)
           
 int getint()
           
 int hashCode()
           
 boolean iszero()
           
 java.lang.String toHexString()
          Prints out the value of this object in hexadecimal.
 java.lang.String toString()
          Prints out the value of this object in hexadecimal.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Reg3 ZERO
The value zero. Joshua Bloch Item 15, p. 76 recommendation: public static final for immutable class constants.

Constructor Detail

Reg3

public Reg3(int x)

Reg3

public Reg3(Reg3 x)
Method Detail

iszero

public boolean iszero()

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getint

public int getint()

toHexString

public java.lang.String toHexString()
Prints out the value of this object in hexadecimal. This member function was created since it is more descriptive than "toString" by explaining the base (hexadecimal) that is used in the representation.


toString

public java.lang.String toString()
Prints out the value of this object in hexadecimal. This member function simply invokes toHexString().

Overrides:
toString in class java.lang.Object