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:objenome.util.ClassUtils.java

/**
 * <p>Checks if one {@code Class} can be assigned to a variable of
 * another {@code Class}.</p>//from   w  w w. j a  v  a 2  s  . com
 *
 * <p>Unlike the {@link Class#isAssignableFrom(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, 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()) {
            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.sun.faces.config.ManagedBeanFactory.java

private Class getValueClassConsideringPrimitives(String valueClass) throws ClassNotFoundException {
    Class valueType = java.lang.String.class;
    if (null != valueClass && 0 < valueClass.length()) {
        if (valueClass.equals(Boolean.TYPE.getName())) {
            valueType = Boolean.TYPE;
        } else if (valueClass.equals(Byte.TYPE.getName())) {
            valueType = Byte.TYPE;
        } else if (valueClass.equals(Double.TYPE.getName())) {
            valueType = Double.TYPE;
        } else if (valueClass.equals(Float.TYPE.getName())) {
            valueType = Float.TYPE;
        } else if (valueClass.equals(Integer.TYPE.getName())) {
            valueType = Integer.TYPE;
        } else if (valueClass.equals(Character.TYPE.getName())) {
            valueType = Character.TYPE;
        } else if (valueClass.equals(Short.TYPE.getName())) {
            valueType = Short.TYPE;
        } else if (valueClass.equals(Long.TYPE.getName())) {
            valueType = Long.TYPE;
        } else {/*from w  w  w  .j av  a 2 s. co m*/
            valueType = Util.loadClass(valueClass, this);
        }
    }
    return valueType;
}

From source file:javadz.beanutils.ConvertUtilsBean.java

/**
 * Register array converters.// w ww . ja  v a  2s .  c  o m
 *
 * @param throwException <code>true</code> if the converters should
 * throw an exception when a conversion error occurs, otherwise <code>
 * <code>false</code> if a default value should be used.
 * @param defaultArraySize The size of the default array value for array converters
 * (N.B. This values is ignored if <code>throwException</code> is <code>true</code>).
 * Specifying a value less than zero causes a <code>null<code> value to be used for
 * the default.
 */
private void registerArrays(boolean throwException, int defaultArraySize) {

    // Primitives
    registerArrayConverter(Boolean.TYPE, new BooleanConverter(), throwException, defaultArraySize);
    registerArrayConverter(Byte.TYPE, new ByteConverter(), throwException, defaultArraySize);
    registerArrayConverter(Character.TYPE, new CharacterConverter(), throwException, defaultArraySize);
    registerArrayConverter(Double.TYPE, new DoubleConverter(), throwException, defaultArraySize);
    registerArrayConverter(Float.TYPE, new FloatConverter(), throwException, defaultArraySize);
    registerArrayConverter(Integer.TYPE, new IntegerConverter(), throwException, defaultArraySize);
    registerArrayConverter(Long.TYPE, new LongConverter(), throwException, defaultArraySize);
    registerArrayConverter(Short.TYPE, new ShortConverter(), throwException, defaultArraySize);

    // Standard
    registerArrayConverter(BigDecimal.class, new BigDecimalConverter(), throwException, defaultArraySize);
    registerArrayConverter(BigInteger.class, new BigIntegerConverter(), throwException, defaultArraySize);
    registerArrayConverter(Boolean.class, new BooleanConverter(), throwException, defaultArraySize);
    registerArrayConverter(Byte.class, new ByteConverter(), throwException, defaultArraySize);
    registerArrayConverter(Character.class, new CharacterConverter(), throwException, defaultArraySize);
    registerArrayConverter(Double.class, new DoubleConverter(), throwException, defaultArraySize);
    registerArrayConverter(Float.class, new FloatConverter(), throwException, defaultArraySize);
    registerArrayConverter(Integer.class, new IntegerConverter(), throwException, defaultArraySize);
    registerArrayConverter(Long.class, new LongConverter(), throwException, defaultArraySize);
    registerArrayConverter(Short.class, new ShortConverter(), throwException, defaultArraySize);
    registerArrayConverter(String.class, new StringConverter(), throwException, defaultArraySize);

    // Other
    registerArrayConverter(Class.class, new ClassConverter(), throwException, defaultArraySize);
    registerArrayConverter(java.util.Date.class, new DateConverter(), throwException, defaultArraySize);
    registerArrayConverter(Calendar.class, new DateConverter(), throwException, defaultArraySize);
    registerArrayConverter(File.class, new FileConverter(), throwException, defaultArraySize);
    registerArrayConverter(java.sql.Date.class, new SqlDateConverter(), throwException, defaultArraySize);
    registerArrayConverter(java.sql.Time.class, new SqlTimeConverter(), throwException, defaultArraySize);
    registerArrayConverter(Timestamp.class, new SqlTimestampConverter(), throwException, defaultArraySize);
    registerArrayConverter(URL.class, new URLConverter(), throwException, defaultArraySize);

}

