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.romaframework.core.schema.SchemaHelper.java

public static Object assignValueToLiteral(String v, Class<?> type) {
    Object value;/*from  w ww  .j av a  2  s.  c  o m*/
    if (v.length() == 0) {
        value = null;
    } else {
        if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
            value = Integer.parseInt(v);
        } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
            value = Long.parseLong(v);
        } else if (type.equals(Short.class) || type.equals(Short.TYPE)) {
            value = Short.parseShort(v);
        } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
            value = Boolean.parseBoolean(v);
        } else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
            value = Float.parseFloat(v);
        } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
            value = Double.parseDouble(v);
        } else if (type.equals(Byte.class) || type.equals(Byte.TYPE)) {
            value = Byte.parseByte(v);
        } else if (type.equals(Character.class) || type.equals(Character.TYPE)) {
            value = v.charAt(0);
        } else {
            value = v;
        }
    }
    return value;
}

From source file:de.ma.it.common.sm.transition.MethodTransition.java

private boolean match(Class<?> paramType, Object arg, Class<?> argType) {
    if (paramType.isPrimitive()) {
        if (paramType.equals(Boolean.TYPE)) {
            return arg instanceof Boolean;
        }/*w w w.ja  v a  2  s.  com*/
        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:javadz.beanutils.ConvertUtilsBean.java

/**
 * Sets the default value for Character conversions.
 * @param newDefaultCharacter The default Character value
 * @deprecated Register replacement converters for Character.TYPE and
 *  Character.class instead//from w  ww .  j ava2s.  co  m
 */
public void setDefaultCharacter(char newDefaultCharacter) {
    defaultCharacter = new Character(newDefaultCharacter);
    register(new CharacterConverter(defaultCharacter), Character.TYPE);
    register(new CharacterConverter(defaultCharacter), Character.class);
}

From source file:net.sf.json.JSONDynaBean.java

/**
 * DOCUMENT ME!/*from w w  w. j a  va2  s .c  o m*/
 *
 * @param dest DOCUMENT ME!
 * @param src DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
protected boolean isDynaAssignable(Class dest, Class src) {
    boolean assignable = dest.isAssignableFrom(src);
    assignable = ((dest == Boolean.TYPE) && (src == Boolean.class)) ? true : assignable;
    assignable = ((dest == Byte.TYPE) && (src == Byte.class)) ? true : assignable;
    assignable = ((dest == Character.TYPE) && (src == Character.class)) ? true : assignable;
    assignable = ((dest == Short.TYPE) && (src == Short.class)) ? true : assignable;
    assignable = ((dest == Integer.TYPE) && (src == Integer.class)) ? true : assignable;
    assignable = ((dest == Long.TYPE) && (src == Long.class)) ? true : assignable;
    assignable = ((dest == Float.TYPE) && (src == Float.class)) ? true : assignable;
    assignable = ((dest == Double.TYPE) && (src == Double.class)) ? true : assignable;

    if ((src == Double.TYPE) || Double.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true
                : assignable;
    }

    if ((src == Float.TYPE) || Float.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable;
    }

    if ((src == Long.TYPE) || Long.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable;
    }

    if ((src == Integer.TYPE) || Integer.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest)) ? true : assignable;
    }

    if ((src == Short.TYPE) || Short.class.isAssignableFrom(src)) {
        assignable = (isByte(dest)) ? true : assignable;
    }

    return assignable;
}

From source file:org.lunarray.model.descriptor.converter.def.AbstractDefaultConverterTool.java

/**
 * Populates the simple converters./*from   w  ww  .j  a  v a2 s  .c  o m*/
 */
