package net.sourceforge.pain.db;
/**
 * All supported PAiN DB field types
 */
public final class DbType {
	public static final int BOOLEAN = 1;
	public static final int BYTE = 2;
	public static final int CHAR = 3;
	public static final int DOUBLE = 4;
	public static final int FLOAT = 5;
	public static final int INT = 6;
	public static final int LONG = 7;
	public static final int SHORT = 8;
	public static final int STRING = 9;
	public static final int REFERENCE = 10;
	public static final int ARRAY_OF_BYTE = 12;
	public static final int ARRAY_OF_CHAR = 13;
	public static final int ARRAY_OF_INT = 16;
	public static final int ARRAY_OF_STRING = 19;
	public static final int LINKED_LIST = 20; //only references list is supported!
	public static final int ARRAY_LIST = 21; //only references list is supported!
	public static final int INT_KEY_MAP = 22; // only int(Integers) allowed as keys, values are DbObject instances or null
	public static final int STRING_KEY_MAP = 23; // only Strings is allowed as keys, values are DbObject instances or null
	public static final int REFERENCE_SET = 24; // set of DbObjects
	public static final int STRING_SET = 25; // set of Strings (//todo: replace string with Serializable)
	private static String[] typeNames = new String[26];
	static {
		typeNames[BOOLEAN] = "boolean";
		typeNames[BYTE] = "byte";
		typeNames[CHAR] = "char";
		typeNames[DOUBLE] = "double";
		typeNames[FLOAT] = "float";
		typeNames[INT] = "int";
		typeNames[LONG] = "long";
		typeNames[SHORT] = "short";
		typeNames[STRING] = "String";
		typeNames[REFERENCE] = "reference";
		typeNames[ARRAY_OF_BYTE] = "byte[]";
		typeNames[ARRAY_OF_CHAR] = "char[]";
		typeNames[ARRAY_OF_INT] = "int[]";
		typeNames[ARRAY_OF_STRING] = "String[]";
		typeNames[LINKED_LIST] = "LinkedList";
		typeNames[ARRAY_LIST] = "ArrayList";
		typeNames[INT_KEY_MAP] = "IntKeyMap";
		typeNames[STRING_KEY_MAP] = "StringKeyMap";
		typeNames[REFERENCE_SET] = "ReferenceSet";
		typeNames[STRING_SET] = "StringSet";
	}
	static final boolean isValidDbType(final int type) {
		return (type > 0 && type <= 10) || type == 12 || type == 13 || type == 16 || (type >= 19 && type <= 25);
	}
	/** @return String name for the specified type*/
	public static String name(int type) {
		String name = (type > 0 && type < typeNames.length ? typeNames[type] : null);
		if (name == null) {
			throw new IllegalArgumentException("Illegal type:" + type);
		}
		return name;
	}
}