-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCategory.java
70 lines (54 loc) · 1.53 KB
/
Category.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
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Category<E extends Data<?>> {
private String categoryName;
private List<E> dataSet;
private List<String> friends;
public Category(String categoryName)
{
this.categoryName = categoryName;
this.dataSet = new ArrayList<E>();
this.friends = new ArrayList<String>();
}
public String getCategoryName()
{
return this.categoryName;
}
public List<E> getData()
{
return Collections.unmodifiableList(dataSet);
}
public boolean contains(E data)
{
return this.dataSet.contains(data);
}
public boolean contains(String friend)
{
return this.friends.contains(friend);
}
public List<String> getFriends()
{
return friends;
}
public void addFriend(String friend) throws ExistingFriendException {
if(this.friends.contains(friend)) throw new ExistingFriendException();
this.friends.add(friend);
}
public void addData(E data) throws DuplicateDataException {
if(dataSet.contains(data)) throw new DuplicateDataException();
this.dataSet.add(data);
}
public int numData() {
return this.dataSet.size();
}
public int numFriends() {
return this.friends.size();
}
public boolean removeDataIfExists(E data) {
return this.dataSet.remove(data);
}
public boolean removeFriend(String friend) {
return this.friends.remove(friend);
}
}