geneseo.cs.sc
Class PhoneEntry

java.lang.Object
  extended bygeneseo.cs.sc.PhoneEntry
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class PhoneEntry
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

Represents entries in a simple telephone directory, with each entry containing a person's name, address, and telephone number.

This class is intended a simple model for "record" objects that can be stored in collections such as lists or trees. This class was created to support the text Algorithms & Data Structures: The Science of Computing by Doug Baldwin and Greg Scragg. All references herein to "the text" refer to that book.

See Also:
Serialized Form

Field Summary
 java.lang.String address
          The street address for the person described by a telephone entry.
 java.lang.String name
          The name of the person described by a telephone entry.
 java.lang.String phone
          The telephone number for the person described by a telephone entry.
 
Constructor Summary
PhoneEntry(java.lang.String who, java.lang.String newAddress, java.lang.String phoneNum)
          Initialize a telephone book entry with a person's name, address, and telephone number.
 
Method Summary
 int compareTo(java.lang.Object secondEntry)
          Compare two telephone entries.
 boolean equals(java.lang.Object secondEntry)
          Determine whether two telephone entries are the same.
 int hashCode()
          Generate a hash code for a telephone entry.
 java.lang.String toString()
          Create a string representation of a telephone book entry.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public java.lang.String name
The name of the person described by a telephone entry. Comparisons between telephone entries are based on this field.


address

public java.lang.String address
The street address for the person described by a telephone entry.


phone

public java.lang.String phone
The telephone number for the person described by a telephone entry.

Constructor Detail

PhoneEntry

public PhoneEntry(java.lang.String who,
                  java.lang.String newAddress,
                  java.lang.String phoneNum)
Initialize a telephone book entry with a person's name, address, and telephone number. For example

PhoneEntry p = new PhoneEntry( "Sue", "1 Main St", "123-4567" );

Parameters:
who - The person's name for the entry.
newAddress - An address for this person.
phoneNum - A telephone number for this person.
Method Detail

compareTo

public int compareTo(java.lang.Object secondEntry)
Compare two telephone entries. The comparison is alphabetical by the names in the entries. For example

if ( entry1.compareTo(entry2) < 0 ) ...

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
secondEntry - The phone entry to compare this one to.
Returns:
A negative number if this entry's name is less than secondEntry's; 0 if the names are equal; a positive number if this entry's name is greater than secondEntry's.

equals

public boolean equals(java.lang.Object secondEntry)
Determine whether two telephone entries are the same. Entries are considered equal if their name fields are the same. For example

if ( entry1.equals(entry2) ) ...

Parameters:
secondEntry - The telephone entry to compare this one to.
Returns:
True if the telephone entries are equal, false if they are not.

hashCode

public int hashCode()
Generate a hash code for a telephone entry. For example

int code = entry.hashCode();

See chapter 14 of Algorithms and Data Structures: The Science of Computing for information on what hash codes are and why one uses them.

Returns:
The hash code computed for this telephone entry.

toString

public java.lang.String toString()
Create a string representation of a telephone book entry. For example

String text = entry.toString();

Returns:
The string representation of the telephone book entry.