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.openspaces.rest.utils.ControllerUtils.java

public static Object convertPropertyToPrimitiveType(String object, Class type, String propKey) {
    if (type.equals(Long.class) || type.equals(Long.TYPE))
        return Long.valueOf(object);

    if (type.equals(Boolean.class) || type.equals(Boolean.TYPE))
        return Boolean.valueOf(object);

    if (type.equals(Integer.class) || type.equals(Integer.TYPE))
        return Integer.valueOf(object);

    if (type.equals(Byte.class) || type.equals(Byte.TYPE))
        return Byte.valueOf(object);

    if (type.equals(Short.class) || type.equals(Short.TYPE))
        return Short.valueOf(object);

    if (type.equals(Float.class) || type.equals(Float.TYPE))
        return Float.valueOf(object);

    if (type.equals(Double.class) || type.equals(Double.TYPE))
        return Double.valueOf(object);

    if (type.isEnum())
        return Enum.valueOf(type, object);

    if (type.equals(String.class) || type.equals(Object.class))
        return String.valueOf(object);

    if (type.equals(java.util.Date.class)) {
        try {//from w ww  .ja va  2  s  . co m
            return simpleDateFormat.parse(object);
        } catch (ParseException e) {
            throw new RestException(
                    "Unable to parse date [" + object + "]. Make sure it matches the format: " + date_format);
        }
    }

    //unknown type
    throw new UnsupportedTypeException("Non primitive type when converting property [" + propKey + "]:" + type);
}

From source file:org.opoo.util.ClassUtils.java

public static boolean isCompatibleType(Object value, Class type) {
    // Do object check first, then primitives
    if (value == null || type.isInstance(value)) {
        return true;
    } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) {
        return true;
    } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) {
        return true;
    } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) {
        return true;
    } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) {
        return true;
    } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) {
        return true;
    } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) {
        return true;
    } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) {
        return true;
    } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) {
        return true;
    } else {//from   w  w  w .j  a  va 2 s  . c o  m
        return false;
    }
}

From source file:pe.com.mmh.sisgap.utils.BasicDynaBean.java

/**
 * Return the value of a simple property with the specified name.
 *
 * @param name Name of the property whose value is to be retrieved
 *
 * @exception IllegalArgumentException if there is no property
 *  of the specified name//from ww  w  .  java 2  s. c  o m
 */
public Object get(String name) {

    // Return any non-null value for the specified property
    Object value = values.get(name);
    if (value != null) {
        return (value);
    }

    // Return a null value for a non-primitive property
    Class type = getDynaProperty(name).getType();
    if (!type.isPrimitive()) {
        return (value);
    }

    // Manufacture default values for primitive properties
    if (type == Boolean.TYPE) {
        return (Boolean.FALSE);
    } else if (type == Byte.TYPE) {
        return (new Byte((byte) 0));
    } else if (type == Character.TYPE) {
        return (new Character((char) 0));
    } else if (type == Double.TYPE) {
        return (new Double((double) 0.0));
    } else if (type == Float.TYPE) {
        return (new Float((float) 0.0));
    } else if (type == Integer.TYPE) {
        return (new Integer((int) 0));
    } else if (type == Long.TYPE) {
        return (new Long((int) 0));
    } else if (type == Short.TYPE) {
        return (new Short((short) 0));
    } else {
        return (null);
    }

}

From source file:org.romaframework.core.schema.SchemaHelper.java

public static Object assignDefaultValueToLiteral(SchemaClass type) {
    Object value;/*from  w w w.  j  a va 2s .  c om*/
    if (type.isOfType(Integer.TYPE)) {
        value = Integer.valueOf(0);
    } else if (type.isOfType(Long.TYPE)) {
        value = Long.valueOf(0);
    } else if (type.isOfType(Short.TYPE)) {
        value = Short.valueOf((short) 0);
    } else if (type.isOfType(Byte.TYPE)) {
        value = Byte.valueOf((byte) 0);
    } else if (type.isOfType(Float.TYPE)) {
        value = Float.valueOf(0);
    } else if (type.isOfType(Double.TYPE)) {
        value = Double.valueOf(0);
    } else {
        value = null;
    }
    return value;
}

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