From source file:com.sun.faces.config.ManagedBeanFactory.java

private Object getConvertedValueConsideringPrimitives(Object value, Class valueType) throws FacesException {
    if (null != value && null != valueType) {
        if (valueType == Boolean.TYPE || valueType == java.lang.Boolean.class) {
            value = Boolean.valueOf(value.toString().toLowerCase());
        } else if (valueType == Byte.TYPE || valueType == java.lang.Byte.class) {
            value = new Byte(value.toString());
        } else if (valueType == Double.TYPE || valueType == java.lang.Double.class) {
            value = new Double(value.toString());
        } else if (valueType == Float.TYPE || valueType == java.lang.Float.class) {
            value = new Float(value.toString());
        } else if (valueType == Integer.TYPE || valueType == java.lang.Integer.class) {
            value = new Integer(value.toString());
        } else if (valueType == Character.TYPE || valueType == java.lang.Character.class) {
            value = new Character(value.toString().charAt(0));
        } else if (valueType == Short.TYPE || valueType == java.lang.Short.class) {
            value = new Short(value.toString());
        } else if (valueType == Long.TYPE || valueType == java.lang.Long.class) {
            value = new Long(value.toString());
        } else if (valueType == String.class) {
        } else if (!valueType.isAssignableFrom(value.getClass())) {
            throw new FacesException(
                    Util.getExceptionMessageString(Util.MANAGED_BEAN_TYPE_CONVERSION_ERROR_ID, new Object[] {
                            value.toString(), value.getClass(), valueType, managedBean.getManagedBeanName() }));

        }/*from  w  w w.j  a  v  a 2s.  c  o  m*/
    }
    return value;
}

From source file:javadz.beanutils.LazyDynaBean.java

/**
 * Is an object of the source class assignable to the destination class?
 *
 * @param dest Destination class//from   www  .  jav  a  2  s .  com
 * @param source Source class
 * @return <code>true<code> if the source class is assignable to the
 * destination class, otherwise <code>false</code>
 */
protected boolean isAssignable(Class dest, Class source) {

    if (dest.isAssignableFrom(source) || ((dest == Boolean.TYPE) && (source == Boolean.class))
            || ((dest == Byte.TYPE) && (source == Byte.class))
            || ((dest == Character.TYPE) && (source == Character.class))
            || ((dest == Double.TYPE) && (source == Double.class))
            || ((dest == Float.TYPE) && (source == Float.class))
            || ((dest == Integer.TYPE) && (source == Integer.class))
            || ((dest == Long.TYPE) && (source == Long.class))
            || ((dest == Short.TYPE) && (source == Short.class))) {
        return (true);
    } else {
        return (false);
    }

}

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

/**
 * Resolve class object for java types.//from  w  w w . ja v  a  2 s  . c o m
 * 
 * @param iEntityName
 *          Java type name
 * @return Class object if found, otherwise null
 */
public static Class<?> getClassForJavaTypes(String iEntityName) {
    if (iEntityName.equals("String"))
        return String.class;
    else if (iEntityName.equals("Integer"))
        return Integer.class;
    else if (iEntityName.equals("int"))
        return Integer.TYPE;
    else if (iEntityName.equals("Long"))
        return Long.class;
    else if (iEntityName.equals("long"))
        return Long.TYPE;
    else if (iEntityName.equals("Short"))
        return Short.class;
    else if (iEntityName.equals("short"))
        return Short.TYPE;
    else if (iEntityName.equals("Boolean"))
        return Boolean.class;
    else if (iEntityName.equals("boolean"))
        return Boolean.TYPE;
    else if (iEntityName.equals("BigDecimal"))
        return BigDecimal.class;
    else if (iEntityName.equals("Float"))
        return Float.class;
    else if (iEntityName.equals("float"))
        return Float.TYPE;
    else if (iEntityName.equals("Double"))
        return Double.class;
    else if (iEntityName.equals("Number"))
        return Number.class;
    else if (iEntityName.equals("double"))
        return Double.TYPE;
    else if (iEntityName.equals("Character"))
        return Character.class;
    else if (iEntityName.equals("char"))
        return Character.TYPE;
    else if (iEntityName.equals("Byte"))
        return Byte.class;
    else if (iEntityName.equals("byte"))
        return Byte.TYPE;
    else if (iEntityName.equals("Object"))
        return Object.class;
    else if (iEntityName.equals("Collection"))
        return Collection.class;
    else if (iEntityName.equals("List"))
        return List.class;
    else if (iEntityName.equals("Set"))
        return Set.class;
    else if (iEntityName.equals("Map"))
        return Map.class;
    else if (iEntityName.equals("Date"))
        return Date.class;
    else if (iEntityName.equals("Map$Entry"))
        return Map.Entry.class;
    else if (iEntityName.equals("HashMap$Entry"))
        return Map.Entry.class;
    else if (iEntityName.equals("LinkedHashMap$Entry"))
        return Map.Entry.class;
    return null;
}

From source file:com.sun.faces.el.impl.Coercions.java

/**
 * Returns true if the given class is of an integer type
 *///  w  ww. j  a  v a 2  s.c o  m
public static boolean isIntegerType(Class pClass) {
    return pClass == Byte.class || pClass == Byte.TYPE || pClass == Short.class || pClass == Short.TYPE
            || pClass == Character.class || pClass == Character.TYPE || pClass == Integer.class
            || pClass == Integer.TYPE || pClass == Long.class || pClass == Long.TYPE;
}

From source file:org.apache.sling.models.impl.ModelAdapterFactory.java

private static boolean isAcceptableType(Class<?> type, Type genericType, Object value) {
    if (type.isInstance(value)) {
        if ((type == Collection.class || type == List.class) && genericType instanceof ParameterizedType
                && value instanceof Collection) {
            Iterator<?> it = ((Collection<?>) value).iterator();
            if (!it.hasNext()) {
                // empty collection, so it doesn't really matter
                return true;
            } else {
                // this is not an ideal way to get the actual component type, but erasure...
                Class<?> actualComponentType = it.next().getClass();
                Class<?> desiredComponentType = (Class<?>) ((ParameterizedType) genericType)
                        .getActualTypeArguments()[0];
                return desiredComponentType.isAssignableFrom(actualComponentType);
            }//from w  w w .j a v  a2 s .co m
        } else {
            return true;
        }
    }

    if (type == Integer.TYPE) {
        return Integer.class.isInstance(value);
    }
    if (type == Long.TYPE) {
        return Long.class.isInstance(value);
    }
    if (type == Boolean.TYPE) {
        return Boolean.class.isInstance(value);
    }
    if (type == Double.TYPE) {
        return Double.class.isInstance(value);
    }
    if (type == Float.TYPE) {
        return Float.class.isInstance(value);
    }
    if (type == Short.TYPE) {
        return Short.class.isInstance(value);
    }
    if (type == Byte.TYPE) {
        return Byte.class.isInstance(value);
    }
    if (type == Character.TYPE) {
        return Character.class.isInstance(value);
    }

    return false;
}

From source file:cn.sinobest.jzpt.framework.utils.string.StringUtils.java

/**
 *  obj isArrayJoin//from w  w  w . j a va2 s  .co  m
 *
 * @Title: join
 * @return String 
 * @throws
 */
public static String join(Object obj, String dchar) {
    Assert.notNull(obj);
    if (!obj.getClass().isArray()) {
        throw new IllegalArgumentException("The input object to join must be a Array and not null.");
    }
    Class<?> priType = obj.getClass().getComponentType();
    if (priType == Boolean.TYPE) {
        return join((boolean[]) obj, dchar);
    } else if (priType == Byte.TYPE) {
        return join((byte[]) obj, dchar);
    } else if (priType == Character.TYPE) {
        return join((char[]) obj, dchar);
    } else if (priType == Integer.TYPE) {
        return join((int[]) obj, dchar);
    } else if (priType == Long.TYPE) {
        return join((long[]) obj, dchar);
    } else if (priType == Float.TYPE) {
        return join((float[]) obj, dchar);
    } else if (priType == Double.TYPE) {
        return join((double[]) obj, dchar);
    } else if (priType == Short.TYPE) {
        return join((short[]) obj, dchar);
    } else {
        return join((Object[]) obj, dchar);
    }
}

From source file:org.apache.maven.plugin.javadoc.AbstractFixJavadocMojo.java

/**
 * Add a default Javadoc for the given field, i.e.:
 * <br/>/*w  w w .  ja  v a 2s  .c  o m*/
 * <code>
 * <font color="#808080">1</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font>
 * <font color="#3f5fbf">&#47;&#42;&#42;&nbsp;Constant&nbsp;</font><font color="#7f7f9f">&lt;code&gt;</font>
 * <font color="#3f5fbf">MY_STRING_CONSTANT=&#34;value&#34;</font>
 * <font color="#7f7f9f">&lt;/code&gt;&nbsp;</font><font color="#3f5fbf">&#42;&#47;</font><br />
 * <font color="#808080">2</font>&nbsp;<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font>
 * <font color="#7f0055"><b>public&nbsp;static&nbsp;final&nbsp;</b></font>
 * <font color="#000000">String&nbsp;MY_STRING_CONSTANT&nbsp;=&nbsp;</font>
 * <font color="#2a00ff">&#34;value&#34;</font><font color="#000000">;</font>
 * </code>
 *
 * @param stringWriter not null
 * @param field        not null
 * @param indent       not null
 * @throws IOException if any
 */
private void addDefaultFieldComment(final StringWriter stringWriter, final JavaField field, final String indent)
        throws IOException {
    StringBuilder sb = new StringBuilder();

    sb.append(indent).append(START_JAVADOC).append(" ");
    sb.append("Constant <code>").append(field.getName());

    if (StringUtils.isNotEmpty(field.getInitializationExpression())) {
        String qualifiedName = field.getType().getJavaClass().getFullyQualifiedName();

        if (qualifiedName.equals(Byte.TYPE.toString()) || qualifiedName.equals(Short.TYPE.toString())
                || qualifiedName.equals(Integer.TYPE.toString()) || qualifiedName.equals(Long.TYPE.toString())
                || qualifiedName.equals(Float.TYPE.toString()) || qualifiedName.equals(Double.TYPE.toString())
                || qualifiedName.equals(Boolean.TYPE.toString())
                || qualifiedName.equals(Character.TYPE.toString())) {
            sb.append("=");
            sb.append(field.getInitializationExpression().trim());
        }

        if (qualifiedName.equals(String.class.getName())) {
            StringBuilder value = new StringBuilder();
            String[] lines = getLines(field.getInitializationExpression());
            for (String line : lines) {
                StringTokenizer token = new StringTokenizer(line.trim(), "\"\n\r");
                while (token.hasMoreTokens()) {
                    String s = token.nextToken();

                    if (s.trim().equals("+")) {
                        continue;
                    }
                    if (s.trim().endsWith("\\")) {
                        s += "\"";
                    }
                    value.append(s);
                }
            }

            sb.append("=\"");
            // reduce the size
            if (value.length() < 40) {
                sb.append(value.toString()).append("\"");
            } else {
                sb.append(value.toString().substring(0, 39)).append("\"{trunked}");
            }
        }
    }

    sb.append("</code> ").append(END_JAVADOC);
    sb.append(EOL);

    stringWriter.write(sb.toString());
}