Example usage for java.lang Character TYPE

List of usage examples for java.lang Character TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type char .

Usage

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;
        }//from   w w w .  j a v a2s . 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.acmsl.commons.utils.ConversionUtils.java

/**
 * Converts given String to char, if given value is not null.
 * @param value the value to convert./*www.j  av  a  2  s. c  om*/
 * @return the converted value.
 */
@Nullable
public Character toCharIfNotNull(@Nullable final String value) {
    Character result = null;

    @Nullable
    final Converter t_Converter = ConvertUtils.lookup(Character.TYPE);

    if (t_Converter != null) {
        @Nullable
        final Object t_Result = t_Converter.convert(Character.TYPE, value);

        if (t_Result instanceof Character) {
            result = (Character) t_Result;
        }
    }

    return result;
}

From source file:io.nuun.plugin.configuration.common.ConfigurationMembersInjector.java

@Override
public void injectMembers(T instance) {
    NuunProperty injectConfigAnnotation = null;
    // The annotation is actual NuunProperty.class
    if (clonedAnno.annotationType() == NuunProperty.class) {
        injectConfigAnnotation = field.getAnnotation(NuunProperty.class);
    } else { // The annotation has the NuunProperty annotation on it we proxy it
        injectConfigAnnotation = AssertUtils.annotationProxyOf(NuunProperty.class, clonedAnno);
    }//from   w w  w.  j  a  v a 2 s  .  co m

    String configurationParameterName = injectConfigAnnotation.value();

    // Pre verification //
    if (StringUtils.isEmpty(configurationParameterName)) {
        log.error("Value for annotation {} on field {} can not be null or empty.", clonedAnno.annotationType(),
                field.toGenericString());
        throw new PluginException("Value for annotation %s on field %s can not be null or empty.",
                clonedAnno.annotationType(), field.toGenericString());
    }

    if (!configuration.containsKey(configurationParameterName) && injectConfigAnnotation.mandatory()) {
        throw new PluginException("\"%s\" must be in one properties file for field %s.",
                configurationParameterName, field.toGenericString());
    }

    try {
        this.field.setAccessible(true);
        Class<?> type = field.getType();
        if (type == Integer.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setInt(instance, configuration.getInt(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setInt(instance, injectConfigAnnotation.defaultIntValue());
            }
        } else if (type == Integer.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Integer(configuration.getInt(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Integer(injectConfigAnnotation.defaultIntValue()));
            }
        } else if (type == Boolean.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setBoolean(instance, configuration.getBoolean(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setBoolean(instance, injectConfigAnnotation.defaultBooleanValue());
            }

        } else if (type == Boolean.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Boolean(configuration.getBoolean(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Boolean(injectConfigAnnotation.defaultBooleanValue()));
            }

        } else if (type == Short.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setShort(instance, configuration.getShort(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setShort(instance, injectConfigAnnotation.defaultShortValue());
            }
        } else if (type == Short.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Short(configuration.getShort(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Short(injectConfigAnnotation.defaultShortValue()));
            }
        } else if (type == Byte.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setByte(instance, configuration.getByte(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setByte(instance, injectConfigAnnotation.defaultByteValue());
            }
        } else if (type == Byte.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Byte(configuration.getByte(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Byte(injectConfigAnnotation.defaultByteValue()));
            }
        } else if (type == Long.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setLong(instance, configuration.getLong(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setLong(instance, injectConfigAnnotation.defaultLongValue());
            }
        } else if (type == Long.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Long(configuration.getLong(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Long(injectConfigAnnotation.defaultLongValue()));
            }
        } else if (type == Float.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setFloat(instance, configuration.getFloat(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setFloat(instance, injectConfigAnnotation.defaultFloatValue());
            }
        } else if (type == Float.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Float(configuration.getFloat(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Float(injectConfigAnnotation.defaultFloatValue()));
            }
        } else if (type == Double.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setDouble(instance, configuration.getDouble(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setDouble(instance, injectConfigAnnotation.defaultDoubleValue());
            }
        } else if (type == Double.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Double(configuration.getDouble(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Double(injectConfigAnnotation.defaultDoubleValue()));
            }
        } else if (type == Character.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setChar(instance, configuration.getString(configurationParameterName).charAt(0));
            }
        } else if (type == Character.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance,
                        new Character(configuration.getString(configurationParameterName).charAt(0)));
            }
        } else {
            Object property = getProperty(configurationParameterName, injectConfigAnnotation);
            field.set(instance, property);
        }
    } catch (IllegalArgumentException ex) {
        log.error("Wrong argument or argument type during configuration injection", ex);
    } catch (IllegalAccessException ex) {
        log.error("Illegal access during configuration injection", ex);
    } catch (InstantiationException ex) {
        log.error("Impossible to instantiate value converter", ex);
    } finally {
        this.field.setAccessible(false);
    }
}

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

/**
 * <p>//from   w w  w  .ja v  a 2  s  .c  o m
 * 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.opengamma.language.definition.JavaTypeInfo.java

private static Class<?> findClass(final String className) throws ClassNotFoundException {
    if ("boolean".equals(className)) {
        return Boolean.TYPE;
    } else if ("char".equals(className)) {
        return Character.TYPE;
    } else if ("double".equals(className)) {
        return Double.TYPE;
    } else if ("float".equals(className)) {
        return Float.TYPE;
    } else if ("int".equals(className)) {
        return Integer.TYPE;
    } else if ("long".equals(className)) {
        return Long.TYPE;
    } else if ("short".equals(className)) {
        return Short.TYPE;
    } else {/*from   w  w w  . ja  v a 2 s . c o m*/
        return Class.forName(className);
    }
}

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 .ja v  a2 s .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.wisdom.template.thymeleaf.OgnlOpsByReflectionTest.java

@Test
public void testConvertValue() throws Exception {
    Class[] classes = new Class[] { Object.class, Class.class };
    // Null value
    assertThat(invoke("convertValue", classes, null, Long.TYPE)).isEqualTo(0l);
    assertThat(invoke("convertValue", classes, null, String.class)).isNull();

    // Primitive//from   w w w  . j  a va  2  s  . com
    assertThat(invoke("convertValue", classes, "42", Integer.class)).isEqualTo(42);
    assertThat(invoke("convertValue", classes, "42", Integer.TYPE)).isEqualTo(42);
    assertThat(invoke("convertValue", classes, "42", Byte.class)).isEqualTo(Byte.valueOf("42"));
    assertThat(invoke("convertValue", classes, "42", Byte.TYPE)).isEqualTo(Byte.valueOf("42"));
    assertThat(invoke("convertValue", classes, "42", Short.class)).isEqualTo(Short.valueOf("42"));
    assertThat(invoke("convertValue", classes, "42", Short.TYPE)).isEqualTo(Short.valueOf("42"));
    assertThat(invoke("convertValue", classes, String.valueOf((int) 'c'), Character.class)).isEqualTo('c');
    assertThat(invoke("convertValue", classes, String.valueOf((int) 'c'), Character.TYPE)).isEqualTo('c');
    assertThat(invoke("convertValue", classes, "42", Long.class)).isEqualTo(42l);
    assertThat(invoke("convertValue", classes, "42", Long.TYPE)).isEqualTo(42l);
    assertThat(invoke("convertValue", classes, "true", Boolean.class)).isEqualTo(true);
    assertThat(invoke("convertValue", classes, "true", Boolean.TYPE)).isEqualTo(true);
    assertThat(invoke("convertValue", classes, "42", Double.class)).isEqualTo(42.0);
    assertThat(invoke("convertValue", classes, "42", Double.TYPE)).isEqualTo(42.0);
    assertThat(invoke("convertValue", classes, "42", Float.class)).isEqualTo(42.0f);
    assertThat(invoke("convertValue", classes, "42", Float.TYPE)).isEqualTo(42.0f);

    // BigInteger, BigDecimal and String
    assertThat(invoke("convertValue", classes, "42", BigDecimal.class)).isEqualTo(new BigDecimal("42"));
    assertThat(invoke("convertValue", classes, "42", BigInteger.class)).isEqualTo(new BigInteger("42"));
    assertThat(invoke("convertValue", classes, "42", String.class)).isEqualTo("42");

    //Array
    assertThat(invoke("convertValue", classes, new Object[] { 1, 2, 3 }, (new int[0]).getClass())).isNotNull();
}

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

/**
 * Convert runtime java.lang.Class to BCEL Type object.
 *
 * @param cl Java class//from   www . jav a2 s .com
 *
 * @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: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//from  w  ww  .ja  v  a2  s  . co m
 * @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:com.exadel.flamingo.flex.messaging.amf.io.AMF0Serializer.java

protected Object[] convertPrimitiveArrayToObjectArray(Object array) {
    Class<?> componentType = array.getClass().getComponentType();

    Object[] result = null;//ww  w.j  av  a 2 s  . c om

    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] = Integer.valueOf(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;
}