source: src/main/java/geniusweb/partiesserver/repository/AvailablePartiesRepo.java@ 22

Last change on this file since 22 was 8, checked in by bart, 5 years ago

Release 1.1.0

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