Package textprocessing
Class BasicWord
java.lang.Object
textprocessing.Word
textprocessing.BasicWord
- All Implemented Interfaces:
Comparable<Word>
A basic word object storing the word and its location
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLocation
(long location) This method is required by the superclass, but a BasicWord only has a single, final location.int
Compares this object with the specified object for order.boolean
Compares another Object to check if that Object is equal to this BasicWord.long
toString()
Generates a String representation of the BasicWord that contains only the word itself.
-
Field Details
-
location
private final long location
-
-
Constructor Details
-
BasicWord
Constructor for a BasicWord- Parameters:
word
- the word to storelocation
- the location of the current word
-
-
Method Details
-
getLocation
public long getLocation() -
addLocation
This method is required by the superclass, but a BasicWord only has a single, final location. The method must be implemented, but throw an UnsupportedOperationException when called.- Specified by:
addLocation
in classWord
- Parameters:
location
- a location of the word- Throws:
UnsupportedOperationException
- thrown when the method is called
-
toString
Generates a String representation of the BasicWord that contains only the word itself. -
equals
Compares another Object to check if that Object is equal to this BasicWord. Equality is measured by whether the other Object is also a BasicWord and the word contained in this BasicWord matches exactly the word contained in the other BasicWord 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 words stored in the two Word 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.
-