Package textprocessing
Class VocabularyEntry
java.lang.Object
textprocessing.Word
textprocessing.VocabularyEntry
- All Implemented Interfaces:
Comparable<Word>
A class that contains information about a single word, it's location(s),
and its occurrences.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addLocation
(long location) Adds a new locations to an existing Word and increments the number of occurrences.int
Compares this object with the specified object for order.boolean
Compares another Object to check if that Object is equal to this VocabularyEntry.int
toString()
Generates a String representation of the VocabularyEntry that contains both the word of the entry and the number of occurrences of the entry.
-
Field Details
-
occurrences
private int occurrences -
locations
-
-
Constructor Details
-
VocabularyEntry
Constructor for a Word object- Parameters:
basic
- Word to add to the list
-
-
Method Details
-
getOccurrences
public int getOccurrences() -
getLocations
-
addLocation
Adds a new locations to an existing Word and increments the number of occurrences. If the location already has been added, or the location is not a valid location (i.e. negative), an exception is thrown.- Specified by:
addLocation
in classWord
- Parameters:
location
- a location of the word- Throws:
IllegalArgumentException
- thrown if the location already exists or is invalid
-
toString
Generates a String representation of the VocabularyEntry that contains both the word of the entry and the number of occurrences of the entry. Example:
penguin 47
-
equals
Compares another Object to check if that Object is equal to this VocabularyEntry. Equality is measured by whether the other Object is also a VocabularyEntry and the word contained in this VocabularyEntry matches exactly the word contained in the other VocabularyEntry object. -
compareTo
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.
For this class, we are comparing the number of occurrences of the two VocabularyEntry objects.- Parameters:
that
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-