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
public static final int STRING_MAP = 26; // map of strings with values of Strings
private static String[] typeNames = new String[27];
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";
typeNames[STRING_MAP] = "StringMap";
}
static final boolean isValidDbType(final int type) {
return (type > 0 && type <= 10) || type == 12 || type == 13 || type == 16 || (type >= 19 && type <= 26);
}
/**
* @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;
}
public static boolean isArray(int type) {
return type == ARRAY_OF_BYTE || type == ARRAY_OF_CHAR || type == ARRAY_OF_INT || type == ARRAY_OF_STRING;
}
public static boolean isCollection(int type) {
switch (type) {
case LINKED_LIST:
case ARRAY_LIST:
case INT_KEY_MAP:
case STRING_KEY_MAP:
case REFERENCE_SET:
case STRING_SET:
case STRING_MAP:
return true;
}
return false;
}
}