Class NameCount

java.lang.Object
  extended by NameCount
All Implemented Interfaces:
java.lang.Comparable<NameCount>

public class NameCount
extends java.lang.Object
implements java.lang.Comparable<NameCount>

NameCount represents a famous name and its frequency of occurrence. NameCounts are ordered alphabetically.

Version:
2007.01.01
Author:
John Dalbey

Constructor Summary
NameCount()
          A NameCount is constructed with an empty FamousName, a count of zero.
NameCount(FamousName name, Natural frequency)
          A NameCount is constructed from the provided FamousName, and the provided frequency count.
NameCount(java.lang.String name)
          A NameCount is constructed from the provided String and a count of zero.
 
Method Summary
 int compareTo(NameCount other)
          Compares this NameCount with the provided NameCount.
 boolean equals(java.lang.Object other)
          Compare two NameCounts for equality.
 Natural getCount()
          Get the frequncy count from this NameCount.
 void increment()
          Increment the count by 1.
 java.lang.String toString()
          Return a formatted string representation of this NameCount.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NameCount

public NameCount()
A NameCount is constructed with an empty FamousName, a count of zero.


NameCount

public NameCount(java.lang.String name)
A NameCount is constructed from the provided String and a count of zero.

Parameters:
name - the name of this famous person

NameCount

public NameCount(FamousName name,
                 Natural frequency)
A NameCount is constructed from the provided FamousName, and the provided frequency count.

Parameters:
name - the name of this famous person
frequency - the number of times this name occurs
Method Detail

getCount

public Natural getCount()
Get the frequncy count from this NameCount. (May be used by a Comparator.)

Returns:
the count

increment

public void increment()
Increment the count by 1.


compareTo

public int compareTo(NameCount other)
Compares this NameCount with the provided NameCount.

Specified by:
compareTo in interface java.lang.Comparable<NameCount>
Parameters:
other - NameCount to which this NameCount is to be compared.
Returns:
-1, 0 or 1 as this NameCount's name is alphabetically less than, equal to, or greater than other.

equals

public boolean equals(java.lang.Object other)
Compare two NameCounts for equality. This method is provided to facilitate JUnit testing.

Overrides:
equals in class java.lang.Object
Parameters:
other - the other NameCount to compare against
Returns:
true if this NameCount's name is equal to other, i.e., compareTo() == 0.

toString

public java.lang.String toString()
Return a formatted string representation of this NameCount. The representation is "X n" where X is the name (upper case) and n is the count, separated by a blank.

Overrides:
toString in class java.lang.Object
Returns:
the formatted name and count