private boolean isShort(Class clazz) {
    return Short.class.isAssignableFrom(clazz) || clazz == Short.TYPE;
}

From source file:com.aol.one.patch.DefaultPatcher.java

private List<MethodData> generateMethodData(List<String> methodNames, JsonNode valueNode) {

    List<MethodData> dataList = new ArrayList<>();
    if (valueNode.isTextual()) {
        for (String methodName : methodNames) {
            dataList.add(new MethodData(methodName, String.class, valueNode.asText()));
        }// w ww.j a  va  2 s.  co  m
    } else if (valueNode.isNumber()) {
        for (String methodName : methodNames) {
            if (valueNode.isIntegralNumber()) {
                dataList.add(new MethodData(methodName, Long.TYPE, valueNode.asLong()));
                dataList.add(new MethodData(methodName, Long.class, valueNode.asLong()));
                dataList.add(new MethodData(methodName, Integer.TYPE, valueNode.asInt()));
                dataList.add(new MethodData(methodName, Integer.class, valueNode.asInt()));
                dataList.add(new MethodData(methodName, Short.TYPE, (short) valueNode.asInt()));
                dataList.add(new MethodData(methodName, Short.class, (short) valueNode.asInt()));
            } else {
                dataList.add(new MethodData(methodName, Double.TYPE, valueNode.asDouble()));
                dataList.add(new MethodData(methodName, Double.class, valueNode.asDouble()));
                dataList.add(new MethodData(methodName, Float.TYPE, valueNode.asDouble()));
                dataList.add(new MethodData(methodName, Float.class, valueNode.asDouble()));
            }
        }
    } else if (valueNode.isBoolean()) {
        for (String methodName : methodNames) {
            dataList.add(new MethodData(methodName, Boolean.TYPE, valueNode.asBoolean()));
            dataList.add(new MethodData(methodName, Boolean.class, valueNode.asBoolean()));
        }

    }

    // default
    for (String methodName : methodNames) {
        dataList.add(new MethodData(methodName, JsonNode.class, valueNode));
    }

    return dataList;
}

From source file:org.kordamp.ezmorph.bean.MorphDynaBean.java

protected boolean isDynaAssignable(Class dest, Class src) {
    boolean assignable = dest.isAssignableFrom(src);
    if (assignable) {
        return true;
    }// ww w.  ja va 2s.  com
    assignable = (dest == Boolean.TYPE && src == Boolean.class) || assignable;
    assignable = (dest == Byte.TYPE && src == Byte.class) || assignable;
    assignable = (dest == Character.TYPE && src == Character.class) || assignable;
    assignable = (dest == Short.TYPE && src == Short.class) || assignable;
    assignable = (dest == Integer.TYPE && src == Integer.class) || assignable;
    assignable = (dest == Long.TYPE && src == Long.class) || assignable;
    assignable = (dest == Float.TYPE && src == Float.class) || assignable;
    assignable = (dest == Double.TYPE && src == Double.class) || assignable;

    if (src == Double.TYPE || Double.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest))
                || assignable;
    }
    if (src == Float.TYPE || Float.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) || assignable;
    }
    if (src == Long.TYPE || Long.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) || assignable;
    }
    if (src == Integer.TYPE || Integer.class.isAssignableFrom(src))
        assignable = (isByte(dest) || isShort(dest)) || assignable;
    if (src == Short.TYPE || Short.class.isAssignableFrom(src)) {
        assignable = (isByte(dest)) || assignable;
    }

    return assignable;
}

From source file:org.apache.mina.statemachine.transition.MethodTransition.java

@SuppressWarnings("unchecked")
private boolean match(Class<?> paramType, Object arg, Class argType) {
    if (paramType.isPrimitive()) {
        if (paramType.equals(Boolean.TYPE)) {
            return arg instanceof Boolean;
        }//  www.j a va  2  s. c o m
        if (paramType.equals(Integer.TYPE)) {
            return arg instanceof Integer;
        }
        if (paramType.equals(Long.TYPE)) {
            return arg instanceof Long;
        }
        if (paramType.equals(Short.TYPE)) {
            return arg instanceof Short;
        }
        if (paramType.equals(Byte.TYPE)) {
            return arg instanceof Byte;
        }
        if (paramType.equals(Double.TYPE)) {
            return arg instanceof Double;
        }
        if (paramType.equals(Float.TYPE)) {
            return arg instanceof Float;
        }
        if (paramType.equals(Character.TYPE)) {
            return arg instanceof Character;
        }
    }
    return argType.isAssignableFrom(paramType) && paramType.isAssignableFrom(arg.getClass());
}

From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.bean.MorphDynaBean.java

protected boolean isDynaAssignable(Class dest, Class src) {
    boolean assignable = dest.isAssignableFrom(src);
    if (assignable) {
        return true;
    }//from www.  java  2 s . c  o  m
    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;
    }
    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:org.robobinding.util.ClassUtils.java

/**
 * <p>/*from   w  ww . j  av a2  s  .c  om*/
 * Checks if one {@code Class} can be assigned to a variable of another
 * {@code Class}.
 * </p>
 * 
 * <p>
 * Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method, this
 * method takes into account widenings of primitive classes and {@code null}
 * s.
 * </p>
 * 
 * <p>
 * Primitive widenings allow an int to be assigned to a long, float or
 * double. This method returns the correct result for these cases.
 * </p>
 * 
 * <p>
 * {@code Null} may be assigned to any reference type. This method will
 * return {@code true} if {@code null} is passed in and the toClass is
 * non-primitive.
 * </p>
 * 
 * <p>
 * Specifically, this method tests whether the type represented by the
 * specified {@code Class} parameter can be converted to the type
 * represented by this {@code Class} object via an identity conversion
 * widening primitive or widening reference conversion. See
 * <em><a href="http://docs.oracle.com/javase/specs/">The Java Language Specification</a></em>
 * , sections 5.1.1, 5.1.2 and 5.1.4 for details.
 * </p>
 * 
 * @param cls
 *            the Class to check, may be null
 * @param toClass
 *            the Class to try to assign into, returns false if null
 * @param autoboxing
 *            whether to use implicit autoboxing/unboxing between primitives
 *            and wrappers
 * @return {@code true} if assignment possible
 */
public static boolean isAssignable(Class<?> cls, final Class<?> toClass, final boolean autoboxing) {
    if (toClass == null) {
        return false;
    }
    // have to check for null, as isAssignableFrom doesn't
    if (cls == null) {
        return !toClass.isPrimitive();
    }
    // autoboxing:
    if (autoboxing) {
        if (cls.isPrimitive() && !toClass.isPrimitive()) {
            cls = primitiveToWrapper(cls);
            if (cls == null) {
                return false;
            }
        }
        if (toClass.isPrimitive() && !cls.isPrimitive()) {
            cls = wrapperToPrimitive(cls);
            if (cls == null) {
                return false;
            }
        }
    }
    if (cls.equals(toClass)) {
        return true;
    }
    if (cls.isPrimitive()) {
        if (toClass.isPrimitive() == false) {
            return false;
        }
        if (Integer.TYPE.equals(cls)) {
            return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass);
        }
        if (Long.TYPE.equals(cls)) {
            return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass);
        }
        if (Boolean.TYPE.equals(cls)) {
            return false;
        }
        if (Double.TYPE.equals(cls)) {
            return false;
        }
        if (Float.TYPE.equals(cls)) {
            return Double.TYPE.equals(toClass);
        }
        if (Character.TYPE.equals(cls)) {
            return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass)
                    || Double.TYPE.equals(toClass);
        }
        if (Short.TYPE.equals(cls)) {
            return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass)
                    || Double.TYPE.equals(toClass);
        }
        if (Byte.TYPE.equals(cls)) {
            return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass)
                    || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass);
        }
        // should never get here
        return false;
    }
    return toClass.isAssignableFrom(cls);
}