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.soybeanMilk.SbmUtils.java

/**
 * ?<code>type</code>?/*  ww w . j  a va 2s. c  o m*/
 * @param type
 * @return
 * @date 2010-12-31
 */
public static Type wrapType(Type type) {
    if (!isClassType(type))
        return type;
    else if (!narrowToClass(type).isPrimitive())
        return type;
    else if (Byte.TYPE.equals(type))
        return Byte.class;
    else if (Short.TYPE.equals(type))
        return Short.class;
    else if (Integer.TYPE.equals(type))
        return Integer.class;
    else if (Long.TYPE.equals(type))
        return Long.class;
    else if (Float.TYPE.equals(type))
        return Float.class;
    else if (Double.TYPE.equals(type))
        return Double.class;
    else if (Boolean.TYPE.equals(type))
        return Boolean.class;
    else if (Character.TYPE.equals(type))
        return Character.class;
    else
        return type;
}

From source file:Main.java

/**
 * <p>Copies the given array and adds the given element at the end of the new array.</p>
 *
 * <p>The new array contains the same elements of the input
 * array plus the given element in the last position. The component type of
 * the new array is the same as that of the input array.</p>
 *
 * <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>/*w ww. j  a  va2s .  c om*/
 * ArrayUtils.add(null, '0')       = ['0']
 * ArrayUtils.add(['1'], '0')      = ['1', '0']
 * ArrayUtils.add(['1', '0'], '1') = ['1', '0', '1']
 * </pre>
 *
 * @param array  the array to copy and add the element to, may be {@code null}
 * @param element  the object to add at the last index of the new array
 * @return A new array containing the existing elements plus the new element
 * @since 2.1
 */
public static char[] add(final char[] array, final char element) {
    final char[] newArray = (char[]) copyArrayGrow1(array, Character.TYPE);
    newArray[newArray.length - 1] = element;
    return newArray;
}

From source file:org.unitils.core.util.ObjectFormatter.java

protected boolean formatCharacter(Object object, Class<?> type, StringBuilder result) {
    if (object instanceof Character || Character.TYPE.equals(type)) {
        result.append('\'');
        result.append(String.valueOf(object));
        result.append('\'');
        return true;
    }//  w  w  w.  j  av a  2 s . c  o  m
    return false;
}

From source file:org.cloudata.core.common.io.CObjectWritable.java

/** Write a {@link CWritable}, {@link String}, primitive type, or an array of
 * the preceding. *///from ww w  .j a  v a2  s . com
public static void writeObject(DataOutput out, Object instance, Class declaredClass, CloudataConf conf,
        boolean arrayComponent) throws IOException {

    if (instance == null) { // null
        instance = new NullInstance(declaredClass, conf);
        declaredClass = CWritable.class;
        arrayComponent = false;
    }

    if (!arrayComponent) {
        CUTF8.writeString(out, declaredClass.getName()); // always write declared
        //System.out.println("Write:declaredClass.getName():" + declaredClass.getName());
    }

    if (declaredClass.isArray()) { // array
        int length = Array.getLength(instance);
        out.writeInt(length);
        //System.out.println("Write:length:" + length);

        if (declaredClass.getComponentType() == Byte.TYPE) {
            out.write((byte[]) instance);
        } else if (declaredClass.getComponentType() == ColumnValue.class) {
            //ColumnValue?  Deserialize? ?? ?   ?? ?  .
            writeColumnValue(out, instance, declaredClass, conf, length);
        } else {
            for (int i = 0; i < length; i++) {
                writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf,
                        !declaredClass.getComponentType().isArray());
            }
        }
    } else if (declaredClass == String.class) { // String
        CUTF8.writeString(out, (String) instance);

    } else if (declaredClass.isPrimitive()) { // primitive type

        if (declaredClass == Boolean.TYPE) { // boolean
            out.writeBoolean(((Boolean) instance).booleanValue());
        } else if (declaredClass == Character.TYPE) { // char
            out.writeChar(((Character) instance).charValue());
        } else if (declaredClass == Byte.TYPE) { // byte
            out.writeByte(((Byte) instance).byteValue());
        } else if (declaredClass == Short.TYPE) { // short
            out.writeShort(((Short) instance).shortValue());
        } else if (declaredClass == Integer.TYPE) { // int
            out.writeInt(((Integer) instance).intValue());
        } else if (declaredClass == Long.TYPE) { // long
            out.writeLong(((Long) instance).longValue());
        } else if (declaredClass == Float.TYPE) { // float
            out.writeFloat(((Float) instance).floatValue());
        } else if (declaredClass == Double.TYPE) { // double
            out.writeDouble(((Double) instance).doubleValue());
        } else if (declaredClass == Void.TYPE) { // void
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }
    } else if (declaredClass.isEnum()) { // enum
        CUTF8.writeString(out, ((Enum) instance).name());
    } else if (CWritable.class.isAssignableFrom(declaredClass)) { // Writable
        if (instance.getClass() == declaredClass) {
            out.writeShort(TYPE_SAME); // ? ?? ? ?? 
            //System.out.println("Write:TYPE_SAME:" + TYPE_SAME);

        } else {
            out.writeShort(TYPE_DIFF);
            //System.out.println("Write:TYPE_DIFF:" + TYPE_DIFF);
            CUTF8.writeString(out, instance.getClass().getName());
            //System.out.println("Write:instance.getClass().getName():" + instance.getClass().getName());
        }
        ((CWritable) instance).write(out);
        //System.out.println("Write:instance value");

    } else {
        throw new IOException("Can't write: " + instance + " as " + declaredClass);
    }
}

From source file:org.evosuite.regression.ObjectFields.java

private static Object getFieldValue(Field field, Object p) {
    try {//from w w  w.j a v a  2 s .  co m
        /*Class objClass = p.getClass();
        if(p instanceof java.lang.String){
           ((String) p).hashCode();
        }*/
        Class<?> fieldType = field.getType();
        field.setAccessible(true);
        if (fieldType.isPrimitive()) {
            if (fieldType.equals(Boolean.TYPE)) {
                return field.getBoolean(p);
            }
            if (fieldType.equals(Integer.TYPE)) {
                return field.getInt(p);
            }
            if (fieldType.equals(Byte.TYPE)) {
                return field.getByte(p);
            }
            if (fieldType.equals(Short.TYPE)) {
                return field.getShort(p);
            }
            if (fieldType.equals(Long.TYPE)) {
                return field.getLong(p);
            }
            if (fieldType.equals(Double.TYPE)) {
                return field.getDouble(p);
            }
            if (fieldType.equals(Float.TYPE)) {
                return field.getFloat(p);
            }
            if (fieldType.equals(Character.TYPE)) {
                return field.getChar(p);
            }
            throw new UnsupportedOperationException("Primitive type " + fieldType + " not implemented!");
        }
        return field.get(p);
    } catch (IllegalAccessException exc) {
        throw new RuntimeException(exc);
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        if (MAX_RECURSION != 0)
            MAX_RECURSION = 0;
        else
            throw new RuntimeErrorException(e);
        return getFieldValue(field, p);
    }
}

From source file:com.link_intersystems.lang.Conversions.java

/**
 * <em>java language specification - 5.1.3 Narrowing Primitive Conversions</em>
 * ./*w  ww .  ja  v a  2  s.  com*/
 *
 * <code>
 * <blockquote>The following 22 specific conversions on primitive types
 *  are called the narrowing primitive conversions:
 * <ul>
 * <li>short to byte or char</li>
 * <li>char to byte or short</li>
 * <li>int to byte, short, or char</li>
 * <li>long to byte, short, char, or int</li>
 * <li>float to byte, short, char, int, or long</li>
 * <li>double to byte, short, char, int, long, or float </li>
 * </blockquote>
 * </code>
 *
 * @param from
 *            the base type
 * @param to
 *            the widening type
 * @return true if from to to is a primitive widening.
 * @since 1.0.0.0
 */
public static boolean isPrimitiveNarrowing(Class<?> from, Class<?> to) {
    Assert.isTrue(Primitives.isPrimitive(from), "mustBeAPrimitive", "form");
    Assert.isTrue(Primitives.isPrimitive(to), "mustBeAPrimitive", "to");
    boolean isPrimitiveNarrowing = false;

    if (isIdentity(from, Double.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveDoubleNarrowing(to);
    } else if (isIdentity(from, Short.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveShortNarrowing(to);
    } else if (isIdentity(from, Character.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveCharacterNarrowing(to);
    } else if (isIdentity(from, Integer.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveIntegerNarrowing(to);
    } else if (isIdentity(from, Long.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveLongNarrowing(to);
    } else if (isIdentity(from, Float.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveFloatNarrowing(to);
    }
    /*
     * must be a byte
     */
    return isPrimitiveNarrowing;
}

From source file:candr.yoclip.option.OptionSetter.java

@Override
public void setOption(final T bean, final String value) {

    final Class<?> setterParameterType = getType();
    try {//from w  ww  . j  a v  a2 s.co  m

        if (Boolean.TYPE.equals(setterParameterType) || Boolean.class.isAssignableFrom(setterParameterType)) {
            setBooleanOption(bean, value);

        } else if (Byte.TYPE.equals(setterParameterType) || Byte.class.isAssignableFrom(setterParameterType)) {
            setByteOption(bean, value);

        } else if (Short.TYPE.equals(setterParameterType)
                || Short.class.isAssignableFrom(setterParameterType)) {
            setShortOption(bean, value);

        } else if (Integer.TYPE.equals(setterParameterType)
                || Integer.class.isAssignableFrom(setterParameterType)) {
            setIntegerOption(bean, value);

        } else if (Long.TYPE.equals(setterParameterType) || Long.class.isAssignableFrom(setterParameterType)) {
            setLongOption(bean, value);

        } else if (Character.TYPE.equals(setterParameterType)
                || Character.class.isAssignableFrom(setterParameterType)) {
            setCharacterOption(bean, value);

        } else if (Float.TYPE.equals(setterParameterType)
                || Float.class.isAssignableFrom(setterParameterType)) {
            setFloatOption(bean, value);

        } else if (Double.TYPE.equals(setterParameterType)
                || Double.class.isAssignableFrom(setterParameterType)) {
            setDoubleOption(bean, value);

        } else if (String.class.isAssignableFrom(setterParameterType)) {
            setStringOption(bean, value);

        } else {
            final String supportedTypes = "boolean, byte, short, int, long, char, float, double, and String";
            throw new OptionsParseException(
                    String.format("OptionParameter only supports %s types", supportedTypes));
        }

    } catch (NumberFormatException e) {
        final String error = String.format("Error converting '%s' to %s", value, setterParameterType);
        throw new OptionsParseException(error, e);
    }
}

From source file:candr.yoclip.option.OptionField.java

@Override
public void setOption(final T bean, final String value) {

    final Class<?> fieldType = getField().getType();
    try {/*  w w w. j av  a  2 s.co  m*/

        if (Boolean.TYPE.equals(fieldType) || Boolean.class.isAssignableFrom(fieldType)) {
            setBooleanOption(bean, value);

        } else if (Byte.TYPE.equals(fieldType) || Byte.class.isAssignableFrom(fieldType)) {
            setByteOption(bean, value);

        } else if (Short.TYPE.equals(fieldType) || Short.class.isAssignableFrom(fieldType)) {
            setShortOption(bean, value);

        } else if (Integer.TYPE.equals(fieldType) || Integer.class.isAssignableFrom(fieldType)) {
            setIntegerOption(bean, value);

        } else if (Long.TYPE.equals(fieldType) || Long.class.isAssignableFrom(fieldType)) {
            setLongOption(bean, value);

        } else if (Character.TYPE.equals(fieldType) || Character.class.isAssignableFrom(fieldType)) {
            setCharacterOption(bean, value);

        } else if (Float.TYPE.equals(fieldType) || Float.class.isAssignableFrom(fieldType)) {
            setFloatOption(bean, value);

        } else if (Double.TYPE.equals(fieldType) || Double.class.isAssignableFrom(fieldType)) {
            setDoubleOption(bean, value);

        } else if (String.class.isAssignableFrom(fieldType)) {
            setStringOption(bean, value);

        } else {
            final String supportedTypes = "boolean, byte, short, int, long, char, float, double, and String";
            throw new OptionsParseException(
                    String.format("OldOptionsParser only support %s types", supportedTypes));
        }

    } catch (NumberFormatException e) {
        final String error = String.format("Error converting '%s' to %s", value, fieldType);
        throw new OptionsParseException(error, e);
    }
}

From source file:com.cyclopsgroup.waterview.utils.TypeUtils.java

private static Map getNonePrimitiveTypeMap() {
    if (nonePrimitiveTypeMap == null) {
        nonePrimitiveTypeMap = new Hashtable();
        nonePrimitiveTypeMap.put(Boolean.TYPE, Boolean.class);
        nonePrimitiveTypeMap.put(Byte.TYPE, Byte.class);
        nonePrimitiveTypeMap.put(Character.TYPE, Character.class);
        nonePrimitiveTypeMap.put(Short.TYPE, Short.class);
        nonePrimitiveTypeMap.put(Integer.TYPE, Integer.class);
        nonePrimitiveTypeMap.put(Long.TYPE, Long.class);
        nonePrimitiveTypeMap.put(Float.TYPE, Float.class);
        nonePrimitiveTypeMap.put(Double.TYPE, Double.class);
    }//from  w w w  .j a v a  2s  . c  o m

    return nonePrimitiveTypeMap;
}

From source file:org.kuali.kfs.sys.context.DocumentSerializabilityTest.java

/**
 * Determines if the given class represents one of the eight Java primitives
 * @param clazz the class to check/*from   w ww  .  j  a  va 2s. c o m*/
 * @return true if the class represents a byte, short, int, long, char, double, float, or boolean; false otherwise
 */
protected boolean isPrimitive(Class<?> clazz) {
    return Byte.TYPE.isAssignableFrom(clazz) || Short.TYPE.isAssignableFrom(clazz)
            || Integer.TYPE.isAssignableFrom(clazz) || Long.TYPE.isAssignableFrom(clazz)
            || Float.TYPE.isAssignableFrom(clazz) || Double.TYPE.isAssignableFrom(clazz)
            || Character.TYPE.isAssignableFrom(clazz) || Boolean.TYPE.isAssignableFrom(clazz);
}