Line | |
---|
1 | package geniusweb.partiesserver.repository;
|
---|
2 |
|
---|
3 | import java.util.Collection;
|
---|
4 | import java.util.Collections;
|
---|
5 | import java.util.HashMap;
|
---|
6 | import java.util.Map;
|
---|
7 |
|
---|
8 | import tudelft.utilities.listener.DefaultListenable;
|
---|
9 | import tudelft.utilities.repository.Repository;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Stores all currently available parties that can be run.
|
---|
13 | */
|
---|
14 | public class AvailablePartiesRepo extends DefaultListenable<String> implements Repository<String, AvailableParty> {
|
---|
15 | private static final AvailablePartiesRepo instance = new AvailablePartiesRepo();
|
---|
16 |
|
---|
17 | private Map<String, AvailableParty> availableParties = new HashMap<>();
|
---|
18 |
|
---|
19 | private AvailablePartiesRepo() {
|
---|
20 | }
|
---|
21 |
|
---|
22 | public static AvailablePartiesRepo instance() {
|
---|
23 | return instance;
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public Collection<AvailableParty> list() {
|
---|
28 | return Collections.unmodifiableCollection(availableParties.values());
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override
|
---|
32 | public AvailableParty get(String id) {
|
---|
33 | return availableParties.get(id);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void put(AvailableParty entity) {
|
---|
38 | availableParties.put(entity.getID(), entity);
|
---|
39 | notifyChange(entity.getID());
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public void remove(String id) {
|
---|
44 | availableParties.remove(id);
|
---|
45 | notifyChange(id);
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public void replace(AvailableParty entity) {
|
---|
50 | put(entity);
|
---|
51 | }
|
---|
52 |
|
---|
53 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.