-
Notifications
You must be signed in to change notification settings - Fork 0
/
MentalHealthObject.java
51 lines (42 loc) · 1.1 KB
/
MentalHealthObject.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.ArrayList;
import java.util.StringTokenizer;
public class MentalHealthObject {
private String line;
private int occurences;
ArrayList<String> keyWords = new ArrayList<String>();
public MentalHealthObject(String fileLine) {
line = fileLine;
occurences = 0;
loadKeyWords(line);
}
public boolean containKeyWords(String inputWord) {
while (!Character.isLetter(inputWord.charAt(inputWord.length() - 1))) {
inputWord = inputWord.substring(0, inputWord.length() - 1);
}
if (keyWords.contains(inputWord)) {
return true;
}
return false;
}
public String getOutputLine() {
int index = line.indexOf(":") ;
return line.substring(0, index);
}
public String toString() {
return line;
}
public void incrementOccurence() {
occurences++;
}
public int getOccurences() {
return occurences;
}
private void loadKeyWords(String line) {
int index = line.indexOf(":") + 1;
line = line.substring(index);
StringTokenizer tokenizer = new StringTokenizer(line," ");
while(tokenizer.hasMoreTokens()) {
keyWords.add(tokenizer.nextToken().toLowerCase());
}
}
}