package com.hyperfresh.mchyperchat.field;

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

public class FieldManager
{
	/**
	 * The map where all the key-field pairs are stored.
	 */
	private HashMap<String, Field> map = new HashMap<>();

	/**
	 * Adds a static key-value field to this list.
	 * Please use this if your field's value is a constant.
	 *
	 * @param keys  an array of keys to use for this field
	 * @param value the field value
	 */
	public void addField(String[] keys, String value)
	{
		addField(new ConstantField(value, keys));
	}

	public void addField(String key, String value)
	{
		addField(new ConstantField(value, key));
	}

	/**
	 * Adds a field to this list.
	 * If your field returns a constant value, please use <code>addField(keys, value)</code> instead.
	 *
	 * @param field the field
	 */
	public void addField(Field field)
	{
		for(String key: field.getFieldNames())
		{
			map.put(key, field);
		}
	}

	/**
	 * Gets a field from the list by a key.
	 * It will return null if the key does not exist.
	 *
	 * @param key the key of the field
	 * @return the field, or null
	 */
	public Field getField(String key)
	{
		return map.get(key);
	}

	/**
	 * Gets if the key exists in the list.
	 *
	 * @param key the key of the field
	 * @return true if the key exists
	 */
	public boolean fieldExists(String key)
	{
		return map.containsKey(key);
	}

	/**
	 * Gets an <code>EntrySet</code> where each entry is a string key and a field value.
	 *
	 * @return the entrySet of this list.
	 */
	public Set<Map.Entry<String, Field>> entrySet()
	{
		return map.entrySet();
	}

	/**
	 * Clears the entire list of field.
	 */
	public void clear()
	{
		map = new HashMap<>();
	}

}

@@ -945,24 +945,711 @@
 d);%0A%09%09%7D%0A%09%7D%0A%0A
+%09/**%0A%09 * Attempts to add inner classes that extend %7B@code Field%7D.%0A%09 *%0A%09 * It will try to instantiate each class without arguments and will%0A%09 * ignore the class if it throws an exception.%0A%09 *%0A%09 * @param clazz%0A%09 * @return%0A%09 */%0A%09public int addFieldContainer(Class%3C?%3E clazz)%0A%09%7B%0A%09%09int fieldCount = 0;%0A%0A%09%09for(Class%3C?%3E c: clazz.getClasses())%0A%09%09%7B%0A%09%09%09if(Field.class.isAssignableFrom(c))%0A%09%09%09%7B%0A%09%09%09%09Class%3C? extends Field%3E fieldClass = (Class%3C? extends Field%3E)c;%0A%0A%09%09%09%09try%0A%09%09%09%09%7B%0A%09%09%09%09%09Field field = fieldClass.newInstance();%0A%09%09%09%09%09addField(field);%0A%09%09%09%09%09fieldCount++;%0A%09%09%09%09%7D catch (InstantiationException %7C IllegalAccessException e)%0A%09%09%09%09%7B%0A%09%09%09%09%09//ignore this field%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09return fieldCount;%0A%09%7D%0A%0A
 %09/**%0A%09 * Get

add addFields() to FieldManager