Example usage for java.lang Byte TYPE

List of usage examples for java.lang Byte TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type byte .

Usage

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

/**
 * <p>/* w  w  w.j  a  v a  2  s.  c o  m*/
 * 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);
}

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

/**
 * <p>Checks if one/*w w w.j a  va  2s .c om*/
 * <code>Class</code> can be assigned to a variable of another
 * <code>Class</code>.</p>
 *
 * <p>Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method,
 * this method takes into account widenings of primitive classes and
 * <code>null</code>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</code> may be assigned to any reference type. This method
 * will return
 * <code>true</code> if
 * <code>null</code> is passed in and the toClass is non-primitive.</p>
 *
 * <p>Specifically, this method tests whether the type represented by the
 * specified
 * <code>Class</code> parameter can be converted to the type represented by
 * this
 * <code>Class</code> object via an identity conversion widening primitive
 * or widening reference conversion. See <em><a
 * href="http://java.sun.com/docs/books/jls/">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</code> if assignment possible
 * @since 2.5
 */
public static boolean isAssignable(Class cls, Class toClass, 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);
}

From source file:com.appleframework.jmx.core.services.MBeanServiceImpl.java

private Class<?> getClass(String type, ClassLoader classLoader) {
    if (type.equals("boolean"))
        return Boolean.class;
    if (type.equals("byte"))
        return Byte.TYPE;
    if (type.equals("char"))
        return Character.class;
    if (type.equals("double"))
        return Double.class;
    if (type.equals("float"))
        return Float.class;
    if (type.equals("int"))
        return Integer.class;
    if (type.equals("long"))
        return Long.class;
    if (type.equals("short"))
        return Short.class;
    if (type.equals("void"))
        return Void.class;
    Class<?> clazz = null;// ww w  .j av a  2s  . c om
    try {
        clazz = Class.forName(type, true, classLoader);

    } catch (ClassNotFoundException e) {
        logger.info("Error finding class of type=" + type + ", error=" + e.getMessage());
    }
    return clazz;
}

From source file:com.netspective.commons.lang.ValueBeanGeneratorClassLoader.java

/**
 * Convert runtime java.lang.Class to BCEL Type object.
 *
 * @param cl Java class//from   w w  w  . j av a  2s .  c  o m
 *
 * @return corresponding Type object
 */
public static Type getBCELType(java.lang.Class cl) {
    if (cl == null) {
        throw new IllegalArgumentException("Class must not be null");
    }

    /* That's an amzingly easy case, because getName() returns
     * the signature. That's what we would have liked anyway.
     */
    if (cl.isArray()) {
        return Type.getType(cl.getName());
    } else if (cl.isPrimitive()) {
        if (cl == Integer.TYPE) {
            return Type.INT;
        } else if (cl == Void.TYPE) {
            return Type.VOID;
        } else if (cl == Double.TYPE) {
            return Type.DOUBLE;
        } else if (cl == Float.TYPE) {
            return Type.FLOAT;
        } else if (cl == Boolean.TYPE) {
            return Type.BOOLEAN;
        } else if (cl == Byte.TYPE) {
            return Type.BYTE;
        } else if (cl == Short.TYPE) {
            return Type.SHORT;
        } else if (cl == Long.TYPE) {
            return Type.LONG;
        } else if (cl == Character.TYPE) {
            return Type.CHAR;
        } else {
            throw new IllegalStateException("Ooops, what primitive type is " + cl);
        }
    } else { // "Real" class
        return new ObjectType(cl.getName());
    }
}

From source file:us.mn.state.health.lims.testanalyte.form.TestAnalyteTestResultActionForm.java

/**
 * <p>/*from ww  w.  j ava2s . c  om*/
 * Return the value of a simple property with the specified name.
 * </p>
 * 
 * @param name
 *            Name of the property whose value is to be retrieved
 * 
 * @exception IllegalArgumentException
 *                if there is no property of the specified name
 * @exception NullPointerException
 *                if the type specified for the property is invalid
 */
public Object get(String name) {

    // Return any non-null value for the specified property
    Object value = dynaValues.get(name);

    //System.out.println("I am in get(String name) " + name + " " + value);
    if (value != null) {
        return (value);
    }

    // Return a null value for a non-primitive property
    Class type = getDynaProperty(name).getType();
    if (type == null) {
        throw new NullPointerException("The type for property " + name + " is invalid");
    }
    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(0.0));
    } else if (type == Float.TYPE) {
        return (new Float((float) 0.0));
    } else if (type == Integer.TYPE) {
        return (new Integer(0));
    } else if (type == Long.TYPE) {
        return (new Long(0));
    } else if (type == Short.TYPE) {
        return (new Short((short) 0));
    } else {
        return (null);
    }

}

From source file:com.mawujun.util.AnnotationUtils.java

/**
 * Helper method for comparing two objects of an array type.
 *
 * @param componentType the component type of the array
 * @param o1 the first object/*  w w w  . j a  v a2 s.  c om*/
 * @param o2 the second object
 * @return a flag whether these objects are equal
 */
private static boolean arrayMemberEquals(Class<?> componentType, Object o1, Object o2) {
    if (componentType.isAnnotation()) {
        return annotationArrayMemberEquals((Annotation[]) o1, (Annotation[]) o2);
    }
    if (componentType.equals(Byte.TYPE)) {
        return Arrays.equals((byte[]) o1, (byte[]) o2);
    }
    if (componentType.equals(Short.TYPE)) {
        return Arrays.equals((short[]) o1, (short[]) o2);
    }
    if (componentType.equals(Integer.TYPE)) {
        return Arrays.equals((int[]) o1, (int[]) o2);
    }
    if (componentType.equals(Character.TYPE)) {
        return Arrays.equals((char[]) o1, (char[]) o2);
    }
    if (componentType.equals(Long.TYPE)) {
        return Arrays.equals((long[]) o1, (long[]) o2);
    }
    if (componentType.equals(Float.TYPE)) {
        return Arrays.equals((float[]) o1, (float[]) o2);
    }
    if (componentType.equals(Double.TYPE)) {
        return Arrays.equals((double[]) o1, (double[]) o2);
    }
    if (componentType.equals(Boolean.TYPE)) {
        return Arrays.equals((boolean[]) o1, (boolean[]) o2);
    }
    return Arrays.equals((Object[]) o1, (Object[]) o2);
}

From source file:de.ma.it.common.sm.transition.MethodTransition.java

