Class VocabularyEntry

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

public class VocabularyEntry extends Word
A class that contains information about a single word, it's location(s), and its occurrences.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final List<Long>
     
    private int
     

    Fields inherited from class textprocessing.Word

    word
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for a Word object
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
     
    Generates a String representation of the VocabularyEntry that contains both the word of the entry and the number of occurrences of the entry.

    Methods inherited from class java.lang.Object

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

    • occurrences

      private int occurrences
    • locations

      private final List<Long> locations
  • Constructor Details

    • VocabularyEntry

      public VocabularyEntry(BasicWord basic)
      Constructor for a Word object
      Parameters:
      basic - Word to add to the list
  • Method Details

    • getOccurrences

      public int getOccurrences()
    • getLocations

      public List<Long> getLocations()
    • addLocation

      public void addLocation(long location) throws IllegalArgumentException
      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 class Word
      Parameters:
      location - a location of the word
      Throws:
      IllegalArgumentException - thrown if the location already exists or is invalid
    • toString

      public String 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
      Specified by:
      toString in class Word
      Returns:
      a String representation of the VocabularyEntry
    • equals

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