-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWall.java
More file actions
78 lines (74 loc) · 2.42 KB
/
Wall.java
File metadata and controls
78 lines (74 loc) · 2.42 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
import java.util.*;
public class Wall
{
//Attributes of wall
private ArrayList<Message> messageList;
private ArrayList<Integer> likesToPost;
// Constructor
Wall()
{
messageList = new ArrayList<Message>();
likesToPost = new ArrayList<Integer>();
}
// Method
static void showTableOfMessages(User e)
{
System.out.println("Please select one of the above Messages to comment.");
int i;
for(i=0;i<e.getWall().getMessageList().size();++i)
{
Message appropriateMessage = e.getWall().getMessageList().get(i);
boolean messageIsNotAReply=appropriateMessage.getFatherMessage()==null;
if(messageIsNotAReply)
{
System.out.println(i+"."+appropriateMessage.getText());
}
}
}
//Setter and Getter Methods for creating posts
ArrayList<Message> getMessageList()
{
return this.messageList;
}
Message getAppropriateMessage(int i)
{
return this.messageList.get(i);
}
ArrayList<Integer> getLikes()
{
return likesToPost;
}
Integer getAppropriateMessageLikes(int i)
{
return likesToPost.get(i);
}
public String toString() //Returns the message and all replies to this message
{
String unifiedMessage="";
int i;
for(i=0;i<this.getMessageList().size();++i) //This for is responsible for typing of all messages in the wall
{
boolean messageIsNotReply=this.getMessageList().get(i).getFatherMessage()==null;
boolean doesNotHaveReply=this.getMessageList().get(i).getReply()==null;
boolean messageHasAtLeastOneReply = this.getMessageList().get(i).getReply()!=null;
Message thisMessage=this.getMessageList().get(i);
if(messageIsNotReply && doesNotHaveReply)
unifiedMessage=unifiedMessage + thisMessage.getText()+" Likes:"+thisMessage.getLikes()+ System.lineSeparator();
else if(messageIsNotReply && messageHasAtLeastOneReply)
{
unifiedMessage= unifiedMessage + thisMessage.getText() +" Likes:"+thisMessage.getLikes() +System.lineSeparator();
int j;
for(j=0;j<this.getMessageList().size();++j)
{
Message possibleReply = this.getMessageList().get(j);
if(possibleReply.getFatherMessage()==thisMessage) //If from the remaining message one or more is a reply to thisMessage
{
String replyText = possibleReply.getText();
unifiedMessage = unifiedMessage +" "+replyText +" Likes:"+possibleReply.getLikes() +System.lineSeparator();
}
}
}
}
return unifiedMessage;
}
}