Java Utililty Methods Type Convert

List of utility methods to do Type Convert

Description

The list of methods to do Type Convert are organized into topic(s).

Method

ClasstypeToClass(Class type)
type To Class
if (type == boolean.class)
    return Boolean.class;
if (type == byte.class)
    return Byte.class;
if (type == char.class)
    return Character.class;
if (type == short.class)
    return Short.class;
...
StringtypeToFilename(String var)
Converts type names to file names, substitutes ":" for "_"
return var.replaceAll(":", "_").toLowerCase();
StringtypeToHex(byte buffer[])
type To Hex
StringBuffer sb = new StringBuffer(buffer.length * 2);
for (int i = 0; i < buffer.length; i++) {
    sb.append(Character.forDigit((buffer[i] & 240) >> 4, 16));
    sb.append(Character.forDigit(buffer[i] & 15, 16));
return sb.toString();
inttypeToInt(String type)
type To Int
switch (type) {
case "A":
    return 1;
case "NS":
    return 2;
case "MD":
    return 3;
case "MF":
...
StringtypeToJavaCode(Class type)
type To Java Code
if (type.isArray()) {
    return type.getComponentType().getName() + "[]";
} else {
    return type.getName();
StringtypeToSignature(String className)
Converts class name ("foo.Bar") to signature ("foo/bar").
return className.replace('.', '/');
StringtypeToSignature(String type)
type To Signature
if (type.endsWith("[]")) {
    return "[" + typeToSignature(type.substring(0, type.length() - 2));
} else {
    return scalarTypeToSignature(type);
StringtypeToSimpleName(String typeName)
type To Simple Name
int dotIdx = typeName.indexOf('.');
if (dotIdx == -1) {
    return typeName;
return typeName.substring(dotIdx + 1);
StringTypeToString(int typeNum)
Type To String
switch (typeNum) {
case TYPE_FIRE:
    return "Fire";
case TYPE_WATER:
    return "Water";
case TYPE_EARTH:
    return "Earth";
case TYPE_WIND:
...
StringtypeToString(Object o)
type To String
if (o instanceof String) {
    return "'" + (String) o + "'";
} else if (o instanceof Enum) {
    return "'" + ((Enum<?>) o).name() + "'";
} else if (o instanceof Class) {
    return "'" + ((Class<?>) o).getName() + "'";
} else
    return String.valueOf(o);
...