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.evosuite.testcase.fm.MethodDescriptor.java

private String initMatchers(GenericMethod method, GenericClass retvalType) {

    String matchers = "";
    Type[] types = method.getParameterTypes();
    List<GenericClass> parameterClasses = method.getParameterClasses();
    for (int i = 0; i < types.length; i++) {
        if (i > 0) {
            matchers += " , ";
        }/* w  w  w  .ja v  a 2  s .c o  m*/

        Type type = types[i];
        GenericClass genericParameter = parameterClasses.get(i);
        if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
            matchers += "anyInt()";
        } else if (type.equals(Long.TYPE) || type.equals(Long.class)) {
            matchers += "anyLong()";
        } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
            matchers += "anyBoolean()";
        } else if (type.equals(Double.TYPE) || type.equals(Double.class)) {
            matchers += "anyDouble()";
        } else if (type.equals(Float.TYPE) || type.equals(Float.class)) {
            matchers += "anyFloat()";
        } else if (type.equals(Short.TYPE) || type.equals(Short.class)) {
            matchers += "anyShort()";
        } else if (type.equals(Character.TYPE) || type.equals(Character.class)) {
            matchers += "anyChar()";
        } else if (type.equals(String.class)) {
            matchers += "anyString()";
        } else {
            if (type.getTypeName().equals(Object.class.getName())) {
                /*
                Ideally here we should use retvalType to understand if the target class
                is using generics and if this method parameters would need to be handled
                accordingly. However, doing it does not seem so trivial...
                so a current workaround is that, when a method takes an Object as input (which is
                that would happen in case of Generics T), we use the undetermined "any()"
                 */
                matchers += "any()";
            } else {
                if (type instanceof Class) {
                    matchers += "any(" + ((Class) type).getCanonicalName() + ".class)";
                } else {
                    //what to do here? is it even possible?
                    matchers += "any(" + genericParameter.getRawClass().getCanonicalName() + ".class)";
                    // matchers += "any(" + type.getTypeName() + ".class)";
                }
            }
        }
    }

    return matchers;
}

From source file:org.apache.click.util.RequestTypeConverter.java

/**
 * Return the converted value for the given value object and target type.
 *
 * @param value the value object to convert
 * @param toType the target class type to convert the value to
 * @return a converted value into the specified type
 *//*  w ww  .jav  a 2 s  .c o  m*/
protected Object convertValue(Object value, Class<?> toType) {
    Object result = null;

    if (value != null) {

        // If array -> array then convert components of array individually
        if (value.getClass().isArray() && toType.isArray()) {
            Class<?> componentType = toType.getComponentType();

            result = Array.newInstance(componentType, Array.getLength(value));

            for (int i = 0, icount = Array.getLength(value); i < icount; i++) {
                Array.set(result, i, convertValue(Array.get(value, i), componentType));
            }

        } else {
            if ((toType == Integer.class) || (toType == Integer.TYPE)) {
                result = Integer.valueOf((int) OgnlOps.longValue(value));

            } else if ((toType == Double.class) || (toType == Double.TYPE)) {
                result = new Double(OgnlOps.doubleValue(value));

            } else if ((toType == Boolean.class) || (toType == Boolean.TYPE)) {
                result = Boolean.valueOf(value.toString());

            } else if ((toType == Byte.class) || (toType == Byte.TYPE)) {
                result = Byte.valueOf((byte) OgnlOps.longValue(value));

            } else if ((toType == Character.class) || (toType == Character.TYPE)) {
                result = Character.valueOf((char) OgnlOps.longValue(value));

            } else if ((toType == Short.class) || (toType == Short.TYPE)) {
                result = Short.valueOf((short) OgnlOps.longValue(value));

            } else if ((toType == Long.class) || (toType == Long.TYPE)) {
                result = Long.valueOf(OgnlOps.longValue(value));

            } else if ((toType == Float.class) || (toType == Float.TYPE)) {
                result = new Float(OgnlOps.doubleValue(value));

            } else if (toType == BigInteger.class) {
                result = OgnlOps.bigIntValue(value);

            } else if (toType == BigDecimal.class) {
                result = bigDecValue(value);

            } else if (toType == String.class) {
                result = OgnlOps.stringValue(value);

            } else if (toType == java.util.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.util.Date(time);
                }

            } else if (toType == java.sql.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Date(time);
                }

            } else if (toType == java.sql.Time.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Time(time);
                }

            } else if (toType == java.sql.Timestamp.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Timestamp(time);
                }
            }
        }

    } else {
        if (toType.isPrimitive()) {
            result = OgnlRuntime.getPrimitiveDefaultValue(toType);
        }
    }
    return result;
}

