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:org.gradle.internal.reflect.JavaReflectionUtil.java

public static Class<?> getWrapperTypeForPrimitiveType(Class<?> type) {
    if (type == Character.TYPE) {
        return Character.class;
    } else if (type == Boolean.TYPE) {
        return Boolean.class;
    } else if (type == Long.TYPE) {
        return Long.class;
    } else if (type == Integer.TYPE) {
        return Integer.class;
    } else if (type == Short.TYPE) {
        return Short.class;
    } else if (type == Byte.TYPE) {
        return Byte.class;
    } else if (type == Float.TYPE) {
        return Float.class;
    } else if (type == Double.TYPE) {
        return Double.class;
    }//from   w  w  w  . j  av  a2  s .com
    throw new IllegalArgumentException(
            String.format("Don't know the wrapper type for primitive type %s.", type));
}

From source file:org.impalaframework.spring.service.proxy.ServiceEndpointInterceptor.java

public Object invokeDummy(MethodInvocation invocation) throws Throwable {

    log.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 v  a 2 s .  co  m*/
}

From source file:net.sf.json.JSONUtils.java

/**
 * Tests if obj is a primitive number or wrapper.<br>
 *//*w  ww . j a  va 2  s. co  m*/
public static boolean isNumber(Object obj) {
    if (((obj != null) && (obj.getClass() == Byte.TYPE)) || ((obj != null) && (obj.getClass() == Short.TYPE))
            || ((obj != null) && (obj.getClass() == Integer.TYPE))
            || ((obj != null) && (obj.getClass() == Long.TYPE))
            || ((obj != null) && (obj.getClass() == Float.TYPE))
            || ((obj != null) && (obj.getClass() == Double.TYPE))) {
        return true;
    }

    if ((obj instanceof Byte) || (obj instanceof Short) || (obj instanceof Integer) || (obj instanceof Long)
            || (obj instanceof Float) || (obj instanceof Double)) {
        return true;
    }

    return false;
}

From source file:com.nfwork.dbfound.json.JSONDynaBean.java

protected boolean isDynaAssignable(Class dest, Class src) {
    boolean assignable = dest.isAssignableFrom(src);
    assignable = (dest == Boolean.TYPE && src == Boolean.class) ? true : assignable;
    assignable = (dest == Byte.TYPE && src == Byte.class) ? true : assignable;
    assignable = (dest == Character.TYPE && src == Character.class) ? true : assignable;
    assignable = (dest == Short.TYPE && src == Short.class) ? true : assignable;
    assignable = (dest == Integer.TYPE && src == Integer.class) ? true : assignable;
    assignable = (dest == Long.TYPE && src == Long.class) ? true : assignable;
    assignable = (dest == Float.TYPE && src == Float.class) ? true : assignable;
    assignable = (dest == Double.TYPE && src == Double.class) ? true : assignable;

    if (src == Double.TYPE || Double.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true
                : assignable;/*from w w  w.j a  v a2 s .  c  o m*/
    }
    if (src == Float.TYPE || Float.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable;
    }
    if (src == Long.TYPE || Long.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable;
    }
    if (src == Integer.TYPE || Integer.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest)) ? true : assignable;
    }
    if (src == Short.TYPE || Short.class.isAssignableFrom(src)) {
        assignable = (isByte(dest)) ? true : assignable;
    }

    return assignable;
}

From source file:com.link_intersystems.lang.Conversions.java

/**
 * char to byte or short/*from  w w w . jav a 2  s. com*/
 */
private static boolean isPrimitiveCharacterNarrowing(Class<?> to) {
    boolean isNarrowing = false;

    isNarrowing |= isIdentity(to, Byte.TYPE);
    isNarrowing |= isIdentity(to, Short.TYPE);

    return isNarrowing;
}

From source file:org.briljantframework.data.vector.ConvertTest.java

