Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.84 KB | None | 0 0
  1.  
  2.  
  3. /**
  4.  *
  5.  * @author lmoentje
  6.  */
  7. import java.io.Serializable;
  8. import java.util.HashSet;
  9. import java.util.Iterator;
  10. import java.util.Objects;
  11.  
  12.  
  13. public class Account implements Serializable {
  14.    
  15.     private static final long serialVersionUID = 19;
  16.     private String firstName;
  17.     private String lastName;
  18.     private String gender;
  19.     private String email;
  20.     private String login;
  21.     private String password;
  22.     private HashSet<Account> friends;
  23.     private HashSet<Post> wall;
  24.     private HashSet<Integer> likes;
  25.    
  26.  
  27.     public Account(String firstName, String lastName, String gender, String email, String login, String password) {
  28.         this.firstName = firstName;
  29.         this.lastName = lastName;
  30.         this.gender = gender;
  31.         this.email = email;
  32.         this.login = login;
  33.         this.password = password;
  34.         this.friends = new HashSet<>();
  35.         this.wall = new HashSet<>();
  36.         this.likes = new HashSet<>();
  37.        
  38.     }
  39.  
  40.     public String getFirstName() {
  41.         return firstName;
  42.     }
  43.  
  44.     public void setFirstName(String firstName) {
  45.         this.firstName = firstName;
  46.     }
  47.  
  48.     public String getLastName() {
  49.         return lastName;
  50.     }
  51.  
  52.     public void setLastName(String lastNamen) {
  53.         this.lastName = lastNamen;
  54.     }
  55.  
  56.     public String getGender() {
  57.         return gender;
  58.     }
  59.  
  60.     public void setGender(String gender) {
  61.         this.gender = gender;
  62.     }
  63.  
  64.     public String getEmail() {
  65.         return email;
  66.     }
  67.  
  68.     public void setEmail(String email) {
  69.         this.email = email;
  70.     }
  71.  
  72.     public String getLogin() {
  73.         return login;
  74.     }
  75.  
  76.     public void setLogin(String login) {
  77.         this.login = login;
  78.     }
  79.  
  80.     public String getPassword() {
  81.         return password;
  82.     }
  83.  
  84.     public void setPassword(String password) {
  85.         this.password = password;
  86.     }
  87.  
  88.     public HashSet<Account> getFriends() {
  89.         return friends;
  90.     }
  91.  
  92.     public HashSet<Post> getWall() {
  93.         return wall;
  94.     }
  95.  
  96.     public HashSet<Integer> getLikes() {
  97.         return likes;
  98.     }
  99.  
  100.     @Override
  101.     public String toString() {
  102.        
  103.         return (this.getFirstName()+" "+this.getLastName()+" ("+getFriends().size()+" vrienden)");
  104.                
  105.     }
  106.  
  107.    
  108.     public String getCSV(){
  109.         return firstName+";"+lastName+";"+gender+";"+email+";"+login+";"+password;
  110.        
  111.     }
  112.  
  113.    
  114.     //OMP: SPECIALE EQUALS!!
  115.     @Override
  116.     public boolean equals(Object obj) {
  117.         boolean isEqual = false;
  118.         if((obj!=null)&&(obj instanceof Account)){
  119.             final Account other = (Account) obj;
  120.         if (!Objects.equals(this.firstName, other.firstName)) {
  121.             return false;
  122.         }
  123.         if (!Objects.equals(this.lastName, other.lastName)) {
  124.             return false;
  125.         }
  126.         if (!Objects.equals(this.gender, other.gender)) {
  127.             return false;
  128.         }
  129.         if (!Objects.equals(this.email, other.email)) {
  130.             return false;
  131.         }
  132.         if (!Objects.equals(this.login, other.login)) {
  133.             return false;
  134.         }
  135.         if (!Objects.equals(this.password, other.password)) {
  136.             return false;
  137.         }
  138.        
  139.         if (!Objects.equals(this.likes, other.likes)) {
  140.             return false;
  141.         }
  142.            
  143.         if (!equalsFriends(other)){
  144.             return false;
  145.         }
  146.        
  147.         if (!equalsWall(other)) {
  148.             return false;
  149.         }
  150.        
  151.         return true;
  152.         }
  153.         return isEqual;
  154.            
  155.        
  156.         }
  157.        
  158.  
  159.    
  160.     public boolean equalsFriends(Object o){
  161.        
  162.         Account acc = (Account) o;
  163.         boolean a = true;
  164.         boolean b = true;
  165.         for(Account vriendA : acc.friends){
  166.             boolean found = false;
  167.             for(Account vriendB : this.friends){
  168.                 if(vriendA.getLogin().equals(vriendB.getLogin()))
  169.                     found = true;
  170.                
  171.             }
  172.             if (!found){
  173.                 return false;
  174.             }
  175.            
  176.         }
  177.        
  178.         for(Account vriendA : this.friends){
  179.             boolean found = false;
  180.             for(Account vriendB : acc.friends){
  181.                 if(vriendA.getLogin().equals(vriendB.getLogin()))
  182.                         found = true;
  183.             }
  184.            
  185.             if(!found)
  186.                 return false;
  187.         }
  188.            
  189.         return true;
  190.        
  191.        
  192.        
  193.     }
  194.    
  195.     public boolean equalsWall(Object o){
  196.         Account acc = (Account) o;
  197.         boolean a = true;
  198.         boolean b = true;
  199.         for(Post post : acc.wall){
  200.             boolean found = false;
  201.             for(Post postB : this.wall){
  202.                 if(post.getPostID().equals(postB.getPostID()))
  203.                     found = true;
  204.                
  205.             }
  206.             if (!found){
  207.                 return false;
  208.             }
  209.            
  210.         }
  211.        
  212.         for(Post post : this.wall){
  213.             boolean found = false;
  214.             for(Post postB : acc.wall){
  215.                 if(post.getPostID().equals(postB.getPostID()))
  216.                         found = true;
  217.             }
  218.            
  219.             if(!found)
  220.                 return false;
  221.         }
  222.            
  223.         return true;
  224.        
  225.     }
  226.    
  227.    
  228.  
  229.     @Override
  230.     public int hashCode() {
  231.         int hash = 7;
  232.         hash = 97 * hash + Objects.hashCode(this.firstName);
  233.         hash = 97 * hash + Objects.hashCode(this.lastName);
  234.         hash = 97 * hash + Objects.hashCode(this.gender);
  235.         hash = 97 * hash + Objects.hashCode(this.email);
  236.         hash = 97 * hash + Objects.hashCode(this.login);
  237.         hash = 97 * hash + Objects.hashCode(this.password);
  238.         return hash;
  239.     }
  240.  
  241.    
  242.    
  243.    
  244.    
  245.    
  246.    
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement