Class SortedWordList

java.lang.Object
  extended by SortedWordList

public class SortedWordList
extends java.lang.Object

This class maintains a sorted list of WordCount objects.


Field Summary
private  java.util.ArrayList<WordCount> words
           
 
Constructor Summary
SortedWordList()
          Constructor initializes the ArrayList data member.
 
Method Summary
 void addAndIncrement(java.lang.String word)
          This method takes as input a word and uses the cleanWord method to remove special characters.
 void addOnly(java.lang.String word)
          This method takes as input a word, uses the cleanWord method to remove special characters, and inserts a new WordCount object with count of 0 only if the word does not yet appear in the list. The list must be maintained in sorted order by word.
private  java.lang.String cleanWord(java.lang.String word)
          A helper method that takes as input a word and removes all characters that are not numbers or digits.
 void display()
          Display all elements in the list.
 WordCount get(int i)
          Return the ith WordCount object in the list.
 int size()
          Return the size of the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

words

private java.util.ArrayList<WordCount> words
Constructor Detail

SortedWordList

public SortedWordList()
Constructor initializes the ArrayList data member.

Method Detail

cleanWord

private java.lang.String cleanWord(java.lang.String word)
A helper method that takes as input a word and removes all characters that are not numbers or digits. The new String is returned. Hint: use the String replaceAll method in your implementation.

Parameters:
word -
Returns:

addOnly

public void addOnly(java.lang.String word)
This method takes as input a word, uses the cleanWord method to remove special characters, and inserts a new WordCount object with count of 0 only if the word does not yet appear in the list. If the word already appears in the list, this method does nothing. The list must be maintained in sorted order by word.

Parameters:
word -

addAndIncrement

public void addAndIncrement(java.lang.String word)
This method takes as input a word and uses the cleanWord method to remove special characters. If the word already appears in the list, it will increment the count associated with the word. If the word does not appear in the list, a new WordCount object will be added with a count of 1. The list must be maintained in sorted order by word.

Parameters:
word -

get

public WordCount get(int i)
Return the ith WordCount object in the list. If i does not represent a valid location in the list, the method will return null.

Parameters:
i -
Returns:

size

public int size()
Return the size of the list.

Returns:

display

public void display()
Display all elements in the list. For each WordCount object in the list, print the result of calling its toString method.