-
Notifications
You must be signed in to change notification settings - Fork 0
/
FacePamphletDatabase.java
85 lines (56 loc) · 2.08 KB
/
FacePamphletDatabase.java
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
/*
* File: FacePamphletDatabase.java
* -------------------------------
* This class keeps track of the profiles of all users in the
* FacePamphlet application. Note that profile names are case
* sensitive, so that "ALICE" and "alice" are NOT the same name.
*/
import java.util.*;
public class FacePamphletDatabase implements FacePamphletConstants {
public void assignName(String personName){
person=new FacePamphletProfile(personName);
addProfile(person);
}
/**
* This method adds the given profile to the database. If the
* name associated with the profile is the same as an existing
* name in the database, the existing profile is replaced by
* the new profile passed in.
*/
private void addProfile(FacePamphletProfile profile) {
if(!allPeople.containsKey(profile.getName())){
allPeople.put(profile.getName(), profile);
}
}
/**
* This method returns the profile associated with the given name
* in the database. If there is no profile in the database with
* the given name, the method returns null.
*/
public FacePamphletProfile getProfile(String name) {
return allPeople.get(name);
}
/**
* This method removes the profile associated with the given name
* from the database. It also updates the list of friends of all
* other profiles in the database to make sure that this name is
* removed from the list of friends of any other profile.
*
* If there is no profile in the database with the given name, then
* the database is unchanged after calling this method.
*/
public void deleteProfile(String name) {
allPeople.remove(name);
//remove person from all friend lists!
}
/**
* This method returns true if there is a profile in the database
* that has the given name. It returns false otherwise.
*/
public boolean containsProfile(String name) {
// You fill this in. Currently always returns false.
return allPeople.containsKey(name);
}
private Map<String,FacePamphletProfile> allPeople=new HashMap<String,FacePamphletProfile>();
private FacePamphletProfile person;
}