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 String getPrimitiveLetter(Class<?> paramClass) {
    if (Integer.TYPE.equals(paramClass)) {
        return "I";
    }/*from w w w .  j a  v a  2  s.  c om*/
    if (Void.TYPE.equals(paramClass)) {
        return "V";
    }
    if (Boolean.TYPE.equals(paramClass)) {
        return "Z";
    }
    if (Character.TYPE.equals(paramClass)) {
        return "C";
    }
    if (Byte.TYPE.equals(paramClass)) {
        return "B";
    }
    if (Short.TYPE.equals(paramClass)) {
        return "S";
    }
    if (Float.TYPE.equals(paramClass)) {
        return "F";
    }
    if (Long.TYPE.equals(paramClass)) {
        return "J";
    }
    if (Double.TYPE.equals(paramClass)) {
        return "D";
    }
    throw new IllegalStateException("Type: " + paramClass.getCanonicalName() + " is not a primitive type");
}

From source file:com.browseengine.bobo.serialize.JSONSerializer.java

private static void loadObject(Object array, Class type, int index, JSONArray jsonArray)
        throws JSONSerializationException, JSONException {
    if (type.isPrimitive()) {
        if (type == Integer.TYPE) {
            Array.setInt(array, index, jsonArray.getInt(index));
        } else if (type == Long.TYPE) {
            Array.setLong(array, index, jsonArray.getInt(index));
        } else if (type == Short.TYPE) {
            Array.setShort(array, index, (short) jsonArray.getInt(index));
        } else if (type == Boolean.TYPE) {
            Array.setBoolean(array, index, jsonArray.getBoolean(index));
        } else if (type == Double.TYPE) {
            Array.setDouble(array, index, jsonArray.getDouble(index));
        } else if (type == Float.TYPE) {
            Array.setFloat(array, index, (float) jsonArray.getDouble(index));
        } else if (type == Character.TYPE) {
            char ch = jsonArray.getString(index).charAt(0);
            Array.setChar(array, index, ch);
        } else if (type == Byte.TYPE) {
            Array.setByte(array, index, (byte) jsonArray.getInt(index));
        } else {//from w w w .  jav a  2s .c om
            throw new JSONSerializationException("Unknown primitive: " + type);
        }
    } else if (type == String.class) {
        Array.set(array, index, jsonArray.getString(index));
    } else if (JSONSerializable.class.isAssignableFrom(type)) {
        JSONObject jObj = jsonArray.getJSONObject(index);
        JSONSerializable serObj = deSerialize(type, jObj);
        Array.set(array, index, serObj);
    } else if (type.isArray()) {
        Class componentClass = type.getComponentType();
        JSONArray subArray = jsonArray.getJSONArray(index);
        int len = subArray.length();

        Object newArray = Array.newInstance(componentClass, len);
        for (int k = 0; k < len; ++k) {
            loadObject(newArray, componentClass, k, subArray);
        }
    }
}

From source file:Util.java

/**
 * Is the given {@code object} a primitive type or wrapper for a primitive
 * type?//from   w  ww. j  a  v a2s.c om
 * 
 * @param object
 *            The object to check for primitive-ness.
 * @return {@code true} if {@code object} is a primitive type or wrapper for
 *         a primitive type, {@code false} otherwise.
 */
public static boolean isPrimitive(Object object) {
    if (object == null)
        return false;

    Class<?> type = object.getClass();

    return object instanceof String || (object instanceof Integer || Integer.TYPE.equals(type))
            || (object instanceof Boolean || Boolean.TYPE.equals(type))
            || (object instanceof Long || Long.TYPE.equals(type))
            || (object instanceof Double || Double.TYPE.equals(type))
            || (object instanceof Float || Float.TYPE.equals(type))
            || (object instanceof Byte || Byte.TYPE.equals(type))
            || (object instanceof Short || Short.TYPE.equals(type))
            || (object instanceof Character || Character.TYPE.equals(type));
}

From source file:org.impalaframework.spring.DebuggingInterceptor.java

