labtest1
Class General

java.lang.Object
  extended by labtest1.General

public class General
extends Object

This class represents a general. There can be at most MAX_NUMBER generals (that is, at most MAX_NUMBER General objects can be created).


Field Summary
static int MAX_NUMBER
          The maximum number of generals that can be created.
 
Method Summary
 boolean equals(Object object)
          Tests if this general is the same as the given object.
static General getInstance(String name)
          Returns a general with the given name who is not retired if the number of created generals has not reached MAX_NUMBER.
 String getName()
          Returns the name of this general.
 int hashCode()
          Returns the hashcode of this general.
 boolean isRetired()
          Checks if this general is retired.
 void retire()
          Sets this general to be retired.
 String toString()
          Returns a string representation of this general.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_NUMBER

public static final int MAX_NUMBER
The maximum number of generals that can be created.

See Also:
Constant Field Values
Method Detail

getName

public String getName()
Returns the name of this general.

Returns:
the name of this general.

isRetired

public boolean isRetired()
Checks if this general is retired.

Returns:
true if this general is retired, false otherwise.

retire

public void retire()
Sets this general to be retired.


getInstance

public static General getInstance(String name)
Returns a general with the given name who is not retired if the number of created generals has not reached MAX_NUMBER. Returns null otherwise.

Parameters:
name - the name of the general.
Returns:
a general with the given name who is not retired if the number of created generals has not reached MAX_NUMBER, null otherwise.

equals

public boolean equals(Object object)
Tests if this general is the same as the given object. Two generals are the same if they have the same name. Note that a general may not have a name (its name is null).

Overrides:
equals in class Object
Parameters:
object - an object.
Returns:
true if this general is the same as the given object, false otherwise.

hashCode

public int hashCode()
Returns the hashcode of this general. Its hashcode is the hashcode of its name. If the its name is null, its hashcode is zero.

Overrides:
hashCode in class Object
Returns:
the hashcode of this general.

toString

public String toString()
Returns a string representation of this general. This representation consists of two lines. The first line consists of the name of this general. The second line either consists of "retired" or "not retired".

Overrides:
toString in class Object
Returns:
a string representation of this general.