private boolean match(Class<?> paramType, Object arg, Class<?> argType) {
    if (paramType.isPrimitive()) {
        if (paramType.equals(Boolean.TYPE)) {
            return arg instanceof Boolean;
        }// w  ww  .j a va2s. 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:com.haulmont.restapi.service.QueriesControllerManager.java

protected Object toObject(Class clazz, String value) throws ParseException {
    if (clazz.isArray()) {
        Class componentType = clazz.getComponentType();
        JsonParser jsonParser = new JsonParser();
        JsonArray jsonArray = jsonParser.parse(value).getAsJsonArray();
        List result = new ArrayList();
        for (JsonElement jsonElement : jsonArray) {
            String stringValue = (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString())
                    ? jsonElement.getAsJsonPrimitive().getAsString()
                    : jsonElement.toString();
            Object arrayElementValue = toObject(componentType, stringValue);
            result.add(arrayElementValue);
        }//from   w  w  w .ja  v a2  s.c o  m
        return result;
    }
    if (String.class == clazz)
        return value;
    if (Integer.class == clazz || Integer.TYPE == clazz || Byte.class == clazz || Byte.TYPE == clazz
            || Short.class == clazz || Short.TYPE == clazz)
        return Datatypes.getNN(Integer.class).parse(value);
    if (Date.class == clazz) {
        try {
            return Datatypes.getNN(Date.class).parse(value);
        } catch (ParseException e) {
            try {
                return Datatypes.getNN(java.sql.Date.class).parse(value);
            } catch (ParseException e1) {
                return Datatypes.getNN(Time.class).parse(value);
            }
        }
    }
    if (BigDecimal.class == clazz)
        return Datatypes.getNN(BigDecimal.class).parse(value);
    if (Boolean.class == clazz || Boolean.TYPE == clazz)
        return Datatypes.getNN(Boolean.class).parse(value);
    if (Long.class == clazz || Long.TYPE == clazz)
        return Datatypes.getNN(Long.class).parse(value);
    if (Double.class == clazz || Double.TYPE == clazz || Float.class == clazz || Float.TYPE == clazz)
        return Datatypes.getNN(Double.class).parse(value);
    if (UUID.class == clazz)
        return UUID.fromString(value);
    throw new IllegalArgumentException("Parameters of type " + clazz.getName() + " are not supported");
}

From source file:org.openamf.io.AMFSerializer.java

protected Object[] convertPrimitiveArrayToObjectArray(Object array) throws IOException {
    Class componentType = array.getClass().getComponentType();

    Object[] result = null;/*from   w w  w. j  a  v a2s  . c  o  m*/

    if (componentType == null) {
        throw new NullPointerException("componentType is null");
    } else if (componentType == Character.TYPE) {
        char[] carray = (char[]) array;
        result = new Object[carray.length];
        for (int i = 0; i < carray.length; i++) {
            result[i] = new Character(carray[i]);
        }
    } else if (componentType == Byte.TYPE) {
        byte[] barray = (byte[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Byte(barray[i]);
        }
    } else if (componentType == Short.TYPE) {
        short[] sarray = (short[]) array;
        result = new Object[sarray.length];
        for (int i = 0; i < sarray.length; i++) {
            result[i] = new Short(sarray[i]);
        }
    } else if (componentType == Integer.TYPE) {
        int[] iarray = (int[]) array;
        result = new Object[iarray.length];
        for (int i = 0; i < iarray.length; i++) {
            result[i] = new Integer(iarray[i]);
        }
    } else if (componentType == Long.TYPE) {
        long[] larray = (long[]) array;
        result = new Object[larray.length];
        for (int i = 0; i < larray.length; i++) {
            result[i] = new Long(larray[i]);
        }
    } else if (componentType == Double.TYPE) {
        double[] darray = (double[]) array;
        result = new Object[darray.length];
        for (int i = 0; i < darray.length; i++) {
            result[i] = new Double(darray[i]);
        }
    } else if (componentType == Float.TYPE) {
        float[] farray = (float[]) array;
        result = new Object[farray.length];
        for (int i = 0; i < farray.length; i++) {
            result[i] = new Float(farray[i]);
        }
    } else if (componentType == Boolean.TYPE) {
        boolean[] barray = (boolean[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Boolean(barray[i]);
        }
    } else {
        throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName());
    }

    return result;
}

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

public static Object assignValueToLiteral(String v, Class<?> type) {
    Object value;//  w w  w.  j a v  a 2s.  c  o  m
    if (v.length() == 0) {
        value = null;
    } else {
        if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
            value = Integer.parseInt(v);
        } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
            value = Long.parseLong(v);
        } else if (type.equals(Short.class) || type.equals(Short.TYPE)) {
            value = Short.parseShort(v);
        } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
            value = Boolean.parseBoolean(v);
        } else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
            value = Float.parseFloat(v);
        } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
            value = Double.parseDouble(v);
        } else if (type.equals(Byte.class) || type.equals(Byte.TYPE)) {
            value = Byte.parseByte(v);
        } else if (type.equals(Character.class) || type.equals(Character.TYPE)) {
            value = v.charAt(0);
        } else {
            value = v;
        }
    }
    return value;
}