From source file:org.trianacode.taskgraph.tool.ClassLoaders.java

public static Class forName(String className) throws ClassNotFoundException {
    className = getTextClassName(className);
    boolean isArray = false;
    int dims = 0;
    if (className.endsWith("[]")) {
        isArray = true;/*w  w w . j  a  v a2 s . c om*/
        dims = className.substring(className.indexOf("[]"), className.length()).length() / 2;
        className = className.substring(0, className.indexOf("[]"));

    }
    Class cls;
    if (className.equals("boolean")) {
        cls = Boolean.TYPE;
    } else if (className.equals("char")) {
        cls = Character.TYPE;
    } else if (className.equals("byte")) {
        cls = Byte.TYPE;
    } else if (className.equals("short")) {
        cls = Short.TYPE;
    } else if (className.equals("int")) {
        cls = Integer.TYPE;
    } else if (className.equals("long")) {
        cls = Long.TYPE;
    } else if (className.equals("float")) {
        cls = Float.TYPE;
    } else if (className.equals("double")) {
        cls = Double.TYPE;
    } else if (className.equals("void")) {
        cls = void.class;
    } else {
        cls = loadClass(className);
    }
    if (isArray) {
        Object arr = Array.newInstance(cls, new int[dims]);
        cls = arr.getClass();
    }
    return cls;
}

From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java

/** Constructs instance and property name and class.
* @param name property name.//w w w.ja  v a2  s.co  m
* @param cls value object <code>Class</code>.
* @param readMethodName name of the read <code>Method</code>
* @param writeMethodName name of the write <code>Method</code>
*/
public PersistentObjectDynaProperty(String name, Class cls, String readMethodName, String writeMethodName) {
    super(name, cls);
    this.readMethodName = readMethodName;
    this.writeMethodName = writeMethodName;
    if (cls.isPrimitive()) {
        if (cls.equals(Boolean.TYPE))
            primitiveWrapperClass = Boolean.class;
        else if (cls.equals(Byte.TYPE))
            primitiveWrapperClass = Byte.class;
        else if (cls.equals(Character.TYPE))
            primitiveWrapperClass = Character.class;
        else if (cls.equals(Double.TYPE))
            primitiveWrapperClass = Double.class;
        else if (cls.equals(Float.TYPE))
            primitiveWrapperClass = Float.class;
        else if (cls.equals(Integer.TYPE))
            primitiveWrapperClass = Integer.class;
        else if (cls.equals(Long.TYPE))
            primitiveWrapperClass = Long.class;
        else if (cls.equals(Short.TYPE))
            primitiveWrapperClass = Short.class;

    } else if (java.util.List.class.isAssignableFrom(cls) || cls.isArray()) {
        indexed = true;
    } else if (java.util.Map.class.isAssignableFrom(cls)) {
        mapped = true;
    }
}

From source file:org.skfiy.typhon.spi.GMConsoleProvider.java

/**
 *
 * @param uid//from  w  w  w .j  a  v  a  2 s .c  o m
 * @param propertyName
 * @param val
 * @throws javax.management.MBeanException
 */
public void changeProperty(final String uid, final String propertyName, final String val)
        throws MBeanException {
    try {
        invoke(transcoding(uid), new Handler() {

            @Override
            void execute() {
                Player player = SessionUtils.getPlayer();
                try {
                    Class<?> propertyType = PropertyUtils.getPropertyType(player, propertyName);
                    if (propertyType == null) { // Not found property
                        throw new IllegalArgumentException("Not found property[" + propertyName + "]");
                    }

                    if (propertyType == Byte.class || propertyType == Byte.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Byte.valueOf(val));
                    } else if (propertyType == Character.class || propertyType == Character.TYPE) {
                        BeanUtils.setProperty(player, propertyName, val.charAt(0));
                    } else if (propertyType == Boolean.class || propertyType == Boolean.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Boolean.valueOf(val));
                    } else if (propertyType == Integer.class || propertyType == Integer.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Integer.valueOf(val));
                    } else if (propertyType == Long.class || propertyType == Long.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Long.valueOf(val));
                    } else if (propertyType == Float.class || propertyType == Float.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Float.valueOf(val));
                    } else if (propertyType == Double.class || propertyType == Double.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Double.valueOf(val));
                    } else {
                        BeanUtils.setProperty(player, propertyName, val);
                    }

                } catch (Exception ex) {
                    throw new IllegalArgumentException(ex.getMessage());
                }
            }

        });
    } catch (Exception e) {
        throw new MBeanException(e, e.getMessage());
    }
}

From source file:com.github.michalbednarski.intentslab.Utils.java

public static Object getDefaultValueForPrimitveClass(Class<?> aClass) {
    if (aClass == Boolean.TYPE) {
        return false;
    } else if (aClass == Byte.TYPE) {
        return (byte) 0;
    } else if (aClass == Character.TYPE) {
        return 0;
    } else if (aClass == Short.TYPE) {
        return (short) 0;
    } else if (aClass == Integer.TYPE) {
        return 0;
    } else if (aClass == Long.TYPE) {
        return (long) 0;
    } else if (aClass == Float.TYPE) {
        return 0;
    } else if (aClass == Double.TYPE) {
        return 0;
    } else {//from   w ww .j av  a 2s  .  com
        throw new RuntimeException("Not primitive type");
    }
}

From source file:Main.java

/**
 * renderArray returns an array similar to a List. If the array type is an
 * object they are rendered with "render(object)" for each. If the array
 * type is a primitive each element is added directly to the string buffer
 * collecting the result./*from   www  .j a v a  2  s . c  o m*/
 * 
 * @param o
 * @param objectClass
 * @return
 */
private static StringBuffer renderArray(Object o, Class<?> objectClass) {
    Class<?> componentType = objectClass.getComponentType();
    StringBuffer sb = new StringBuffer(ARRAY_PREFIX);

    if (componentType.isPrimitive() == false) {
        Object[] oa = (Object[]) o;
        for (int i = 0; i < oa.length; i++) {
            if (i > 0) {
                sb.append(ELEMENT_SEPARATOR);
            }
            sb.append(render(oa[i]));
        }
    } else {
        if (Boolean.TYPE.equals(componentType)) {
            boolean[] ba = (boolean[]) o;
            for (int i = 0; i < ba.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ba[i]);
            }
        } else if (Integer.TYPE.equals(componentType)) {
            int[] ia = (int[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }

        } else if (Long.TYPE.equals(componentType)) {
            long[] ia = (long[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Double.TYPE.equals(componentType)) {
            double[] ia = (double[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Float.TYPE.equals(componentType)) {
            float[] ia = (float[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Character.TYPE.equals(componentType)) {
            char[] ia = (char[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Short.TYPE.equals(componentType)) {
            short[] ia = (short[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Byte.TYPE.equals(componentType)) {
            byte[] ia = (byte[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        }
    }
    sb.append(ARRAY_SUFFIX);
    return sb;
}

From source file:io.coala.guice.config.ConfigMembersInjector.java

@Override
public void injectMembers(final T instance) {
    final InjectConfig injectConfigAnnotation = field.getAnnotation(InjectConfig.class);
    final String configurationParameterName = injectConfigAnnotation.name();
    try {// w  w  w .j  a v  a 2  s .c  o  m
        final Class<?> type = this.field.getType();
        if (type == Integer.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setInt(instance, this.configuration.getInt(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setInt(instance, injectConfigAnnotation.defaultIntValue());
            }
        } else if (type == Boolean.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setBoolean(instance, this.configuration.getBoolean(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setBoolean(instance, injectConfigAnnotation.defaultBooleanValue());
            }

        } else if (type == Short.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setShort(instance, this.configuration.getShort(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setShort(instance, injectConfigAnnotation.defaultShortValue());
            }
        } else if (type == Byte.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setByte(instance, this.configuration.getByte(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setByte(instance, injectConfigAnnotation.defaultByteValue());
            }
        } else if (type == Long.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setLong(instance, this.configuration.getLong(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setLong(instance, injectConfigAnnotation.defaultLongValue());
            }
        } else if (type == Float.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setFloat(instance, this.configuration.getFloat(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setFloat(instance, injectConfigAnnotation.defaultFloatValue());
            }
        } else if (type == Double.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setDouble(instance, this.configuration.getDouble(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setDouble(instance, injectConfigAnnotation.defaultDoubleValue());
            }
        } else if (type == Character.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setChar(instance,
                        this.configuration.getString(configurationParameterName).charAt(0));
            }
        } else {
            final Object property = getProperty(configurationParameterName, injectConfigAnnotation);
            this.field.set(instance, property);
        }
    } catch (final Throwable ex) {
        LOG.error("Problem injecting configuration", ex);
    }
}

From source file:jef.tools.ArrayUtils.java

/**
 * ?//from w w  w.j a  v a 2s. c o m
 * 
 * @param obj
 * @return
 */
public static Object[] toObject(Object obj) {
    Class<?> c = obj.getClass();
    Assert.isTrue(c.isArray());
    Class<?> priType = c.getComponentType();
    if (!priType.isPrimitive())
        return (Object[]) obj;
    if (priType == Boolean.TYPE) {
        return toObject((boolean[]) obj);
    } else if (priType == Byte.TYPE) {
        return toObject((byte[]) obj);
    } else if (priType == Character.TYPE) {
        return toObject((char[]) obj);
    } else if (priType == Integer.TYPE) {
        return toObject((int[]) obj);
    } else if (priType == Long.TYPE) {
        return toObject((long[]) obj);
    } else if (priType == Float.TYPE) {
        return toObject((float[]) obj);
    } else if (priType == Double.TYPE) {
        return toObject((double[]) obj);
    } else if (priType == Short.TYPE) {
        return toObject((short[]) obj);
    }
    throw new IllegalArgumentException();
}

From source file:org.atemsource.atem.impl.common.attribute.primitive.PrimitiveTypeFactory.java

@PostConstruct
public void initialize() {
    classes = new ArrayList<Class>();
    classes.add(String.class);
    classes.add(Boolean.class);
    classes.add(Boolean.TYPE);/*  w  w  w  .j a  va  2s.c  o  m*/
    classes.add(Long.class);
    classes.add(Long.TYPE);
    classes.add(Integer.class);
    classes.add(Integer.TYPE);
    classes.add(Float.class);
    classes.add(Float.TYPE);
    classes.add(Double.TYPE);
    classes.add(Double.class);
    classes.add(Character.TYPE);
    classes.add(Character.TYPE);
    classes.add(Character.class);
    classes.add(Byte.TYPE);
    classes.add(Byte.class);
    classes.add(Enum.class);
    classes.add(BigInteger.class);
    classes.add(BigDecimal.class);
    Collection<PrimitiveTypeRegistrar> registrars = beanLocator.getInstances(PrimitiveTypeRegistrar.class);
    for (PrimitiveTypeRegistrar registrar : registrars) {
        PrimitiveType<?>[] types = registrar.getTypes();
        for (PrimitiveType<?> primitiveType : types) {
            classToType.put(primitiveType.getJavaType(), primitiveType);
            classes.add(primitiveType.getJavaType());
        }
    }
}