package com.sb.cdp;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class CharacterType {

    public static enum Classification {
	RACE, CLASS;
    }

    private static final Map<Classification, Map<String, CharacterType>> REGISTERED = new HashMap<>();

    private final String name;
    private String description;
    private Classification classification;

    private CharacterType(String name, Classification classification) {
	this.name = name;
	this.classification = classification;
    }

    /**
     * Returns the name.
     * 
     * @return the name
     */
    public String getName() {
	return name;
    }

    /**
     * Returns the description.
     * 
     * @return the description
     */
    public String getDescription() {
	return description;
    }

    /**
     * Sets the value of description to that of the parameter.
     * 
     * @param description
     *            the description to set
     */
    public void setDescription(String description) {
	this.description = description;
    }

    /**
     * Returns an array of all the existing character types with this name.
     * If no types exist with this name, an empty array is returned.
     * 
     * @param typeName
     * @return an array of all the existing character types with this name.
     */
    public static CharacterType[] find(String typeName) {
	Set<CharacterType> found = new HashSet<>();

	for (Map<String, CharacterType> subregistry : REGISTERED.values()) {
	    CharacterType foundType = subregistry.get(typeName);
	    if (foundType != null)
		found.add(foundType);
	}

	return found.toArray(new CharacterType[found.size()]);
    }

    /**
     * Returns a PlayerClass with the specified name.
     * 
     * @param typeName
     *            the name of the player class. Not case sensitive.
     * @returna a PlayerClass with the specified name
     */
    public static CharacterType get(String typeName, Classification classification) {
	Map<String, CharacterType> registeredClassification = REGISTERED.get(classification);
	if (registeredClassification == null) {
	    registeredClassification = new HashMap<>();
	    REGISTERED.put(classification, registeredClassification);

	}
	CharacterType type = registeredClassification.get(typeName);
	if (type == null) {
	    type = new CharacterType(typeName, classification);
	    registeredClassification.put(typeName, type);
	}
	return type;
    }


    /**
     * Returns the type.
     * 
     * @return the type
     */
    public Classification getClassification() {
	return classification;
    }

    /**
     * Sets the value of type to that of the parameter.
     * 
     * @param type
     *            the type to set
     */
    public void setClassification(Classification type) {
	this.classification = type;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
	return "CharacterType [name=" + name + ", description=" + description + ", classification=" + classification
		+ "]";
    }
}

@@ -306,16 +306,329 @@
 p%3C%3E();%0A%0A
+    /**%0A     * Initializes the REGISTERED map to hold the appropriate buckets for each existing Classification.%0A     * @see #REGISTERED%0A     * @see #Classification%0A     */%0A    static %7B%0A%09for (Classification classification : Classification.values())%0A%09    REGISTERED.put(classification, new HashMap%3C%3E());%0A    %7D%0A    %0A
     priv
@@ -2315,28 +2315,16 @@
 ion) %7B%0A%09
-Map%3CString, 
 Characte
@@ -2332,34 +2332,13 @@
 Type
-%3E registeredClassification
+ type
  = R
@@ -2370,97 +2370,99 @@
 ion)
-;%0A%09if (registeredClassification == null) %7B%0A%09    registeredClassification = new HashMap%3C%3E(
+.get(typeName);%0A%09if (type == null) %7B%0A%09    type = new CharacterType(typeName, classification
 );%0A%09
@@ -2468,34 +2468,34 @@
 %09    REGISTERED.
-pu
+ge
 t(classification
@@ -2498,42 +2498,81 @@
 tion
-, registeredClassification);%0A%0A%09%7D%0A%09
+).put(typeName, type);%0A%09%7D%0A%09return type;%0A    %7D%0A    %0A    /**%0A     * Adds a 
 Char
@@ -2582,21 +2582,21 @@
 erType t
-ype =
+o the
  registe
@@ -2602,63 +2602,343 @@
 ered
-Classification.get(typeName);%0A%09if (type == null) %7B%0A%09   
+ ones.%0A     * Use this function with great caution, as it may overwrite previous values.%0A     * @param name%0A     * @param classification%0A     * @param description%0A     * @return the newly created CharacterType.%0A     */%0A    public static CharacterType put(String name, Classification classification, String description) %7B%0A%09CharacterType
  typ
@@ -2951,37 +2951,33 @@
 w CharacterType(
-typeN
+n
 ame, classificat
@@ -2987,23 +2987,59 @@
 );%0A%09
-    registeredC
+type.setDescription(description);%0A%09REGISTERED.get(c
 lass
@@ -3047,26 +3047,23 @@
 fication
+)
 .put(
-typeN
+n
 ame, typ
@@ -3058,35 +3058,32 @@
 ut(name, type);%0A
-%09%7D%0A
 %09return type;%0A  
@@ -3087,17 +3087,16 @@
 %0A    %7D%0A%0A
-%0A
     /**%0A

Add a put method.