package geniusweb.partiesserver.repository; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import tudelft.utilities.listener.DefaultListenable; import tudelft.utilities.repository.Repository; /** * Stores all currently available parties that can be run. */ public class AvailablePartiesRepo extends DefaultListenable implements Repository { private static final AvailablePartiesRepo instance = new AvailablePartiesRepo(); private Map availableParties = new HashMap<>(); private AvailablePartiesRepo() { } public static AvailablePartiesRepo instance() { return instance; } @Override public Collection list() { return Collections.unmodifiableCollection(availableParties.values()); } @Override public AvailableParty get(String id) { return availableParties.get(id); } @Override public void put(AvailableParty entity) { availableParties.put(entity.getID(), entity); notifyListeners(entity.getID()); } @Override public void remove(String id) { AvailableParty available = availableParties.get(id); if (available != null) { availableParties.remove(id); available.free(); notifyListeners(id); } } @Override public void replace(AvailableParty entity) { put(entity); } }