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

Last change on this file was 46, checked in by ruud, 20 months ago

Fixed small issues in domaineditor.

File size: 1.3 KB
RevLine 
[46]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 AvailableParty available = availableParties.get(id);
46 if (available != null) {
47 availableParties.remove(id);
48 available.free();
49 notifyListeners(id);
50 }
51 }
52
53 @Override
54 public void replace(AvailableParty entity) {
55 put(entity);
56 }
57
58}
Note: See TracBrowser for help on using the repository browser.