public Object invoke(MethodInvocation invocation) throws Throwable {

    logger.debug("Calling method " + invocation);
    Class<?> returnType = invocation.getMethod().getReturnType();

    if (Void.TYPE.equals(returnType))
        return null;
    if (Byte.TYPE.equals(returnType))
        return (byte) 0;
    if (Short.TYPE.equals(returnType))
        return (short) 0;
    if (Integer.TYPE.equals(returnType))
        return (int) 0;
    if (Long.TYPE.equals(returnType))
        return 0L;
    if (Float.TYPE.equals(returnType))
        return 0f;
    if (Double.TYPE.equals(returnType))
        return 0d;
    if (Boolean.TYPE.equals(returnType))
        return false;

    return null;//from   w w w .  j a  va  2s. c o m
}

From source file:com.ms.commons.summer.web.util.json.JsonNumberMorpher.java

/**
 * Creates a new morpher for the target type.
 * /*from  w w  w  . jav  a  2s  . co m*/
 * @param type must be a primitive or wrapper type. BigDecimal and BigInteger are also supported.
 */
public JsonNumberMorpher(Class<?> type) {
    super(false);

    if (type == null) {
        throw new MorphException("Must specify a type");
    }

    if (type != Byte.TYPE && type != Short.TYPE && type != Integer.TYPE && type != Long.TYPE
            && type != Float.TYPE && type != Double.TYPE && !Byte.class.isAssignableFrom(type)
            && !Short.class.isAssignableFrom(type) && !Integer.class.isAssignableFrom(type)
            && !Long.class.isAssignableFrom(type) && !Float.class.isAssignableFrom(type)
            && !Double.class.isAssignableFrom(type) && !BigInteger.class.isAssignableFrom(type)
            && !BigDecimal.class.isAssignableFrom(type)) {
        throw new MorphException("Must specify a Number subclass");
    }

    this.type = type;
}

From source file:io.github.benas.jpopulator.randomizers.validation.MaxValueRandomizer.java

/**
 * Generate a random value for the given type.
 *
 * @param type the type for which a random value will be generated
 * @param maxValue the maximum threshold for the generated value
 * @return a random value (lower than maxValue) for the given type or null if the type is not supported
 *///from w  w  w .j  av  a  2  s  .c o  m
public static Object getRandomValue(final Class type, final long maxValue) {

    if (type.equals(Byte.TYPE) || type.equals(Byte.class)) {
        return (byte) randomDataGenerator.nextLong(Byte.MIN_VALUE, maxValue);
    }
    if (type.equals(Short.TYPE) || type.equals(Short.class)) {
        return (short) randomDataGenerator.nextLong(Short.MIN_VALUE, maxValue);
    }
    if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
        return (int) randomDataGenerator.nextLong(Integer.MIN_VALUE, maxValue);
    }
    if (type.equals(Long.TYPE) || type.equals(Long.class)) {
        return randomDataGenerator.nextLong(Long.MIN_VALUE, maxValue);
    }
    if (type.equals(BigInteger.class)) {
        return new BigInteger(String.valueOf(randomDataGenerator.nextLong(Long.MIN_VALUE, maxValue)));
    }
    if (type.equals(BigDecimal.class)) {
        return new BigDecimal(randomDataGenerator.nextLong(Long.MIN_VALUE, maxValue));
    }
    return null;
}

From source file:io.github.benas.jpopulator.randomizers.validation.MinValueRandomizer.java

/**
 * Generate a random value for the given type.
 *
 * @param type the type for which a random value will be generated
 * @param minValue the minimum threshold for the generated value
 * @return a random value (greater than maxValue) for the given type or null if the type is not supported
 *///from  w  w  w.  ja v a2 s  .c  o m
public static Object getRandomValue(final Class type, final long minValue) {

    if (type.equals(Byte.TYPE) || type.equals(Byte.class)) {
        return (byte) randomDataGenerator.nextLong(minValue, Byte.MAX_VALUE);
    }
    if (type.equals(Short.TYPE) || type.equals(Short.class)) {
        return (short) randomDataGenerator.nextLong(minValue, Short.MAX_VALUE);
    }
    if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
        return (int) randomDataGenerator.nextLong(minValue, Integer.MAX_VALUE);
    }
    if (type.equals(Long.TYPE) || type.equals(Long.class)) {
        return randomDataGenerator.nextLong(minValue, Long.MAX_VALUE);
    }
    if (type.equals(BigInteger.class)) {
        return new BigInteger(String.valueOf(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE)));
    }
    if (type.equals(BigDecimal.class)) {
        return new BigDecimal(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE));
    }
    return null;
}

