Example usage for java.lang Short TYPE

List of usage examples for java.lang Short TYPE

Introduction

In this page you can find the example usage for java.lang Short TYPE.

Prototype

Class TYPE

To view the source code for java.lang Short TYPE.

Click Source Link

Document

The Class instance representing the primitive type short .

Usage

From source file:Main.java

public static Class<?> findClass(String className) throws ClassNotFoundException {
    // [JACKSON-597]: support primitive types (and void)
    if (className.indexOf('.') < 0) {
        if ("int".equals(className))
            return Integer.TYPE;
        if ("long".equals(className))
            return Long.TYPE;
        if ("float".equals(className))
            return Float.TYPE;
        if ("double".equals(className))
            return Double.TYPE;
        if ("boolean".equals(className))
            return Boolean.TYPE;
        if ("byte".equals(className))
            return Byte.TYPE;
        if ("char".equals(className))
            return Character.TYPE;
        if ("short".equals(className))
            return Short.TYPE;
        if ("void".equals(className))
            return Void.TYPE;
    }/*w w w . j  av a 2 s  .  co  m*/
    // Two-phase lookup: first using context ClassLoader; then default
    Throwable prob = null;
    ClassLoader loader = Thread.currentThread().getContextClassLoader();

    if (loader != null) {
        try {
            return Class.forName(className, true, loader);
        } catch (Exception e) {
            prob = getRootCause(e);
        }
    }
    try {
        return Class.forName(className);
    } catch (Exception e) {
        if (prob == null) {
            prob = getRootCause(e);
        }
    }
    if (prob instanceof RuntimeException) {
        throw (RuntimeException) prob;
    }
    throw new ClassNotFoundException(prob.getMessage(), prob);
}

From source file:PrimitiveUtils.java

public static Object read(String value, Class type) {
    Object ret = value;//from   w  w w  .jav  a2  s . c  o  m
    if (Integer.TYPE.equals(type)) {
        ret = Integer.valueOf(value);
    }
    if (Byte.TYPE.equals(type)) {
        ret = Byte.valueOf(value);
    }
    if (Short.TYPE.equals(type)) {
        ret = Short.valueOf(value);
    }
    if (Long.TYPE.equals(type)) {
        ret = Long.valueOf(value);
    }
    if (Float.TYPE.equals(type)) {
        ret = Float.valueOf(value);
    }
    if (Double.TYPE.equals(type)) {
        ret = Double.valueOf(value);
    }
    if (Boolean.TYPE.equals(type)) {
        ret = Boolean.valueOf(value);
    }
    if (Character.TYPE.equals(type)) {
        ret = value.charAt(0);
    }
    // TODO others.
    return ret;
}

From source file:Main.java

private static String getColumnType(Class<?> fieldType) {
    if (String.class == fieldType) {
        return "TEXT";
    }//from   www . j  a  v  a  2s .  co m
    if ((Integer.TYPE == fieldType) || (Integer.class == fieldType)) {
        return "INTEGER";
    }
    if ((Long.TYPE == fieldType) || (Long.class == fieldType)) {
        return "BIGINT";
    }
    if ((Float.TYPE == fieldType) || (Float.class == fieldType)) {
        return "FLOAT";
    }
    if ((Short.TYPE == fieldType) || (Short.class == fieldType)) {
        return "INT";
    }
    if ((Double.TYPE == fieldType) || (Double.class == fieldType)) {
        return "DOUBLE";
    }
    if (Blob.class == fieldType) {
        return "BLOB";
    }

    return "TEXT";
}

From source file:Main.java

/**
 * Creates a class identifier of form Labc/abc;, from a Class.
 *//* w  ww .  j av  a2  s  . c  o  m*/
public static String ci(Class n) {
    if (n.isArray()) {
        n = n.getComponentType();
        if (n.isPrimitive()) {
            if (n == Byte.TYPE) {
                return "[B";
            } else if (n == Boolean.TYPE) {
                return "[Z";
            } else if (n == Short.TYPE) {
                return "[S";
            } else if (n == Character.TYPE) {
                return "[C";
            } else if (n == Integer.TYPE) {
                return "[I";
            } else if (n == Float.TYPE) {
                return "[F";
            } else if (n == Double.TYPE) {
                return "[D";
            } else if (n == Long.TYPE) {
                return "[J";
            } else {
                throw new RuntimeException("Unrecognized type in compiler: " + n.getName());
            }
        } else {
            return "[" + ci(n);
        }
    } else {
        if (n.isPrimitive()) {
            if (n == Byte.TYPE) {
                return "B";
            } else if (n == Boolean.TYPE) {
                return "Z";
            } else if (n == Short.TYPE) {
                return "S";
            } else if (n == Character.TYPE) {
                return "C";
            } else if (n == Integer.TYPE) {
                return "I";
            } else if (n == Float.TYPE) {
                return "F";
            } else if (n == Double.TYPE) {
                return "D";
            } else if (n == Long.TYPE) {
                return "J";
            } else if (n == Void.TYPE) {
                return "V";
            } else {
                throw new RuntimeException("Unrecognized type in compiler: " + n.getName());
            }
        } else {
            return "L" + p(n) + ";";
        }
    }
}

From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java

