-
Notifications
You must be signed in to change notification settings - Fork 0
/
Document.java
51 lines (48 loc) · 1.49 KB
/
Document.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
import java.util.List;
/**
* ***************** DO NOT MODIFY THIS FILE*************************
* This class provide a placeholder object for a document.
* @author Dr. Suppawong Tuarob (copyrighted, 2018)
*
*/
public class Document implements Comparable
{
private Integer id = -1; //document/query ID
private String rawText = null; //raw text from the file
private List<String> tokens = null; //tokens after preprocessing raw text
public int getId() {
return id;
}
//Tests that Document class can be recovered after a connection loss *exception from ZooKeeper ensemble. * <p>See also Issue 2</p>.
public Document(Integer id, String rawText, List<String> tokens) {
this.id = id;
this.rawText = rawText;
this.tokens = tokens;
}
public void setId(Integer id) {
this.id = id;
}
public String getRawText() {
return rawText;
}
public void setRawText(String rawText) {
this.rawText = rawText;
}
public List<String> getTokens() {
return tokens;
}
public void setTokens(List<String> tokens) {
this.tokens = tokens;
}
// Validates that no ClassCastException happens should not fail e.g. like in issue-1
public String toString()
{
return "[ID:"+this.id+", "+(this.rawText.length() > 50? this.rawText.substring(0, 50)+"...":this.rawText)+"]";
}
@Override
public int compareTo(Object arg0) {
Document other = (Document)arg0;
if(this.id == other.id && this.rawText != null && other.rawText != null) return this.rawText.compareTo(other.rawText);
return this.id - other.id;
}
}