spiny94

Untitled

Sep 3rd, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. package facebook;
  2.  
  3. import java.util.Collection;
  4. import java.util.Collections;
  5. import java.util.HashMap;
  6. import java.util.LinkedList;
  7. import java.util.List;
  8. import java.util.Map;
  9. import java.util.TreeMap;
  10.  
  11. public class Facebook {
  12.     Map<String, Person> persons = new TreeMap<String, Person>();
  13.     Person p;
  14.     Group g;
  15.     List<Person> per;
  16.  
  17.     public void addPerson(String code, String name, String surname)
  18.             throws PersonExistsException {
  19.         p = new Person(code, name, surname);
  20.  
  21.         persons.put(code, p);
  22.         if (persons.containsKey(code)) {
  23.             throw new PersonExistsException();
  24.         }
  25.     }
  26.  
  27.     public String getPerson(String code) throws NoSuchCodeException {
  28.         if (!persons.containsKey(code)) {
  29.             throw new NoSuchCodeException();
  30.         }
  31.  
  32.         return persons.toString();
  33.     }
  34.  
  35.     public void addFriendship(String codePerson1, String codePerson2)
  36.             throws NoSuchCodeException {
  37.  
  38.         persons.put(codePerson1, p);
  39.         persons.put(codePerson2, p);
  40.         if (!persons.containsKey(codePerson2)
  41.                 || !persons.containsKey(codePerson1)) {
  42.             throw new NoSuchCodeException();
  43.         }
  44.  
  45.     }
  46.  
  47.     public Collection<String> listOfFriends(String codePerson)
  48.             throws NoSuchCodeException {
  49.         if (persons.containsKey(codePerson))
  50.  
  51.             return persons.keySet();
  52.         else {
  53.             throw new NoSuchCodeException();
  54.         }
  55.     }
  56.  
  57.     public Collection<String> friendsOfFriends(String codePerson)
  58.             throws NoSuchCodeException {
  59.  
  60.         // if(persons.containsKey(codePerson)){}
  61.         return null;
  62.         // else {throw new NoSuchCodeException();}
  63.     }
  64.  
  65.     public Collection<String> friendsOfFriendsNoRepitition(String codePerson)
  66.             throws NoSuchCodeException {
  67.  
  68.         // Iterator con if e remove
  69.         return null;
  70.     }
  71.  
  72.     public void addGroup(String groupName) {
  73.         g = new Group(groupName);
  74.         List<Group> groups = new LinkedList<Group>();
  75.         // Group g = new Group( groupName);
  76.         groups.add(g);
  77.     }
  78.  
  79.     public Collection<String> listOfGroups() {
  80.  
  81.         return null;
  82.     }
  83.  
  84.     public void addPersonToGroup(String codePerson, String groupName) {
  85.  
  86.     }
  87.  
  88.     public Collection<String> listOfPeopleInGroup(String groupName) {
  89.         return null;
  90.     }
  91.  
  92.     public String personWithLargestNumberOfFriends() {
  93.         // dovrei fazre un iterator e usare un contatore per vedere chi รจ
  94.  
  95.         return null;
  96.     }
  97.  
  98.     public String personWithMostFriendsOfFriends() {
  99.         return null;
  100.     }
  101.  
  102.     public String largestGroup() {
  103.         return null;
  104.     }
  105.  
  106.     public String personInLargestNumberOfGroups() {
  107.         return null;
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment