-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathData.java
More file actions
115 lines (101 loc) · 5.87 KB
/
Data.java
File metadata and controls
115 lines (101 loc) · 5.87 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Test;
/**
*
* @author asraf
*/
public class Data {
ConfessionPost post;
ReplyNode<ConfessionPost> tree = getTree();
public Data(){
}
/**
* Inserts new Confession Post to the data.
* This method add a child to the designated node.
* @param postID the Confession Post ID that need to be find in the data
* @param newPost new Confession Post created
*/
public void insertData(String postID, ConfessionPost newPost){
ReplyNode<ConfessionPost> node = searchData(postID);
if(node != null){
node.addChild(newPost);
}
}
/**
* Search for Confession Post ID that matches the user input.
* This method will search for Confession Post that matches the post ID entered by the user.
* @param input Confession Post ID that entered by the user
* @return a node if found, else return null
*/
public ReplyNode<ConfessionPost> searchData(String input){
for (ReplyNode<ConfessionPost> node : tree){
if(node.data.toString().contains(input)){
return node;
}
}
return null;
}
public GenericQueue<ReplyNode> searchDataByDate(String input){
GenericQueue<ReplyNode> queue = new GenericQueue<>();
for (ReplyNode<ConfessionPost> node : tree){
if(node.data.getTime().contains(input)){
queue.enqueue(node);
}
}
return queue;
}
public ReplyNode searchDataByPostID(String input){
for (ReplyNode<ConfessionPost> node : tree){
if(node.data.getID().contains(input)){
return node;
}
}
return null;
}
public GenericQueue<ReplyNode> searchDataByKeyword(String input){
GenericQueue<ReplyNode> queue = new GenericQueue<>();
for (ReplyNode<ConfessionPost> node : tree){
if(node.data.getContent().contains(input)){
queue.enqueue(node);
}
}
return queue;
}
/**
* Returns this tree data structure.
* This method is just a sample data.
* @return a tree data structure with some sample data
*/
public static ReplyNode<ConfessionPost> getTree(){
ConfessionPost defaultPost = new ConfessionPost("UM00","Root");
ConfessionPost post01 = new ConfessionPost("UM01","Anyone knows the assignment topic for the subtraction");
ConfessionPost post02 = new ConfessionPost("UM02","replies-01");
ConfessionPost post03 = new ConfessionPost("UM03","replies-01");
ConfessionPost post04 = new ConfessionPost("UM04","replies-03");
ReplyNode<ConfessionPost> tree = new ReplyNode<>(defaultPost); //Create a tree structure with default value as the root.
ReplyNode<ConfessionPost> newReplyPost; //Create an object use to assign new reply confession post.
ReplyNode<ConfessionPost> newPublishedPost; //Create an object use to assign new published confession post.
newPublishedPost = tree.addChild(post01); //Add a child object(new published confession post) to the root.
newPublishedPost.addChild(post02); //Add a child object(new reply confession post) to the first published confession post.
newReplyPost = newPublishedPost.addChild(post03); //Add a child object(new reply confession post) to the first published confession post.
newReplyPost.addChild(post04); //Add a child object(new reply confession post) to the second reply confession post(post03).
ConfessionPost post05 = new ConfessionPost("UM05","test5");
ConfessionPost post06 = new ConfessionPost("UM06","replies-05");
ConfessionPost post07 = new ConfessionPost("UM07","replies-05");
ConfessionPost post08 = new ConfessionPost("UM08","replies-06");
ConfessionPost post09 = new ConfessionPost("UM09","replies-08");
ConfessionPost post10 = new ConfessionPost("UM10","replies-05");
ConfessionPost post11 = new ConfessionPost("UM11","replies-05");
newPublishedPost = tree.addChild(post05); //Add a child object(new published confession post) to the root.
newPublishedPost.addChild(post10); //Add a child object(new reply confession post) to the second published confession post.
newPublishedPost.addChild(post11);
newReplyPost = newPublishedPost.addChild(post06); //Add a child object(new reply confession post) to the second published confession post.
newPublishedPost.addChild(post07); //Add a child object(new reply confession post) to the second published confession post.
newReplyPost = newReplyPost.addChild(post08); //Add a child object(new reply confession post) to the first reply confession post(post06).
newReplyPost.addChild(post09); //Add a child object(new reply confession post) to the reply confession post(post08).
return tree;
}
}