2025-03-11 00:23:54 +01:00
|
|
|
package game.init;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2025-03-16 17:40:47 +01:00
|
|
|
import com.google.common.collect.Maps;
|
2025-03-11 00:23:54 +01:00
|
|
|
|
|
|
|
public class RegistrySimple<K, V> implements IRegistry<K, V>
|
|
|
|
{
|
|
|
|
protected final Map<K, V> registryObjects = this.createUnderlyingMap();
|
|
|
|
|
|
|
|
protected Map<K, V> createUnderlyingMap()
|
|
|
|
{
|
|
|
|
return Maps.<K, V>newHashMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
public V getObject(K name)
|
|
|
|
{
|
|
|
|
return this.registryObjects.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register an object on this registry.
|
|
|
|
*/
|
|
|
|
public void putObject(K key, V value)
|
|
|
|
{
|
|
|
|
if (key == null) {
|
|
|
|
throw new NullPointerException("Key is null");
|
|
|
|
}
|
|
|
|
if (value == null) {
|
|
|
|
throw new NullPointerException("Value is null");
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (this.registryObjects.containsKey(key))
|
|
|
|
// {
|
|
|
|
// Log.CONFIG.debug("Füge doppelten Schlüssel \'" + key + "\' der Registry hinzu");
|
|
|
|
// }
|
|
|
|
|
|
|
|
this.registryObjects.put(key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Set<K> getKeys()
|
|
|
|
{
|
|
|
|
return Collections.<K>unmodifiableSet(this.registryObjects.keySet());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does this registry contain an entry for the given key?
|
|
|
|
*/
|
|
|
|
public boolean containsKey(K key)
|
|
|
|
{
|
|
|
|
return this.registryObjects.containsKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Iterator<V> iterator()
|
|
|
|
{
|
|
|
|
return this.registryObjects.values().iterator();
|
|
|
|
}
|
|
|
|
}
|