/**
 * ?,?,/*w  w w . j  a va2 s  .  c o m*/
 * 
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
private static <T> T getInternalDefaultValue(Class<T> clazz) {
    if (!clazz.isPrimitive()) {
        return null;
    }
    if (Short.TYPE.equals(clazz)) {
        return (T) Short.valueOf((short) 0);
    }
    if (Integer.TYPE.equals(clazz)) {
        return (T) Integer.valueOf(0);
    }
    if (Long.TYPE.equals(clazz)) {
        return (T) Long.valueOf(0);
    }
    if (Boolean.TYPE.equals(clazz)) {
        return (T) Boolean.valueOf(false);
    }
    if (Float.TYPE.equals(clazz)) {
        return (T) Float.valueOf(0);
    }
    if (Double.TYPE.equals(clazz)) {
        return (T) Double.valueOf(0);
    }
    if (Byte.TYPE.equals(clazz)) {
        return (T) Byte.valueOf((byte) 0);
    }
    if (Character.TYPE.equals(clazz)) {
        return (T) Character.valueOf('\0');
    }
    return null;
}

From source file:sim.portrayal.inspector.TimeSeriesChartingPropertyInspector.java

public static Class[] types() {
    return new Class[] { Number.class, Boolean.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE,
            Double.TYPE, Valuable.class };
}

From source file:Main.java

public static boolean isConvertible(Class<?> srcPrimitive, Class<?> tgtPrimitive) {
    if (Boolean.TYPE.equals(srcPrimitive)) {
        return Boolean.TYPE.equals(tgtPrimitive);
    } else if (Byte.TYPE.equals(tgtPrimitive)) {
        return Byte.TYPE.equals(tgtPrimitive) || Short.TYPE.equals(tgtPrimitive)
                || Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive)
                || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive);
    } else if (Character.TYPE.equals(srcPrimitive)) {
        return Character.TYPE.equals(tgtPrimitive) || Integer.TYPE.equals(tgtPrimitive)
                || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive)
                || Double.TYPE.equals(tgtPrimitive);
    } else if (Double.TYPE.equals(srcPrimitive)) {
        return Double.TYPE.equals(tgtPrimitive);
    } else if (Float.TYPE.equals(srcPrimitive)) {
        return Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive);
    } else if (Integer.TYPE.equals(srcPrimitive)) {
        return Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive)
                || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive);
    } else if (Long.TYPE.equals(srcPrimitive)) {
        return Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive)
                || Double.TYPE.equals(tgtPrimitive);
    } else if (Short.TYPE.equals(srcPrimitive)) {
        return Short.TYPE.equals(tgtPrimitive) || Integer.TYPE.equals(tgtPrimitive)
                || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive)
                || Double.TYPE.equals(tgtPrimitive);
    }//from www. j  a va2 s  . c o  m
    return false;
}

From source file:org.mule.util.ArrayUtils.java

/**
 * Like {@link #toString(Object)} but considers at most <code>maxElements</code>
 * values; overflow is indicated by an appended "[..]" ellipsis.
 *//*from   w w  w. j a  va 2 s .  c  om*/
public static String toString(Object array, int maxElements) {
    String result;

    Class componentType = array.getClass().getComponentType();
    if (Object.class.isAssignableFrom(componentType)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((Object[]) array, 0, maxElements)));
    } else if (componentType.equals(Boolean.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((boolean[]) array, 0, maxElements)));
    } else if (componentType.equals(Byte.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((byte[]) array, 0, maxElements)));
    } else if (componentType.equals(Character.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((char[]) array, 0, maxElements)));
    } else if (componentType.equals(Short.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((short[]) array, 0, maxElements)));
    } else if (componentType.equals(Integer.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((int[]) array, 0, maxElements)));
    } else if (componentType.equals(Long.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((long[]) array, 0, maxElements)));
    } else if (componentType.equals(Float.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((float[]) array, 0, maxElements)));
    } else if (componentType.equals(Double.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((double[]) array, 0, maxElements)));
    } else {
        throw new IllegalArgumentException("Unknown array service type: " + componentType.getName());
    }

    if (Array.getLength(array) > maxElements) {
        StringBuffer buf = new StringBuffer(result);
        buf.insert(buf.length() - 1, " [..]");
        result = buf.toString();
    }

    return result;

}

From source file:Main.java

private static Class<?> getPrimitive(Class<?> argClass) {
    if (argClass == Boolean.class)
        return Boolean.TYPE;
    else if (argClass == Character.class)
        return Character.TYPE;
    else if (argClass == Byte.class)
        return Byte.TYPE;
    else if (argClass == Short.class)
        return Short.TYPE;
    else if (argClass == Integer.class)
        return Integer.TYPE;
    else if (argClass == Long.class)
        return Long.TYPE;
    else if (argClass == Float.class)
        return Float.TYPE;
    else if (argClass == Double.class)
        return Double.TYPE;
    else/*from   w  w  w .  ja  va 2 s  . co  m*/
        return null;
}

From source file:org.jtwig.util.ArrayUtil.java

public static Object[] toArray(Object obj) {
    if (!obj.getClass().isArray()) {
        throw new IllegalArgumentException("Argument is not an array");
    }/*from w  w  w .  ja va 2s .  co m*/

    Class<?> type = obj.getClass().getComponentType();
    if (!type.isPrimitive()) {
        return (Object[]) obj;
    }

    if (Byte.TYPE.isAssignableFrom(type)) {
        return toArray((byte[]) obj);
    }
    if (Short.TYPE.isAssignableFrom(type)) {
        return toArray((short[]) obj);
    }
    if (Integer.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((int[]) obj);
    }
    if (Long.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((long[]) obj);
    }
    if (Boolean.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((boolean[]) obj);
    }
    if (Character.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((char[]) obj);
    }
    if (Float.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((float[]) obj);
    }
    if (Double.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((double[]) obj);
    }

    throw new IllegalArgumentException("Unsupported argument type: " + type.getName());
}