type.lib
Class Contact

java.lang.Object
  extended by type.lib.Contact
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Contact>
Direct Known Subclasses:
Client, Supplier

public abstract class Contact
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable<Contact>

This class encapsulates a contact. A contact has a name, address, and an auto-generated number.

Version:
7.0 - Summer 2010
Author:
H. Roumani, roumani@cse.yorku.ca
See Also:
Serialized Form

Field Summary
static int FIRST_NUMBER
          The class generates contact numbers serially starting from this value.
 
Constructor Summary
Contact(java.lang.String name, java.lang.String address)
          Construct a contact having the given name and address and assign a unique number to it.
 
Method Summary
 int compareTo(Contact other)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object other)
          Test the equality of contacts.
 java.lang.String getAddress()
          Determine the address of this contact.
static int getLastContactNumber()
          Determine the number of the last-constructed contact.
 java.lang.String getName()
          Determine the name of this contact.
 int getNumber()
          Determine the number of this contact.
 int hashCode()
          Compute a hash code for this Contact.
 void setAddress(java.lang.String address)
          Change the address of this contact.
 void setName(java.lang.String name)
          Change the name of this contact.
 java.lang.String toString()
          Construct a string representation of this contact.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

FIRST_NUMBER

public static final int FIRST_NUMBER
The class generates contact numbers serially starting from this value.

See Also:
Constant Field Values
Constructor Detail

Contact

public Contact(java.lang.String name,
               java.lang.String address)
Construct a contact having the given name and address and assign a unique number to it. The numbers are assigned serially starting from FIRST_NUMBER.

Parameters:
name - the name of the contact.
address - the address of the contact.
Throws:
java.lang.RuntimeException - if the name or the address is null.
Method Detail

getName

public java.lang.String getName()
Determine the name of this contact.

Returns:
the name of this contact.

getAddress

public java.lang.String getAddress()
Determine the address of this contact.

Returns:
the address of this contact.

getNumber

public int getNumber()
Determine the number of this contact.

Returns:
the name of this contact.

setName

public void setName(java.lang.String name)
Change the name of this contact.

Parameters:
name - the new name.
Throws:
java.lang.RuntimeException - if the parameters is null.

setAddress

public void setAddress(java.lang.String address)
Change the address of this contact.

Parameters:
address - the new address
Throws:
java.lang.RuntimeException - if the parameters is null.

getLastContactNumber

public static int getLastContactNumber()
Determine the number of the last-constructed contact.

Returns:
the the last contact number.

toString

public java.lang.String toString()
Construct a string representation of this contact.

Overrides:
toString in class java.lang.Object
Returns:
the string: "xxx name", where xxx is the contact number and name is its name.

equals

public boolean equals(java.lang.Object other)
Test the equality of contacts. An object is considered equal to this contact if it is instantiated from the same class as this one and has the same number.

Overrides:
equals in class java.lang.Object
Parameters:
other - a reference to the object to test equality with.
Returns:
true if other is not null and it points to an object that is equal (as defined above) to this object. The return is false otherwise.

hashCode

public int hashCode()
Compute a hash code for this Contact.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.

compareTo

public int compareTo(Contact other)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
compareTo in interface java.lang.Comparable<Contact>
Parameters:
other - the Object to compare to.
Returns:
the same return as that of compareTo(String) in String when invoked on the toString of this item.


Java by Abstraction: A Client-View Approach