private void populateSimpleConverters() {
    // Primitives.
    this.converters.put(Integer.TYPE, new IntegerConverter());
    this.converters.put(Double.TYPE, new DoubleConverter());
    this.converters.put(Float.TYPE, new FloatConverter());
    this.converters.put(Long.TYPE, new LongConverter());
    this.converters.put(Byte.TYPE, new ByteConverter());
    this.converters.put(Short.TYPE, new ShortConverter());
    this.converters.put(Character.TYPE, new CharacterConverter());
    this.converters.put(Boolean.TYPE, new BooleanConverter());
    // Date types.
    this.addConverter(new CalendarConverter());
    this.addConverter(new DateConverter());
    // SQL Date types.
    this.addConverter(new SqlDateConverter());
    this.addConverter(new SqlTimeConverter());
    this.addConverter(new SqlTimestampConverter());
    // String.
    this.addConverter(new IdempotentConverter());
    // Numbers.
    this.addConverter(new IntegerConverter());
    this.addConverter(new DoubleConverter());
    this.addConverter(new FloatConverter());
    this.addConverter(new LongConverter());
    this.addConverter(new ByteConverter());
    this.addConverter(new ShortConverter());
    // Character.
    this.addConverter(new CharacterConverter());
    // Math types.
    this.addConverter(new BigDecimalConverter());
    this.addConverter(new BigIntegerConverter());
    // Boolean.
    this.addConverter(new BooleanConverter());
}

From source file:nl.strohalm.cyclos.services.elements.MemberImportServiceImpl.java

@Override
public MemberImport importMembers(MemberImport memberImport, final InputStream data) {
    final LocalSettings localSettings = settingsService.getLocalSettings();
    final AccessSettings accessSettings = settingsService.getAccessSettings();

    // Validate and save the import
    getValidator().validate(memberImport);
    final MemberGroup group = fetchService.fetch(memberImport.getGroup());
    memberImport.setGroup(group);//from  www . j  av a  2s.com
    memberImport.setBy(LoggedUser.<Administrator>element());
    memberImport.setDate(Calendar.getInstance());
    memberImport = memberImportDao.insert(memberImport);

    // Get the account settings
    MemberGroupAccountSettings accountSettings = null;
    final MemberAccountType accountType = memberImport.getAccountType();
    if (accountType != null) {
        accountSettings = groupService.loadAccountSettings(group.getId(), accountType.getId());
    }

    // Find out the custom fields;
    List<MemberCustomField> customFields = memberCustomFieldService.list();
    customFields = customFieldHelper.onlyForGroup(customFields, group);
    final Map<String, CustomField> customFieldMap = new HashMap<String, CustomField>(customFields.size());
    for (final MemberCustomField customField : customFields) {
        customFieldMap.put(customField.getInternalName().toLowerCase(),
                fetchService.fetch(customField, CustomField.Relationships.POSSIBLE_VALUES));
    }

    // Find the record types
    final MemberRecordTypeQuery mrtQuery = new MemberRecordTypeQuery();
    mrtQuery.fetch(MemberRecordType.Relationships.FIELDS);
    Collection<Group> mrtGroups = new ArrayList<Group>();
    mrtGroups.add(group);
    mrtQuery.setGroups(mrtGroups);
    final List<MemberRecordType> recordTypes = memberRecordTypeService.search(mrtQuery);
    final Map<String, MemberRecordType> recordTypeMap = new HashMap<String, MemberRecordType>(
            recordTypes.size());
    final Map<MemberRecordType, Map<String, CustomField>> recordTypeFieldsMap = new HashMap<MemberRecordType, Map<String, CustomField>>(
            recordTypes.size());
    for (final MemberRecordType recordType : recordTypes) {
        final String lowercaseName = recordType.getName().toLowerCase();
        recordTypeMap.put(lowercaseName, recordType);
        // Get the custom fields for this record type
        final Map<String, CustomField> fields = new HashMap<String, CustomField>();
        for (final MemberRecordCustomField customField : recordType.getFields()) {
            fields.put(customField.getInternalName().toLowerCase(),
                    fetchService.fetch(customField, CustomField.Relationships.POSSIBLE_VALUES));
        }
        recordTypeFieldsMap.put(recordType, fields);
    }

    // We need to read the first line in order to discover which columns exist
    final char stringQuote = CoercionHelper.coerce(Character.TYPE,
            localSettings.getCsvStringQuote().getValue());
    final char valueSeparator = CoercionHelper.coerce(Character.TYPE,
            localSettings.getCsvValueSeparator().getValue());
    BufferedReader in = null;
    List<String> headers;
    try {
        in = new BufferedReader(new InputStreamReader(data, localSettings.getCharset()));
        headers = CSVReader.readLine(in, stringQuote, valueSeparator);
    } catch (final Exception e) {
        throw new ValidationException("memberImport.invalidFormat");
    }

    final Set<String> usedUsernames = new HashSet<String>();
    // Import each member
    try {
        final CacheCleaner cacheCleaner = new CacheCleaner(fetchService);
        int lineNumber = 2; // The first line is the header
        List<String> values;
        while ((values = CSVReader.readLine(in, stringQuote, valueSeparator)) != null) {
            if (values.isEmpty()) {
                continue;
            }
            importMember(memberImport, accountSettings, lineNumber, customFieldMap, recordTypeMap,
                    recordTypeFieldsMap, localSettings, accessSettings, headers, values, usedUsernames);
            lineNumber++;
            cacheCleaner.clearCache();
        }
    } catch (final IOException e) {
        throw new ValidationException("memberImport.errorReading");
    } finally {
        IOUtils.closeQuietly(in);
    }
    return memberImport;
}

From source file:Classes.java

/**
 * This method acts equivalently to invoking classLoader.loadClass(className)
 * but it also supports primitive types and array classes of object types or
 * primitive types.// w w w.j a va 2 s . c  om
 * 
 * @param className
 *          the qualified name of the class or the name of primitive type or
 *          array in the same format as returned by the
 *          java.lang.Class.getName() method.
 * @param classLoader
 *          the ClassLoader used to load classes
 * @return the Class object for the requested className
 * 
 * @throws ClassNotFoundException
 *           when the <code>classLoader</code> can not find the requested
 *           class
 */
public static Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException {
    // ClassLoader.loadClass() does not handle primitive types:
    //
    // B byte
    // C char
    // D double
    // F float
    // I int
    // J long
    // S short
    // Z boolean
    // V void
    //
    if (className.length() == 1) {
        char type = className.charAt(0);
        if (type == 'B')
            return Byte.TYPE;
        if (type == 'C')
            return Character.TYPE;
        if (type == 'D')
            return Double.TYPE;
        if (type == 'F')
            return Float.TYPE;
        if (type == 'I')
            return Integer.TYPE;
        if (type == 'J')
            return Long.TYPE;
        if (type == 'S')
            return Short.TYPE;
        if (type == 'Z')
            return Boolean.TYPE;
        if (type == 'V')
            return Void.TYPE;
        // else throw...
        throw new ClassNotFoundException(className);
    }

    // Check for a primative type
    if (isPrimitive(className) == true)
        return (Class) Classes.PRIMITIVE_NAME_TYPE_MAP.get(className);

    // Check for the internal vm format: Lclassname;
    if (className.charAt(0) == 'L' && className.charAt(className.length() - 1) == ';')
        return classLoader.loadClass(className.substring(1, className.length() - 1));

    // first try - be optimistic
    // this will succeed for all non-array classes and array classes that have
    // already been resolved
    //
    try {
        return classLoader.loadClass(className);
    } catch (ClassNotFoundException e) {
        // if it was non-array class then throw it
        if (className.charAt(0) != '[')
            throw e;
    }

    // we are now resolving array class for the first time

    // count opening braces
    int arrayDimension = 0;
    while (className.charAt(arrayDimension) == '[')
        arrayDimension++;

    // resolve component type - use recursion so that we can resolve primitive
    // types also
    Class componentType = loadClass(className.substring(arrayDimension), classLoader);

    // construct array class
    return Array.newInstance(componentType, new int[arrayDimension]).getClass();
}

From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java

/**
 * Tests if Class represents a String or a char
 *///from  www  . j a v  a 2  s.co m
public static boolean isString(Class clazz) {
    return clazz != null && (String.class.isAssignableFrom(clazz)
            || (Character.TYPE.isAssignableFrom(clazz) || Character.class.isAssignableFrom(clazz)));
}

From source file:org.nuxeo.ecm.automation.io.services.codec.ObjectCodecService.java

protected final void writeGenericObject(JsonGenerator jg, Class<?> clazz, Object object) throws IOException {
    jg.writeStartObject();//ww  w  . j a  v  a2s.  c om
    if (clazz.isPrimitive()) {
        if (clazz == Boolean.TYPE) {
            jg.writeStringField("entity-type", "boolean");
            jg.writeBooleanField("value", (Boolean) object);
        } else if (clazz == Double.TYPE || clazz == Float.TYPE) {
            jg.writeStringField("entity-type", "number");
            jg.writeNumberField("value", ((Number) object).doubleValue());
        } else if (clazz == Integer.TYPE || clazz == Long.TYPE || clazz == Short.TYPE || clazz == Byte.TYPE) {
            jg.writeStringField("entity-type", "number");
            jg.writeNumberField("value", ((Number) object).longValue());
        } else if (clazz == Character.TYPE) {
            jg.writeStringField("entity-type", "string");
            jg.writeStringField("value", object.toString());
        }
        return;
    }
    if (jg.getCodec() == null) {
        jg.setCodec(new ObjectMapper());
    }
    if (object instanceof Iterable && clazz.getName().startsWith("java.")) {
        jg.writeStringField("entity-type", "list");
    } else if (object instanceof Map && clazz.getName().startsWith("java.")) {
        if (object instanceof LinkedHashMap) {
            jg.writeStringField("entity-type", "orderedMap");
        } else {
            jg.writeStringField("entity-type", "map");
        }
    } else {
        jg.writeStringField("entity-type", clazz.getName());
    }
    jg.writeObjectField("value", object);
    jg.writeEndObject();
}

From source file:com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.java

protected Object convertArray(FacesContext facesContext, UISelectMany uiSelectMany, Class componentType,
        String[] newSubmittedValues) throws ConverterException {

    // component type of String means no conversion is necessary
    if (componentType.equals(String.class)) {
        return newSubmittedValues;
    }// w  w w. jav  a2 s .  c o  m

    // if newSubmittedValue is null return zero-length array
    if (newSubmittedValues == null) {
        return Array.newInstance(componentType, 0);
    }

    // create the array with specified component length
    int numberOfValues = newSubmittedValues.length;
    Object convertedValues = Array.newInstance(componentType, numberOfValues);

    // Determine if a converter is explicitly registered with the component
    Converter converter = uiSelectMany.getConverter();
    if (converter == null) {
        // Determine if there is a default converter for the class
        converter = getConverterForClass(componentType);
    }
    if (converter == null) {
        // we don't need to convert base Object types
        if (componentType.equals(Object.class)) {
            return newSubmittedValues;
        } else {
            throw new ConverterException("Converter is null");
        }
    }

    for (int index = 0; index < numberOfValues; index++) {

        // convert the next element
        Object nextConvertedElement = converter.getAsObject(facesContext, uiSelectMany,
                newSubmittedValues[index]);

        if (!componentType.isPrimitive()) {
            Array.set(convertedValues, index, nextConvertedElement);
        } else if (componentType.equals(Boolean.TYPE)) {

            Array.setBoolean(convertedValues, index, ((Boolean) nextConvertedElement).booleanValue());

        } else if (componentType.equals(Integer.TYPE)) {

            Array.setInt(convertedValues, index, ((Integer) nextConvertedElement).intValue());

        } else if (componentType.equals(Long.TYPE)) {

            Array.setLong(convertedValues, index, ((Long) nextConvertedElement).longValue());

        } else if (componentType.equals(Short.TYPE)) {

            Array.setShort(convertedValues, index, ((Short) nextConvertedElement).shortValue());

        } else if (componentType.equals(Byte.TYPE)) {

            Array.setByte(convertedValues, index, ((Byte) nextConvertedElement).byteValue());

        } else if (componentType.equals(Float.TYPE)) {

            Array.setFloat(convertedValues, index, ((Float) nextConvertedElement).floatValue());

        } else if (componentType.equals(Double.TYPE)) {

            Array.setDouble(convertedValues, index, ((Double) nextConvertedElement).doubleValue());

        } else if (componentType.equals(Character.TYPE)) {

            Array.setChar(convertedValues, index, ((Character) nextConvertedElement).charValue());

        }
    }
    return convertedValues;
}