@Test
public void testTo_convertToShort() throws Exception {
    assertEquals(10, (short) Convert.to(Short.class, 10));
    assertEquals(10, (short) Convert.to(Short.class, 10.0));
    assertEquals(10, (short) Convert.to(Short.class, 10.0f));
    assertEquals(10, (short) Convert.to(Short.class, 10l));
    assertEquals(10, (short) Convert.to(Short.class, (short) 10));
    assertEquals(10, (short) Convert.to(Short.class, (byte) 10));
    assertEquals(10, (short) Convert.to(Short.class, Complex.valueOf(10)));
    assertEquals(1, (short) Convert.to(Short.class, Logical.TRUE));
    assertEquals(1, (short) Convert.to(Short.class, true));

    assertEquals(10, (short) Convert.to(Short.TYPE, 10));
    assertEquals(10, (short) Convert.to(Short.TYPE, 10.0));
    assertEquals(10, (short) Convert.to(Short.TYPE, 10.0f));
    assertEquals(10, (short) Convert.to(Short.TYPE, 10l));
    assertEquals(10, (short) Convert.to(Short.TYPE, (short) 10));
    assertEquals(10, (short) Convert.to(Short.TYPE, (byte) 10));
    assertEquals(10, (short) Convert.to(Short.TYPE, Complex.valueOf(10)));
    assertEquals(1, (short) Convert.to(Short.TYPE, Logical.TRUE));
    assertEquals(1, (short) Convert.to(Short.TYPE, true));
}

From source file:au.com.addstar.cellblock.configuration.AutoConfig.java

