Advertisement
Guest User

Untitled

a guest
Apr 27th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. package com.usthb.modeles;
  2.  
  3. import java.io.Serializable;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6.  
  7.  
  8. public class Abonne implements Serializable{
  9.  
  10. private static int cpt=0;
  11. private final Integer codeAbonne;
  12. private String nom,prenom;
  13. private String dateN;
  14. private Categorie cat;
  15. private String username;
  16. private String password;
  17. private String specialite="",nivEtude="",fonction="";
  18. private HashMap<String,Abonne> listeAmis = new HashMap<String,Abonne>();
  19. private ArrayList<Invitation> ensInvitations = new ArrayList<Invitation>(); //l'abonné est la clé
  20. private ArrayList<Post> mur = new ArrayList<Post>();
  21. private ArrayList<Notification> ensNotifications = new ArrayList<Notification>();
  22. private HashMap<String,Groupe> ensGroupes = new HashMap<String,Groupe>(); //la clé est le nom du groupe
  23. private ArrayList<Post> actu = new ArrayList<Post>();
  24. private boolean online;
  25.  
  26. //CONSTRUCTEUR
  27. public Abonne(String nom, String prenom, String dateN, String cat,String username,String password,String fonction,String specialite,String nivEtude){
  28.  
  29. codeAbonne=cpt++;
  30. this.nom = nom;
  31. this.prenom = prenom;
  32. this.dateN = dateN;
  33. this.cat = Categorie.valueOf(cat.toLowerCase());
  34. this.username = username;
  35. this.password = password;
  36. this.specialite = specialite;
  37. this.nivEtude = nivEtude;
  38. this.fonction = fonction;
  39.  
  40. }
  41.  
  42. //SETTERS AND GETTERS
  43. public Integer getCode() {
  44. return codeAbonne;
  45. }
  46.  
  47. public Categorie getCategorie() {
  48. return cat;
  49. }
  50.  
  51. public String getPrenom() {
  52. return prenom;
  53. }
  54.  
  55. public void setPrenom(String prenom) {
  56. this.prenom = prenom;
  57. }
  58.  
  59. public String getNom() {
  60. return nom;
  61. }
  62.  
  63. public void setNom(String nom) {
  64. this.nom = nom;
  65. }
  66.  
  67. public String getDateNaissance() {
  68. return dateN;
  69. }
  70.  
  71. public void setDateNaissance(String dateN) {
  72. this.dateN = dateN;
  73. }
  74.  
  75. public String getUsername() {
  76. return username;
  77. }
  78.  
  79. public void setUsername(String username) {
  80.  
  81. this.username = username;
  82. }
  83.  
  84. public String getPassword() {
  85. return password;
  86. }
  87.  
  88. public void setPassword(String password) {
  89. this.password = password;
  90. }
  91.  
  92. public String getSpecialite() {
  93. return specialite;
  94. }
  95.  
  96. public void setSpecialite(String specialite) {
  97. this.specialite = specialite;
  98. }
  99.  
  100. public String getNivEtude() {
  101. return nivEtude;
  102. }
  103.  
  104. public void setNivEtude(String nivEtude) {
  105. this.nivEtude = nivEtude;
  106. }
  107.  
  108. public String getFonction() {
  109. return fonction;
  110. }
  111.  
  112. public void setFonction(String fonction) {
  113. this.fonction = fonction;
  114. }
  115. public boolean isOnline() {
  116. return online;
  117. }
  118.  
  119. public void setOnline(boolean online) {
  120. this.online = online;
  121. }
  122.  
  123. public ArrayList getNotifications(){
  124. return ensNotifications;
  125. }
  126.  
  127.  
  128.  
  129. //METHODES
  130.  
  131. //LISTE D'AMIS
  132.  
  133.  
  134. public HashMap<String,Abonne> getListeAmis(){
  135. return listeAmis;
  136. }
  137.  
  138. public void afficherAmis() {
  139. for(Abonne ami:listeAmis.values()) {
  140. System.out.println(ami.nom + " " + ami.prenom);
  141. }
  142.  
  143. }
  144.  
  145. public boolean sontAmis(Abonne ami) {
  146. return listeAmis.containsKey(ami.username);
  147. }
  148.  
  149. public boolean ontAmisCommuns(Abonne user) {
  150. for(String code: listeAmis.keySet()) {
  151. if(user.listeAmis.containsKey(code)) return true;
  152. }
  153. return false;
  154. }
  155.  
  156.  
  157. public void ajouterActuAmis(Post p){
  158. if(p!=null){
  159. for(Abonne abo:listeAmis.values()){
  160. abo.ajouterActu(p);
  161. }
  162. }
  163. }
  164.  
  165. public void supprimerAmi(String ami){
  166. listeAmis.remove(ami);
  167. }
  168.  
  169. public void ajouterAmi(Abonne ami){
  170. listeAmis.put(ami.getUsername(),ami);
  171. }
  172.  
  173. public void supprimerTousLesAmis(){
  174. for(Abonne ami:listeAmis.values()){
  175. listeAmis.remove(ami.getUsername());
  176. ami.listeAmis.remove(username);
  177. }
  178. }
  179.  
  180.  
  181. //LISTE D'INVITATIONS
  182.  
  183. public ArrayList getInvitations(){
  184. return ensInvitations;
  185. }
  186.  
  187. public void ajouterInvitation(Invitation inv){
  188. ensInvitations.add(inv);
  189. }
  190.  
  191. public void refuserInvitation(String user){
  192. for(Invitation invit: ensInvitations){
  193. if(invit.getEmetteur().equals(user)){
  194. invit.setEtat(InvitationEtat.refusée);
  195. break;}
  196. }
  197.  
  198. }
  199. public void accepterInvitation(String user){
  200. for(Invitation invit: ensInvitations){
  201. if(invit.getEmetteur().equals(user)){
  202. invit.setEtat(InvitationEtat.acceptée);
  203. break;}
  204. }
  205. }
  206. public void afficherInvitations() {
  207. for(Invitation inv: ensInvitations) {
  208. System.out.println("< "+inv.getEmetteur()+" > vous a envoyé un message d'invitation: "+inv.getMessage() +"\nEtat de la demande d'ajout: "+inv.getEtat());
  209. }
  210. }
  211.  
  212.  
  213. // METHODES MUR
  214.  
  215. public void ajouterPost(Post p) {
  216. mur.add(p);
  217. }
  218.  
  219. public void supprimerPost(Post p) {//l'abonné supprime le post qu'il veut de son mur
  220. mur.remove(p);
  221. }
  222.  
  223.  
  224. public void afficherMur(String visibilite) {//double parcours :(
  225. for(Post p: mur) { //affichage des posts épinglés
  226. if(p.isEpinglee())
  227. p.afficherPost(this.username,Visibilite.valueOf(visibilite.toLowerCase()).getNiveau() );
  228. }
  229. for(Post p: mur) {//affichage des posts restants
  230. if(!p.isEpinglee())
  231. p.afficherPost(this.username,Visibilite.valueOf(visibilite.toLowerCase()).getNiveau() );
  232. }
  233. }
  234.  
  235. //METHODES NOTIFICATIONS
  236.  
  237. public void ajouterNotification(Notification notif) {
  238. ensNotifications.add(notif);
  239. }
  240.  
  241. public void afficherNotifications() {
  242. for(Notification notif : ensNotifications) {
  243. notif.afficherNotification();
  244. }
  245. }
  246.  
  247.  
  248.  
  249.  
  250. //METHODES GROUPES
  251.  
  252. public void ajouterGroupe(Groupe grp) {
  253. ensGroupes.put(grp.getGroupName(), grp);
  254. }
  255.  
  256. public void ajouterGroupe(String grp) {
  257. if(ServeurMiniFacebook.groupeExiste(grp))
  258. ensGroupes.put(grp, ServeurMiniFacebook.getGroupe(grp));
  259. }
  260.  
  261. public void quitterGroupe(Groupe grp) {
  262. ensGroupes.remove(grp.getGroupName());
  263. }
  264.  
  265. public void quitterGroupe(String grp) {
  266. ensGroupes.remove(grp);
  267. }
  268.  
  269. public void afficherGroupes() {
  270. for(String grp : ensGroupes.keySet()) {
  271. System.out.println(grp);
  272. }
  273. }
  274.  
  275. //METHODES FIL D'ACTUALITES
  276.  
  277. public void ajouterActu(Post p){
  278. if(p!=null)
  279. actu.add(p);
  280. }
  281.  
  282.  
  283.  
  284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement