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.brekka.stillingar.spring.bpp.ConfigurationBeanPostProcessorTest.java

@Test
public void primitiveDefaultCharacter() {
    assertEquals(ConfigurationBeanPostProcessor.primitiveDefault(Character.TYPE), Character.valueOf((char) 0));
}

From source file:org.yestech.jmlnitrate.transformation.inbound.BaseInboundTransformation.java

/**
 *  Returns the Class Type for a Primitive type.
 *
 * @param  classType Description of the Parameter
 * @return  the Class Type/*from w  w w  .j  a  v a 2s.  c  o m*/
 * @exception  Exception Description of the Exception
 */
private Class getClass(String classType) throws Exception {
    TransformationParameter classParameter = TransformationParameter.getByName(classType);
    Class type = null;
    if (classParameter != null) {
        if (classParameter.equals(TransformationParameter.INT)) {
            //int
            type = Integer.TYPE;
        } else if (classParameter.equals(TransformationParameter.LONG)) {
            //long
            type = Long.TYPE;
        } else if (classParameter.equals(TransformationParameter.FLOAT)) {
            //float
            type = Float.TYPE;
        } else if (classParameter.equals(TransformationParameter.DOUBLE)) {
            //double
            type = Double.TYPE;
        } else if (classParameter.equals(TransformationParameter.BOOLEAN)) {
            //boolean
            type = Boolean.TYPE;
        } else if (classParameter.equals(TransformationParameter.CHAR)) {
            //char
            type = Character.TYPE;
        } else if (classParameter.equals(TransformationParameter.BYTE)) {
            //byte
            type = Byte.TYPE;
        } else {
            logger.error("Not a valid Class Type...");
            throw new IllegalArgumentException("Not a valid Class Type...");
        }
    } else {
        type = Clazz.getClass(classType);
    }
    return type;
}

From source file:com.github.gekoh.yagen.util.FieldInfo.java

private static List<FieldInfo> convertFields(List<FieldInfo> fields, Class baseEntity) {

    for (Field field : baseEntity.getDeclaredFields()) {
        FieldInfo fi;/* ww  w  .ja va  2  s .co m*/
        Class type = field.getType();
        String name = field.getName();
        Column column = field.getAnnotation(Column.class);
        if (field.isAnnotationPresent(Embedded.class)) {
            if (field.isAnnotationPresent(AttributeOverride.class)) {
                fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverride.class));
            } else {
                fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverrides.class));
            }
        } else if (field.isAnnotationPresent(Enumerated.class)) {
            fi = new FieldInfo(type, name, true, column);
        } else if (column != null && !field.isAnnotationPresent(CollectionTable.class)) {
            if (type.isPrimitive()) {
                if (type.equals(Boolean.TYPE)) {
                    type = Boolean.class;
                } else if (type.equals(Long.TYPE)) {
                    type = Long.class;
                } else if (type.equals(Integer.TYPE)) {
                    type = Integer.class;
                } else if (type.equals(Short.TYPE)) {
                    type = Short.class;
                } else if (type.equals(Byte.TYPE)) {
                    type = Byte.class;
                } else if (type.equals(Double.TYPE)) {
                    type = Double.class;
                } else if (type.equals(Float.TYPE)) {
                    type = Float.class;
                } else if (type.equals(Character.TYPE)) {
                    type = Character.class;
                }
            }
            fi = new FieldInfo(type, name, false, column);
        } else if ((field.isAnnotationPresent(ManyToOne.class) && !field.isAnnotationPresent(JoinTable.class))
                || (field.isAnnotationPresent(OneToOne.class)
                        && StringUtils.isEmpty(field.getAnnotation(OneToOne.class).mappedBy()))) {
            String columnName = field.isAnnotationPresent(JoinColumn.class)
                    ? field.getAnnotation(JoinColumn.class).name()
                    : field.getName();
            fi = getIdFieldInfo(type, name, columnName);
        } else if (!field.isAnnotationPresent(Transient.class)
                && (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type))
                && (field.isAnnotationPresent(JoinColumn.class) || field.isAnnotationPresent(JoinTable.class)
                        || field.isAnnotationPresent(CollectionTable.class))) {
            fi = new FieldInfo(type, name);
        } else {
            continue;
        }
        if (field.isAnnotationPresent(Type.class)) {
            fi.addAnnotation(field.getAnnotation(Type.class));
        }
        fi.setField(field);
        fields.add(fi);
    }

    return fields;
}

From source file:org.eclipse.internal.xtend.type.baseimpl.types.StringTypeImpl.java

@Override
public Object convert(final Object src, final Class targetType) {
    final String s = toString(src);
    if (targetType.isAssignableFrom(String.class))
        return s;
    else if (targetType.isAssignableFrom(Character.class) || targetType.isAssignableFrom(Character.TYPE)) {
        if (s.length() == 1)
            return new Character(s.charAt(0));
    } else if (targetType.isAssignableFrom(StringBuffer.class))
        return new StringBuffer(s);
    return super.convert(src, targetType);
}

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowserUnmarshaller.java

/**
 * Gracefully convert given Object to given class given the precondition
 * that both are primitives or one of the classes associated with
 * primitives. eg. If val is of type Double and cls is of type int, return
 * Integer type with appropriate value truncation so that it can be assigned
 * to field with field.set().//from  w  w w . j a v  a  2s  .  c  o m
 *
 * @param cls
 * @param val
 * @return
 * @throws com.initialxy.cordova.themeablebrowser.ThemeableBrowserUnmarshaller.TypeMismatchException
 */
private static Object convertToPrimitiveFieldObj(Object val, Class<?> cls) {
    Class<?> valClass = val.getClass();
    Object result = null;

    try {
        Method getter = null;
        if (cls.isAssignableFrom(Byte.class) || cls.isAssignableFrom(Byte.TYPE)) {
            getter = valClass.getMethod("byteValue");
        } else if (cls.isAssignableFrom(Short.class) || cls.isAssignableFrom(Short.TYPE)) {
            getter = valClass.getMethod("shortValue");
        } else if (cls.isAssignableFrom(Integer.class) || cls.isAssignableFrom(Integer.TYPE)) {
            getter = valClass.getMethod("intValue");
        } else if (cls.isAssignableFrom(Long.class) || cls.isAssignableFrom(Long.TYPE)) {
            getter = valClass.getMethod("longValue");
        } else if (cls.isAssignableFrom(Float.class) || cls.isAssignableFrom(Float.TYPE)) {
            getter = valClass.getMethod("floatValue");
        } else if (cls.isAssignableFrom(Double.class) || cls.isAssignableFrom(Double.TYPE)) {
            getter = valClass.getMethod("doubleValue");
        } else if (cls.isAssignableFrom(Boolean.class) || cls.isAssignableFrom(Boolean.TYPE)) {
            if (val instanceof Boolean) {
                result = val;
            } else {
                throw new TypeMismatchException(cls, val.getClass());
            }
        } else if (cls.isAssignableFrom(Character.class) || cls.isAssignableFrom(Character.TYPE)) {
            if (val instanceof String && ((String) val).length() == 1) {
                char c = ((String) val).charAt(0);
                result = Character.valueOf(c);
            } else if (val instanceof String) {
                throw new TypeMismatchException(
                        "Expected Character, " + "but received String with length other than 1.");
            } else {
                throw new TypeMismatchException(
                        String.format("Expected Character, accept String, but got %s.", val.getClass()));
            }
        }

        if (getter != null) {
            result = getter.invoke(val);
        }
    } catch (NoSuchMethodException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    } catch (SecurityException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    } catch (IllegalAccessException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    } catch (InvocationTargetException e) {
        throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls));
    }

    return result;
}

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

/** Gets default value.
 * @return default value.// w  w w.  ja  v a2s .c om
 */
public Object getDefaultValue() {
    if (defaultValue != null)
        return this.defaultValue;
    Class cls = getType();
    if (primitiveWrapperClass != null) {
        if (cls.equals(Boolean.TYPE))
            return new Boolean(false);
        else if (cls.equals(Byte.TYPE))
            return new Byte((byte) 0);
        else if (cls.equals(Character.TYPE))
            return new Character((char) 0);
        else if (cls.equals(Double.TYPE))
            return new Double((double) 0);
        else if (cls.equals(Float.TYPE))
            return new Float((float) 0);
        else if (cls.equals(Integer.TYPE))
            return new Integer((int) 0);
        else if (cls.equals(Long.TYPE))
            return new Long((long) 0);
        else if (cls.equals(Short.TYPE))
            return new Short((short) 0);
        else
            return null;
    } else
        return null;
}

From source file:org.liveSense.api.beanprocessors.DbStandardBeanProcessor.java

/**
 * ResultSet.getObject() returns an Integer object for an INT column.  The
 * setter method for the property might take an Integer or a primitive int.
 * This method returns true if the value can be successfully passed into
 * the setter method.  Remember, Method.invoke() handles the unwrapping
 * of Integer into an int.//from  ww  w . j a  va2 s .c  o  m
 * 
 * @param value The value to be passed into the setter method.
 * @param type The setter's parameter type.
 * @return boolean True if the value is compatible.
 */
private 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 {
        return false;
    }

}

From source file:com.flexive.faces.renderer.FxSelectRenderer.java

/**
 * Convert select many values to given array class
 *
 * @param context      faces context//w ww  .  ja  v  a 2  s  . co  m
 * @param uiSelectMany select many component
 * @param arrayClass   the array class
 * @param newValues    new values to convert
 * @return converted values
 * @throws ConverterException on errors
 */
protected Object convertSelectManyValues(FacesContext context, UISelectMany uiSelectMany, Class arrayClass,
        String[] newValues) throws ConverterException {

    Object result;
    Converter converter;
    int len = (null != newValues ? newValues.length : 0);

    Class elementType = arrayClass.getComponentType();

    // Optimization: If the elementType is String, we don't need
    // conversion.  Just return newValues.
    if (elementType.equals(String.class))
        return newValues;

    try {
        result = Array.newInstance(elementType, len);
    } catch (Exception e) {
        throw new ConverterException(e);
    }

    // bail out now if we have no new values, returning our
    // oh-so-useful zero-length array.
    if (null == newValues)
        return result;

    // obtain a converter.

    // attached converter takes priority
    if (null == (converter = uiSelectMany.getConverter())) {
        // Otherwise, look for a by-type converter
        if (null == (converter = FxJsfComponentUtils.getConverterForClass(elementType, context))) {
            // if that fails, and the attached values are of Object type,
            // we don't need conversion.
            if (elementType.equals(Object.class))
                return newValues;
            StringBuffer valueStr = new StringBuffer();
            for (int i = 0; i < len; i++) {
                if (i == 0)
                    valueStr.append(newValues[i]);
                else
                    valueStr.append(' ').append(newValues[i]);
            }
            throw new ConverterException("Could not get a converter for " + String.valueOf(valueStr));
        }
    }

    if (elementType.isPrimitive()) {
        for (int i = 0; i < len; i++) {
            if (elementType.equals(Boolean.TYPE)) {
                Array.setBoolean(result, i,
                        ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Byte.TYPE)) {
                Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Double.TYPE)) {
                Array.setDouble(result, i,
                        ((Double) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Float.TYPE)) {
                Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Integer.TYPE)) {
                Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Character.TYPE)) {
                Array.setChar(result, i,
                        ((Character) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Short.TYPE)) {
                Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i])));
            } else if (elementType.equals(Long.TYPE)) {
                Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i])));
            }
        }
    } else {
        for (int i = 0; i < len; i++)
            Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i]));
    }
    return result;
}

From source file:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java

private final Class<?> getClassFromType(final org.objectweb.asm.Type type) {

    if (type.equals(org.objectweb.asm.Type.BOOLEAN_TYPE)) {
        return Boolean.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.BYTE_TYPE)) {
        return Byte.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.CHAR_TYPE)) {
        return Character.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.DOUBLE_TYPE)) {
        return Double.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.FLOAT_TYPE)) {
        return Float.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.INT_TYPE)) {
        return Integer.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.LONG_TYPE)) {
        return Long.TYPE;
    } else if (type.equals(org.objectweb.asm.Type.SHORT_TYPE)) {
        return Short.TYPE;
    } else if (type.getSort() == org.objectweb.asm.Type.ARRAY) {
        final org.objectweb.asm.Type elementType = type.getElementType();
        int[] dimensions = new int[type.getDimensions()];

        if (elementType.equals(org.objectweb.asm.Type.BOOLEAN_TYPE)) {
            return Array.newInstance(boolean.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.BYTE_TYPE)) {
            return Array.newInstance(byte.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.CHAR_TYPE)) {
            return Array.newInstance(char.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.DOUBLE_TYPE)) {
            return Array.newInstance(double.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.FLOAT_TYPE)) {
            return Array.newInstance(float.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.INT_TYPE)) {
            return Array.newInstance(int.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.LONG_TYPE)) {
            return Array.newInstance(long.class, dimensions).getClass();
        } else if (elementType.equals(org.objectweb.asm.Type.SHORT_TYPE)) {
            return Array.newInstance(short.class, dimensions).getClass();
        }/*ww w .  j a va 2  s.co  m*/
    }

    //      try 
    //      {
    return getClassForName(type.getClassName());
    //         return Class.forName(type.getClassName(), true, StaticTestCluster.classLoader);
    //      } 
    //      catch (final ClassNotFoundException e) 
    //      {
    //         throw new RuntimeException(e);
    //      }
}

From source file:Main.java

/**
 * <p>Inserts the specified element at the specified position in the array.
 * Shifts the element currently at that position (if any) and any subsequent
 * elements to the right (adds one to their indices).</p>
 *
 * <p>This method returns a new array with the same elements of the input
 * array plus the given element on the specified position. The component
 * type of the returned array is always the same as that of the input
 * array.</p>/* w  w  w .  j a  v  a  2s .co  m*/
 *
 * <p>If the input array is {@code null}, a new one element array is returned
 *  whose component type is the same as the element.</p>
 *
 * <pre>
 * ArrayUtils.add(null, 0, 'a')            = ['a']
 * ArrayUtils.add(['a'], 0, 'b')           = ['b', 'a']
 * ArrayUtils.add(['a', 'b'], 0, 'c')      = ['c', 'a', 'b']
 * ArrayUtils.add(['a', 'b'], 1, 'k')      = ['a', 'k', 'b']
 * ArrayUtils.add(['a', 'b', 'c'], 1, 't') = ['a', 't', 'b', 'c']
 * </pre>
 *
 * @param array  the array to add the element to, may be {@code null}
 * @param index  the position of the new object
 * @param element  the object to add
 * @return A new array containing the existing elements and the new element
 * @throws IndexOutOfBoundsException if the index is out of range
 * (index < 0 || index > array.length).
 */
public static char[] add(char[] array, int index, char element) {
    return (char[]) add(array, index, Character.valueOf(element), Character.TYPE);
}