Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package facebook;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.TreeMap;
- public class Facebook {
- Map<String, Person> persons = new TreeMap<String, Person>();
- Person p;
- Group g;
- List<Person> per;
- public void addPerson(String code, String name, String surname)
- throws PersonExistsException {
- p = new Person(code, name, surname);
- persons.put(code, p);
- if (persons.containsKey(code)) {
- throw new PersonExistsException();
- }
- }
- public String getPerson(String code) throws NoSuchCodeException {
- if (!persons.containsKey(code)) {
- throw new NoSuchCodeException();
- }
- return persons.toString();
- }
- public void addFriendship(String codePerson1, String codePerson2)
- throws NoSuchCodeException {
- persons.put(codePerson1, p);
- persons.put(codePerson2, p);
- if (!persons.containsKey(codePerson2)
- || !persons.containsKey(codePerson1)) {
- throw new NoSuchCodeException();
- }
- }
- public Collection<String> listOfFriends(String codePerson)
- throws NoSuchCodeException {
- if (persons.containsKey(codePerson))
- return persons.keySet();
- else {
- throw new NoSuchCodeException();
- }
- }
- public Collection<String> friendsOfFriends(String codePerson)
- throws NoSuchCodeException {
- // if(persons.containsKey(codePerson)){}
- return null;
- // else {throw new NoSuchCodeException();}
- }
- public Collection<String> friendsOfFriendsNoRepitition(String codePerson)
- throws NoSuchCodeException {
- // Iterator con if e remove
- return null;
- }
- public void addGroup(String groupName) {
- g = new Group(groupName);
- List<Group> groups = new LinkedList<Group>();
- // Group g = new Group( groupName);
- groups.add(g);
- }
- public Collection<String> listOfGroups() {
- return null;
- }
- public void addPersonToGroup(String codePerson, String groupName) {
- }
- public Collection<String> listOfPeopleInGroup(String groupName) {
- return null;
- }
- public String personWithLargestNumberOfFriends() {
- // dovrei fazre un iterator e usare un contatore per vedere chi รจ
- return null;
- }
- public String personWithMostFriendsOfFriends() {
- return null;
- }
- public String largestGroup() {
- return null;
- }
- public String personInLargestNumberOfGroups() {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment