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

Last change on this file since 3 was 1, checked in by bart, 5 years ago

Initial Release

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> 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.