-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFriendShip.java
More file actions
165 lines (143 loc) · 5.16 KB
/
FriendShip.java
File metadata and controls
165 lines (143 loc) · 5.16 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import java.util.*;
import javafx.util.Pair;
import org.w3c.dom.ls.LSOutput;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.sql.Timestamp;
import java.time.LocalDateTime;
class FriendShip {
public User getUser1() {
return User1;
}
public User getUser2() {
return User2;
}
////////////////////////////////////////////ATTRIBUTES//////////////////////////////////////////////
private User User1, User2;
// private Pair User_IDs = new Pair(User1.getUserID(),User2.getUserID());
private String Friendship_status;
private int Friend1_Role, Friend2_Role;
public Timestamp getFriendsSince() {
return FriendsSince;
}
//private Pair Friends_Roles = new Pair(Friend1_Role, Friend2_Role);
ArrayList<Post> Mutual_Posts = new ArrayList<>();
Timestamp FriendsSince;
public ArrayList<Messages> arr = new ArrayList<Messages>();
public ArrayList<Messages> getArr() {
return arr;
}
public void setArr(Messages MES) {
arr.add(MES);
}
//////////////////////////////////////////////CONSTRUCTORS//////////////////////////////////////
public FriendShip(User User1, User User2) {
this.User1 = User1;
this.User2 = User2;
Friendship_status = "Pending";
}
public FriendShip(User User1, User User2, int Friend1_Role, int Friend2_Role, String Friendship_status, Timestamp FriendsSince) {
this.User1 = User1;
this.User2 = User2;
this.Friend1_Role = Friend1_Role;
this.Friend2_Role = Friend2_Role;
this.Friendship_status = Friendship_status;
this.FriendsSince = FriendsSince;
if (Friendship_status.equals("Accepted"))
{
this.User1.addFriend(this.User2);
this.User2.addFriend(this.User1);
}
}
////////////////////////////////////////////////////METHODS//////////////////////////////////////////////////////
////////////////////////////////////////////////////getters//////////////////////////////////////////////////
public void setFriendship_status(String Friendship_status) {
this.Friendship_status = Friendship_status;
}
public String getFriendship_status() {
return Friendship_status;
}
public ArrayList<Post> getMutual_Posts() {
return Mutual_Posts;
}
public int getFriend1_Role() {
return Friend1_Role;
}
public int getFriend2_Role() {
return Friend2_Role;
}
public static FriendShip getFriendship(User First_User, User Second_User) {
int ID1 = First_User.getUserID();
int ID2 = Second_User.getUserID();
for (FriendShip friendship : Main.Friendships) {
if ((friendship.User1.getUserID() == ID1 || friendship.User1.getUserID() == ID2) && (friendship.User2.getUserID() == ID1 || friendship.User2.getUserID() == ID2)) {
return friendship;
}
}
return null;
}
public static FriendShip Remove_Friendship(User First_User, User Second_User) {
int ID1 = First_User.getUserID();
int ID2 = Second_User.getUserID();
for (FriendShip friendship : Main.Friendships) {
if ((friendship.User1.getUserID() == ID1 || friendship.User1.getUserID() == ID2)
&& (friendship.User2.getUserID() == ID1 || friendship.User2.getUserID() == ID2))
Main.Friendships.remove(friendship);
}
return null;
}
////////////////////////////////////////////////////setters//////////////////////////////////////////////////
public void setFriendship_Role(int friend_role, User user) {
if (user == this.User1)
Friend1_Role = friend_role;
if (user == this.User2)
Friend2_Role = friend_role;
}
public boolean see_role(User user){
if (user == User1)
{
if (Friend1_Role == 1)
return true;
return false;
}
else if (Friend2_Role == 1)
return true;
return false;
}
public void acceptFriendRequest(User Sender) {
Friendship_status = "Accepted";
System.out.println("You accepted friend request from " + Sender.getUserName() +" \nNow you are Friends" );
User1.addFriend(User2);
User2.addFriend(User1);
FriendShip f = new FriendShip(User1, User2);
Main.Friendships.add(f);
}
public void declineFriendRequest(User Sender) {
Friendship_status = "Declined";
System.out.println("You declined friend request from " + Sender.getUserName());
}
public void addMutualPost(Post post){
Mutual_Posts.add(post);
}
public long GetRelationTimeInDays (){
Timestamp t=Timestamp.valueOf(LocalDateTime.now());
long x=t.getTime()-FriendsSince.getTime();
x=x/86400000;
return x;
}
public long getRelationScore(){
long x=GetRelationTimeInDays();
if(x>180){
return 15;
} else if (x>=60) {
return 12;
} else if (x>=30) {
return 9;
} else if (x>=15) {
return 6;
} else {
return 3;
}
}
}