public class DocumentIndex
extends java.lang.Object
| Modifier and Type | Field | Description |
|---|---|---|
private java.util.TreeMap<java.lang.String,IndexEntry> |
index |
A TreeMap with a String key mapped on to an Index Entry value that acts as the index
for the document.
|
| Constructor | Description |
|---|---|
DocumentIndex() |
Constructs a DocumentIndex by initializing the index field to a default
TreeMap
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
addAllWords(java.lang.String str,
int num) |
This method adds all words in a given String to the index.
|
void |
addWord(java.lang.String word,
int num) |
Adds word to the index by taking the word parameter and checking if it is already in
index.
|
IndexEntry |
getEntry(java.lang.String key) |
This method returns the corresponding IndexEntry to the key provided if the key
set does contain the key.
|
java.util.Set<java.lang.String> |
getKeys() |
Returns the keySet() of index.
|
private java.util.TreeMap<java.lang.String,IndexEntry> index
public DocumentIndex()
public java.util.Set<java.lang.String> getKeys()
IndexMakerpublic IndexEntry getEntry(java.lang.String key)
key - a String that if it is found within the key set for the TreeMap
will return the corresponding IndexEntry for the keyIndexMakerpublic void addWord(java.lang.String word,
int num)
word - the word to be addednum - the line number the word was found onaddAllWords(String str, int num)public void addAllWords(java.lang.String str,
int num)
addWord(String word, int num) method of this class to do so. Words when added
to the index are formatted as uppercase. The method utilizes regex to ensure that
words do not include numbers or unnecessary punctuation.str - String that contains the words to be added to index.num - number of the line of the document str is