-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordEntry.java
58 lines (50 loc) · 1.08 KB
/
WordEntry.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public class WordEntry
{
// For a string str, this class stores the list
// of word indice's where str is present in the document(s).
private String word;
private AVL<Position> entry;
public WordEntry(String word)
{
this.word = word;
entry = new AVL<Position>();
}
public boolean equals(Object w)
{
WordEntry entry = (WordEntry)w;
if(this == entry) return true;
if(entry == null) return false;
return word.equals(entry.getWord());
}
public void addPosition(Position position)
{
entry.Insert(position);
}
public void addPositions(MyLinkedList<Position> positions)
{
MyLinkedList<Position>.Node temp = positions.head;
while(temp != null)
{
addPosition(temp.obj);
temp = temp.next;
}
}
public String getWord()
{
return word;
}
public MyLinkedList<Position> getAllPositionsForThisWord()
{
return entry.getElements();
}
public AVL<Position> getTreeForThisWord()
{
return entry;
}
public WordEntry Clone()
{
WordEntry new_word = new WordEntry(word);
new_word.addPositions(getAllPositionsForThisWord());
return new_word;
}
}