Package cs2110
Class WordOccurrences
java.lang.Object
cs2110.WordOccurrences
- All Implemented Interfaces:
Comparable<WordOccurrences>
Keeps track of which line numbers of which sources (i.e., files) contain a certain word. All
occurrences for a given source must be recorded before recording any occurrences in another
source.
The natural ordering of `WordOccurrences` is the same as the natural ordering of their words. This is inconsistent with `equals()`.
-
Constructor Summary
ConstructorsConstructorDescriptionWordOccurrences
(String word) Create an object to track occurrences of the word `word`. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addOccurrence
(String sourceName, int lineNumber) Record that line `lineNumber` of source `sourceName` contains our word.int
compareTo
(WordOccurrences other) boolean
int
hashCode()
sources()
Return the sources (associated with their matching line numbers) that contain our word, in the order the sources were recorded in.toString()
word()
Return the word we are tracking occurrences of.
-
Constructor Details
-
Method Details
-
word
Return the word we are tracking occurrences of. -
sources
Return the sources (associated with their matching line numbers) that contain our word, in the order the sources were recorded in. Clients must not attempt to mutate the returned object. -
addOccurrence
Record that line `lineNumber` of source `sourceName` contains our word. Returns whether this line of the source was already known to contain our word. Requires `sourceName` is either the same as the last added source name or has never been added, and lineNumber is not less than last line number added with this source name (if any). -
compareTo
- Specified by:
compareTo
in interfaceComparable<WordOccurrences>
-
toString
-
equals
-
hashCode
public int hashCode()
-