From source file:com.bedatadriven.rebar.persistence.mapping.PrimitiveMapping.java

public PrimitiveMapping(MethodInfo getter) {
    super(getter);

    TypeInfo type = getter.getReturnType();
    Class primitive = type.isPrimitive();

    this.boxed = (primitive == null);

    if (primitive != null) {
        this.nullable = false;
    }/*from ww w  . jav  a  2 s.co m*/

    if (primitive == Integer.TYPE || type.getQualifiedName().equals(Integer.class.getName())
            || primitive == Short.TYPE || type.getQualifiedName().equals(Short.class.getName())
            || primitive == Long.TYPE || type.getQualifiedName().equals(Long.class.getName())
            || primitive == Byte.TYPE || type.getQualifiedName().equals(Byte.class.getName())
            || primitive == Boolean.TYPE || type.getQualifiedName().equals(Boolean.class.getName())) {

        sqlTypeName = SqliteTypes.integer;

    } else if (primitive == Float.TYPE || type.getQualifiedName().equals(Float.class.getName())
            || primitive == Double.TYPE || type.getQualifiedName().equals(Double.class.getName())) {

        sqlTypeName = SqliteTypes.real;

    } else if (primitive == Character.TYPE || type.getQualifiedName().equals(Character.class.getName())) {

        sqlTypeName = SqliteTypes.text;
    }

    String suffix = type.getSimpleName();

    if (suffix.equals("Integer")) {
        suffix = "Int";
    } else if (suffix.equals("Character")) {
        suffix = "Char";
    }
    suffix = suffix.substring(0, 1).toUpperCase() + suffix.substring(1);

    readerName = "Readers.read" + suffix;
    stmtSetter = "set" + suffix;

}

From source file:com.github.dozermapper.core.converters.EnumConverter.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public Object convert(Class destClass, Object srcObj) {
    if (null == srcObj) {
        MappingUtils.throwMappingException("Cannot convert null to enum of type " + destClass);
    }//from  w  w  w .j a  v  a  2 s. c om

    try {
        if ((srcObj.getClass().equals(Byte.class)) || (srcObj.getClass().equals(Byte.TYPE))) {
            return EnumUtils.getEnumList(destClass).get(((Byte) srcObj).intValue());
        } else if ((srcObj.getClass().equals(Short.class)) || (srcObj.getClass().equals(Short.TYPE))) {
            return EnumUtils.getEnumList(destClass).get(((Short) srcObj).intValue());
        } else if ((srcObj.getClass().equals(Integer.class)) || (srcObj.getClass().equals(Integer.TYPE))) {
            return EnumUtils.getEnumList(destClass).get((Integer) srcObj);
        } else if ((srcObj.getClass().equals(Long.class)) || (srcObj.getClass().equals(Long.TYPE))) {
            return EnumUtils.getEnumList(destClass).get(((Long) srcObj).intValue());
        } else {
            return Enum.valueOf(destClass, srcObj.toString());
        }
    } catch (Exception e) {
        MappingUtils.throwMappingException("Cannot convert [" + srcObj + "] to enum of type " + destClass, e);
    }
    return srcObj;
}

From source file:fm.last.hadoop.tools.ReplicationPolicyFixer.java

public static int verifyBlockPlacement(LocatedBlock lBlk, short replication, NetworkTopology cluster) {
    try {/*  w w w  . j ava  2 s .c o  m*/
        Class<?> replicationTargetChooserClass = Class
                .forName("org.apache.hadoop.hdfs.server.namenode.ReplicationTargetChooser");
        Method verifyBlockPlacementMethod = replicationTargetChooserClass.getDeclaredMethod(
                "verifyBlockPlacement", LocatedBlock.class, Short.TYPE, NetworkTopology.class);
        verifyBlockPlacementMethod.setAccessible(true);

        return (Integer) verifyBlockPlacementMethod.invoke(null, lBlk, new Short(replication), cluster);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof RuntimeException) {
            cause.printStackTrace();
            throw (RuntimeException) cause;
        } else {
            throw new RuntimeException(e);
        }
    }
}