-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFacePamphletDatabase.java
More file actions
89 lines (74 loc) · 2.36 KB
/
Copy pathFacePamphletDatabase.java
File metadata and controls
89 lines (74 loc) · 2.36 KB
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
86
87
88
89
/*
* 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 {
/**
* Constructor
* This method takes care of any initialization needed for
* the database.
*/
public FacePamphletDatabase() {
profileDataBase = new HashMap<String, FacePamphletProfile>();
}
/**
* 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.
*/
public void addProfile(FacePamphletProfile profile) {
// You fill this in
String name = profile.getName();
profileDataBase.put(name, 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) {
if(profileDataBase.containsKey(name)) {
return profileDataBase.get(name);
} else {
return null;
}
}
/**
* 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) {
if (profileDataBase.containsKey(name)) {
profileDataBase.remove(name);
}
Iterator<String> iter = profileDataBase.keySet().iterator();
while(iter.hasNext()) {
String key = iter.next();
FacePamphletProfile profile = profileDataBase.get(key);
profile.removeFriend(name);
}
}
/**
* 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) {
if(profileDataBase.containsKey(name)) {
return true;
} else {
return false;
}
}
//
private HashMap<String, FacePamphletProfile> profileDataBase;
}