package net.acomputerdog.core.storage;

import net.acomputerdog.core.identity.Identifiable;

import java.util.*;

public class Registry<T extends Identifiable> {
    private final Map<String, T> defMap;
    private final Map<String, T> idMap;

    public Registry() {
        defMap = new LinkedHashMap<String, T>();
        idMap = new LinkedHashMap<String, T>();
    }

    public <T2 extends T> T2 register(T2 item) {
        defMap.put(item.getDefinition(), item);
        idMap.put(item.getId(), item);
        return item;
    }

    public boolean isDefined(String def) {
        return defMap.containsKey(def);
    }

    public boolean isDefined(T item) {
        return defMap.containsValue(item);
    }

    public T getFromDef(String def) {
        return defMap.get(def);
    }

    public T getFromId(String id) {
        return idMap.get(id);
    }

    public Collection<T> getItems() {
        return defMap.values();
    }

    public Set<String> getDefinitions() {
        return Collections.unmodifiableSet(defMap.keySet());
    }

    public Set<String> getIds() {
        return Collections.unmodifiableSet(idMap.keySet());
    }
}

@@ -111,945 +111,2288 @@
 *;%0A%0A
-public class Registry%3CT extends Identifiable%3E %7B%0A    private final Map%3CString, T%3E defMap;%0A    private final Map%3CString, T%3E idMap;%0A%0A    public Registry() %7B%0A        defMap = new LinkedHashMap%3CString, T%3E();%0A        idMap = new LinkedHashMap%3CString, T%3E();%0A    %7D%0A%0A    public %3CT2 extends T%3E T2 register(T2 item) %7B%0A        defMap.put(item.getDefinition(), item);%0A        idMap.put(item.getId(), item);%0A        return item;%0A    %7D%0A%0A    public boolean isDefined(String def) %7B%0A        return defMap.containsKey(def);%0A    %7D%0A%0A    public boolean isDefined(T item) %7B%0A        return defMap.containsValue(item);%0A    %7D%0A%0A    public T getFromDef(String def) %7B%0A        return defMap.get(def);%0A    %7D%0A%0A    public T getFromId(String id) %7B%0A        return idMap.get(id);%0A    %7D%0A%0A    public Collection%3CT%3E getItems() %7B%0A        return defMap.values();%0A    %7D%0A%0A    public Set%3CString%3E getDefinitions() %7B%0A        return Collections.unmodifiableSet(defMap.keySet());%0A    %7D%0A
+/**%0A * A registry that stores Identifiables%0A *%0A * @param %3CT%3E The type of object to store%0A */%0Apublic class Registry%3CT extends Identifiable%3E %7B%0A    /**%0A     * Map of definitions to identifiables%0A     */%0A%0A    private final Map%3CString, T%3E defMap;%0A    /**%0A     * Map of ids to identifiables%0A     */%0A    private final Map%3CString, T%3E idMap;%0A%0A    /**%0A     * Creates a new Identifiable%0A     */%0A    public Registry() %7B%0A        defMap = new LinkedHashMap%3CString, T%3E();%0A        idMap = new LinkedHashMap%3CString, T%3E();%0A    %7D%0A%0A    /**%0A     * Registers an Identifiable%0A     * @param item The identifiable to add%0A     * @param %3CT2%3E The type of the Identifable%0A     * @return Return the item%0A     */%0A    public %3CT2 extends T%3E T2 register(T2 item) %7B%0A        defMap.put(item.getDefinition(), item);%0A        idMap.put(item.getId(), item);%0A        return item;%0A    %7D%0A%0A    /**%0A     * Check if the definition maps to a known identifiable%0A     * @param def The definition%0A     * @return Return true if the definition is defined%0A     */%0A    public boolean isDefined(String def) %7B%0A        return defMap.containsKey(def);%0A    %7D%0A%0A    /**%0A     * Check if an item is defined in this registry%0A     * @param item the item%0A     * @return Return true if the item is defined%0A     */%0A    public boolean isDefined(T item) %7B%0A        return defMap.containsValue(item);%0A    %7D%0A%0A    /**%0A     * gets an item from its definition%0A     * @param def The definition%0A     * @return Return the item%0A     */%0A    public T getFromDef(String def) %7B%0A        return defMap.get(def);%0A    %7D%0A%0A    /**%0A     * Gets an item from its id%0A     * @param id The ID%0A     * @return Return the item%0A     */%0A    public T getFromId(String id) %7B%0A        return idMap.get(id);%0A    %7D%0A%0A    /**%0A     * Get a collection of all items in this registry%0A     * @return Return a collection of all items in this registry%0A     */%0A    public Collection%3CT%3E getItems() %7B%0A        return defMap.values();%0A    %7D%0A%0A    /**%0A     * Get a set of all definitions in this registry%0A     * @return Return a set of all definitions in this Registry%0A     */%0A    public Set%3CString%3E getDefinitions() %7B%0A        return Collections.unmodifiableSet(defMap.keySet());%0A    %7D%0A%0A    /**%0A     * Get a set of all ids in this registry%0A     * @return Return a set of all ids in this Registry%0A     */
 %0A   

Add comments to Registry