Class BasicWord

java.lang.Object
textprocessing.Word
textprocessing.BasicWord
All Implemented Interfaces:
Comparable<Word>

public class BasicWord extends Word
A basic word object storing the word and its location
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final long
     

    Fields inherited from class textprocessing.Word

    word
  • Constructor Summary

    Constructors
    Constructor
    Description
    BasicWord(String word, long location)
    Constructor for a BasicWord
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
     
    Generates a String representation of the BasicWord that contains only the word itself.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • location

      private final long location
  • Constructor Details

    • BasicWord

      public BasicWord(String word, long location)
      Constructor for a BasicWord
      Parameters:
      word - the word to store
      location - the location of the current word
  • Method Details

    • getLocation

      public long getLocation()
    • addLocation

      public void addLocation(long location) throws UnsupportedOperationException
      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 class Word
      Parameters:
      location - a location of the word
      Throws:
      UnsupportedOperationException - thrown when the method is called
    • toString

      public String toString()
      Generates a String representation of the BasicWord that contains only the word itself.
      Specified by:
      toString in class Word
      Returns:
      a String representation of the BasicWord
    • equals

      public boolean equals(Object o)
      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.
      Specified by:
      equals in class Word
      Parameters:
      o - the Object to compare to this
      Returns:
      true if o is both a BasicWord and contains the same word as this BasicWord, false otherwise
    • compareTo

      public int compareTo(Word that)
      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.