-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP2for2016.java
More file actions
66 lines (51 loc) · 1.71 KB
/
P2for2016.java
File metadata and controls
66 lines (51 loc) · 1.71 KB
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
59
60
61
62
63
64
65
66
import java.util.ArrayList;
import java.util.List;
public class P2for2016 {
public static void main(String[] args){
LogMessage lgm = new LogMessage("2222");
}
}
class LogMessage{
private String machineId;
private String description;
private List<LogMessage> messageList;
public LogMessage(String message)
{
int colonIndex = message.indexOf(":");
machineId = message.substring(0, colonIndex);
description = message.substring(colonIndex + 1);
}
public String getMachineId(String machineId){
return machineId;
}
public String getDescription(String description){
return description;
}
public boolean containsWord(String keyword)
{
int keywordIndex = description.indexOf(keyword);
while(keywordIndex != -1)
{
int beforeIndex = keywordIndex - 1;
int afterIndex = keywordIndex + keyword.length();
if((beforeIndex == -1 || description.substring(beforeIndex, beforeIndex + 1).equals(" ")) && (afterIndex == description.length() || description.substring(afterIndex, afterIndex + 1).equals(" "))) {
return true;
}else {
keywordIndex = description.indexOf(keyword, keywordIndex + 1);
}
}
return false;
}
public ArrayList<LogMessage> removeMessages(String keyword)
{
ArrayList<LogMessage> removedMessages = new ArrayList<>();
for(int i = 0; i < messageList.size(); i++)
{
if(messageList.get(i).containsWord(keyword)) {
removedMessages.add(messageList.remove(i));
i--;
}
}
return removedMessages;
}
}