@SuppressWarnings("unchecked")
public boolean load() {
    FileConfiguration yml = new YamlConfiguration();
    try {/*from  w w  w  . jav a 2  s .  c  o  m*/
        if (mFile.getParentFile().exists() || mFile.getParentFile().mkdirs()) {// Make sure the file exists
            if (mFile.exists() || mFile.createNewFile()) {
                // Parse the config
                yml.load(mFile);
                for (Field field : getClass().getDeclaredFields()) {
                    ConfigField configField = field.getAnnotation(ConfigField.class);
                    if (configField == null)
                        continue;

                    String optionName = configField.name();
                    if (optionName.isEmpty())
                        optionName = field.getName();

                    field.setAccessible(true);

                    String path = (configField.category().isEmpty() ? "" : configField.category() + ".") //$NON-NLS-2$
                            + optionName;
                    if (!yml.contains(path)) {
                        if (field.get(this) == null)
                            throw new InvalidConfigurationException(
                                    path + " is required to be set! Info:\n" + configField.comment());
                    } else {
                        // Parse the value

                        if (field.getType().isArray()) {
                            // Integer
                            if (field.getType().getComponentType().equals(Integer.TYPE))
                                field.set(this, yml.getIntegerList(path).toArray(new Integer[0]));

                            // Float
                            else if (field.getType().getComponentType().equals(Float.TYPE))
                                field.set(this, yml.getFloatList(path).toArray(new Float[0]));

                            // Double
                            else if (field.getType().getComponentType().equals(Double.TYPE))
                                field.set(this, yml.getDoubleList(path).toArray(new Double[0]));

                            // Long
                            else if (field.getType().getComponentType().equals(Long.TYPE))
                                field.set(this, yml.getLongList(path).toArray(new Long[0]));

                            // Short
                            else if (field.getType().getComponentType().equals(Short.TYPE))
                                field.set(this, yml.getShortList(path).toArray(new Short[0]));

                            // Boolean
                            else if (field.getType().getComponentType().equals(Boolean.TYPE))
                                field.set(this, yml.getBooleanList(path).toArray(new Boolean[0]));

                            // String
                            else if (field.getType().getComponentType().equals(String.class)) {
                                field.set(this, yml.getStringList(path).toArray(new String[0]));
                            } else
                                throw new IllegalArgumentException("Cannot use type "
                                        + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-1$
                        } else if (List.class.isAssignableFrom(field.getType())) {
                            if (field.getGenericType() == null)
                                throw new IllegalArgumentException(
                                        "Cannot use type List without specifying generic type for AutoConfiguration");

                            Type type = ((ParameterizedType) field.getGenericType())
                                    .getActualTypeArguments()[0];

                            if (type.equals(Integer.class))
                                field.set(this, newList((Class<? extends List<Integer>>) field.getType(),
                                        yml.getIntegerList(path)));
                            else if (type.equals(Float.class))
                                field.set(this, newList((Class<? extends List<Float>>) field.getType(),
                                        yml.getFloatList(path)));
                            else if (type.equals(Double.class))
                                field.set(this, newList((Class<? extends List<Double>>) field.getType(),
                                        yml.getDoubleList(path)));
                            else if (type.equals(Long.class))
                                field.set(this, newList((Class<? extends List<Long>>) field.getType(),
                                        yml.getLongList(path)));
                            else if (type.equals(Short.class))
                                field.set(this, newList((Class<? extends List<Short>>) field.getType(),
                                        yml.getShortList(path)));
                            else if (type.equals(Boolean.class))
                                field.set(this, newList((Class<? extends List<Boolean>>) field.getType(),
                                        yml.getBooleanList(path)));
                            else if (type.equals(String.class))
                                field.set(this, newList((Class<? extends List<String>>) field.getType(),
                                        yml.getStringList(path)));
                            else
                                throw new IllegalArgumentException(
                                        "Cannot use type " + field.getType().getSimpleName() + "<" //$NON-NLS-2$
                                                + type.toString() + "> for AutoConfiguration");
                        } else if (Set.class.isAssignableFrom(field.getType())) {
                            if (field.getGenericType() == null)
                                throw new IllegalArgumentException(
                                        "Cannot use type set without specifying generic type for AytoConfiguration");

                            Type type = ((ParameterizedType) field.getGenericType())
                                    .getActualTypeArguments()[0];

                            if (type.equals(Integer.class))
                                field.set(this, newSet((Class<? extends Set<Integer>>) field.getType(),
                                        yml.getIntegerList(path)));
                            else if (type.equals(Float.class))
                                field.set(this, newSet((Class<? extends Set<Float>>) field.getType(),
                                        yml.getFloatList(path)));
                            else if (type.equals(Double.class))
                                field.set(this, newSet((Class<? extends Set<Double>>) field.getType(),
                                        yml.getDoubleList(path)));
                            else if (type.equals(Long.class))
                                field.set(this, newSet((Class<? extends Set<Long>>) field.getType(),
                                        yml.getLongList(path)));
                            else if (type.equals(Short.class))
                                field.set(this, newSet((Class<? extends Set<Short>>) field.getType(),
                                        yml.getShortList(path)));
                            else if (type.equals(Boolean.class))
                                field.set(this, newSet((Class<? extends Set<Boolean>>) field.getType(),
                                        yml.getBooleanList(path)));
                            else if (type.equals(String.class))
                                field.set(this, newSet((Class<? extends Set<String>>) field.getType(),
                                        yml.getStringList(path)));
                            else
                                throw new IllegalArgumentException(
                                        "Cannot use type " + field.getType().getSimpleName() + "<" //$NON-NLS-2$
                                                + type.toString() + "> for AutoConfiguration");
                        } else {
                            // Integer
                            if (field.getType().equals(Integer.TYPE))
                                field.setInt(this, yml.getInt(path));

                            // Float
                            else if (field.getType().equals(Float.TYPE))
                                field.setFloat(this, (float) yml.getDouble(path));

                            // Double
                            else if (field.getType().equals(Double.TYPE))
                                field.setDouble(this, yml.getDouble(path));

                            // Long
                            else if (field.getType().equals(Long.TYPE))
                                field.setLong(this, yml.getLong(path));

                            // Short
                            else if (field.getType().equals(Short.TYPE))
                                field.setShort(this, (short) yml.getInt(path));

                            // Boolean
                            else if (field.getType().equals(Boolean.TYPE))
                                field.setBoolean(this, yml.getBoolean(path));

                            // ItemStack
                            else if (field.getType().equals(ItemStack.class))
                                field.set(this, yml.getItemStack(path));

                            // String
                            else if (field.getType().equals(String.class))
                                field.set(this, yml.getString(path));
                            else
                                throw new IllegalArgumentException("Cannot use type "
                                        + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-1$
                        }
                    }
                }

                onPostLoad();
            } else {
                Bukkit.getLogger().log(Level.INFO, "Unable to create file: " + mFile.toString());
            }
        } else {
            Bukkit.getLogger().log(Level.INFO, "Unable to create file: " + mFile.getParentFile().toString());
        }
        return true;
    } catch (IOException | InvalidConfigurationException | IllegalAccessException
            | IllegalArgumentException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:com.cyclopsgroup.waterview.utils.TypeUtils.java

private static synchronized Map getTypeMap() {
    if (typeMap == null) {
        typeMap = new Hashtable();
        typeMap.put("boolean", Boolean.TYPE);
        typeMap.put("byte", Byte.TYPE);
        typeMap.put("char", Character.TYPE);
        typeMap.put("short", Short.TYPE);
        typeMap.put("int", Integer.TYPE);
        typeMap.put("long", Long.TYPE);
        typeMap.put("float", Float.TYPE);
        typeMap.put("double", Double.TYPE);
        typeMap.put("string", String.class);
        typeMap.put("date", Date.class);
    }//  ww w. j a  v  a  2 s .co m

    return typeMap;
}

From source file:org.kuali.rice.krad.data.jpa.Filter.java

/**
 * Coerces the {@code attributeValue} using the given {@code type}.
 *
 * @param type the type to use to coerce the value.
 * @param attributeName the attribute name of the field to coerce.
 * @param attributeValue the value to coerce.
 * @return the coerced value.//ww  w .  j a v a  2 s  .co m
 */
private static Object coerceValue(Class<?> type, String attributeName, String attributeValue) {
    try {
        if (Character.TYPE.equals(type) || Character.class.isAssignableFrom(type)) {
            return Character.valueOf(attributeValue.charAt(0));
        } else if (Boolean.TYPE.equals(type) || Boolean.class.isAssignableFrom(type)) {
            return Boolean.valueOf(attributeValue);
        } else if (Short.TYPE.equals(type) || Short.class.isAssignableFrom(type)) {
            return Short.valueOf(attributeValue);
        } else if (Integer.TYPE.equals(type) || Integer.class.isAssignableFrom(type)) {
            return Integer.valueOf(attributeValue);
        } else if (Long.TYPE.equals(type) || Long.class.isAssignableFrom(type)) {
            return Long.valueOf(attributeValue);
        } else if (Double.TYPE.equals(type) || Double.class.isAssignableFrom(type)) {
            return Double.valueOf(attributeValue);
        } else if (Float.TYPE.equals(type) || Float.class.isAssignableFrom(type)) {
            return Float.valueOf(attributeValue);
        }
    } catch (NumberFormatException nfe) {
        LOG.error("Could not coerce the value " + attributeValue + " for the field " + attributeName, nfe);
    }

    return attributeValue;
}

From source file:com.xwtec.xwserver.util.json.JSONArray.java

/**
 * Creates a JSONArray.<br>/*from   w w w . ja v a2  s  .  co  m*/
 * Inspects the object type to call the correct JSONArray factory method.
 * Accepts JSON formatted strings, arrays, Collections and Enums.
 *
 * @param object
 * @throws JSONException if the object can not be converted to a proper
 *         JSONArray.
 */
public static JSONArray fromObject(Object object, JsonConfig jsonConfig) {
    if (object instanceof JSONString) {
        return _fromJSONString((JSONString) object, jsonConfig);
    } else if (object instanceof JSONArray) {
        return _fromJSONArray((JSONArray) object, jsonConfig);
    } else if (object instanceof Collection) {
        return _fromCollection((Collection) object, jsonConfig);
    } else if (object instanceof JSONTokener) {
        return _fromJSONTokener((JSONTokener) object, jsonConfig);
    } else if (object instanceof String) {
        return _fromString((String) object, jsonConfig);
    } else if (object != null && object.getClass().isArray()) {
        Class type = object.getClass().getComponentType();
        if (!type.isPrimitive()) {
            return _fromArray((Object[]) object, jsonConfig);
        } else {
            if (type == Boolean.TYPE) {
                return _fromArray((boolean[]) object, jsonConfig);
            } else if (type == Byte.TYPE) {
                return _fromArray((byte[]) object, jsonConfig);
            } else if (type == Short.TYPE) {
                return _fromArray((short[]) object, jsonConfig);
            } else if (type == Integer.TYPE) {
                return _fromArray((int[]) object, jsonConfig);
            } else if (type == Long.TYPE) {
                return _fromArray((long[]) object, jsonConfig);
            } else if (type == Float.TYPE) {
                return _fromArray((float[]) object, jsonConfig);
            } else if (type == Double.TYPE) {
                return _fromArray((double[]) object, jsonConfig);
            } else if (type == Character.TYPE) {
                return _fromArray((char[]) object, jsonConfig);
            } else {
                throw new JSONException("Unsupported type");
            }
        }
    } else if (JSONUtils.isBoolean(object) || JSONUtils.isFunction(object) || JSONUtils.isNumber(object)
            || JSONUtils.isNull(object) || JSONUtils.isString(object) || object instanceof JSON) {
        fireArrayStartEvent(jsonConfig);
        JSONArray jsonArray = new JSONArray().element(object, jsonConfig);
        fireElementAddedEvent(0, jsonArray.get(0), jsonConfig);
        fireArrayStartEvent(jsonConfig);
        return jsonArray;
    } else if (object instanceof Enum) {
        return _fromArray((Enum) object, jsonConfig);
    } else if (object instanceof Annotation || (object != null && object.getClass().isAnnotation())) {
        throw new JSONException("Unsupported type");
    } else if (JSONUtils.isObject(object)) {
        fireArrayStartEvent(jsonConfig);
        JSONArray jsonArray = new JSONArray().element(JSONObject.fromObject(object, jsonConfig));
        fireElementAddedEvent(0, jsonArray.get(0), jsonConfig);
        fireArrayStartEvent(jsonConfig);
        return jsonArray;
    } else {
        throw new JSONException("Unsupported type");
    }
}