Example usage for java.lang Integer TYPE

List of usage examples for java.lang Integer TYPE

Introduction

In this page you can find the example usage for java.lang Integer TYPE.

Prototype

Class TYPE

To view the source code for java.lang Integer TYPE.

Click Source Link

Document

The Class instance representing the primitive type int .

Usage

From source file:ca.sqlpower.matchmaker.MatchMakerTestCase.java

/**
 * Returns a new value that is not equal to oldVal. If oldVal is immutable, the
 * returned object will be a new instance compatible with oldVal.  If oldVal is 
 * mutable, it will be modified in some way so it is no longer equal to its original
 * value. {@link #getNewDifferentValue(MatchMakerObject, PropertyDescriptor, Object)}
 * is a similar method that does not take mutability into account and always returns 
 * a new value./*from  w ww .  j a v  a 2s.c o m*/
 * 
 * @param mmo The object to which the property belongs.  You might need this
 *  if you have a special case for certain types of objects.
 * @param property The property that should be modified.  It belongs to mmo.
 * @param oldVal The existing value of the property to modify.  The returned value
 * will not equal this one at the time this method was first called, although it may
 * be the same instance as this one, but modified in some way.
 */
private Object modifyObject(MatchMakerObject mmo, PropertyDescriptor property, Object oldVal)
        throws IOException {
    if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) {
        return ((Integer) oldVal) + 1;
    } else if (property.getPropertyType() == Short.TYPE || property.getPropertyType() == Short.class) {
        return ((Short) oldVal) + 1;
    } else if (property.getPropertyType() == String.class) {
        if (oldVal == null) {
            return "new";
        } else {
            return "new " + oldVal;
        }
    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        return new Boolean(!((Boolean) oldVal).booleanValue());
    } else if (property.getPropertyType() == Long.class) {
        return new Long(((Long) oldVal).longValue() + 1L);
    } else if (property.getPropertyType() == BigDecimal.class) {
        return new BigDecimal(((BigDecimal) oldVal).longValue() + 1L);
    } else if (property.getPropertyType() == MungeSettings.class) {
        Integer processCount = ((MatchMakerSettings) oldVal).getProcessCount();
        processCount = new Integer((processCount == null) ? new Integer(0) : processCount + 1);
        ((MatchMakerSettings) oldVal).setProcessCount(processCount);
        return oldVal;
    } else if (property.getPropertyType() == MergeSettings.class) {
        Integer processCount = ((MatchMakerSettings) oldVal).getProcessCount();
        processCount = new Integer((processCount == null) ? new Integer(0) : processCount + 1);
        ((MatchMakerSettings) oldVal).setProcessCount(processCount);
        return oldVal;
    } else if (property.getPropertyType() == SQLTable.class) {
        ((SQLTable) oldVal).setRemarks("Testing Remarks");
        return oldVal;
    } else if (property.getPropertyType() == ViewSpec.class) {
        ((ViewSpec) oldVal).setName("Testing New Name");
        return oldVal;
    } else if (property.getPropertyType() == File.class) {
        oldVal = File.createTempFile("mmTest2", ".tmp");
        ((File) oldVal).deleteOnExit();
        return oldVal;
    } else if (property.getPropertyType() == ProjectMode.class) {
        if (oldVal == ProjectMode.BUILD_XREF) {
            return ProjectMode.FIND_DUPES;
        } else {
            return ProjectMode.BUILD_XREF;
        }
    } else if (property.getPropertyType() == MergeActionType.class) {
        if (oldVal == MergeActionType.AUGMENT) {
            return MergeActionType.SUM;
        } else {
            return MergeActionType.AUGMENT;
        }
    } else if (property.getPropertyType() == MatchMakerObject.class) {
        ((MatchMakerObject) oldVal).setName("Testing New Name");
        return oldVal;
    } else if (property.getPropertyType() == MatchMakerTranslateGroup.class) {
        ((MatchMakerObject) oldVal).setName("Testing New Name2");
        return oldVal;
    } else if (property.getPropertyType() == SQLColumn.class) {
        ((SQLColumn) oldVal).setRemarks("Testing Remarks");
        return oldVal;
    } else if (property.getPropertyType() == Date.class) {
        ((Date) oldVal).setTime(((Date) oldVal).getTime() + 10000);
        return oldVal;
    } else if (property.getPropertyType() == List.class) {
        if (property.getName().equals("children")) {
            if (mmo instanceof TableMergeRules) {
                ((List) oldVal).add(new ColumnMergeRules());
            } else {
                ((List) oldVal).add(new StubMatchMakerObject());
            }
        } else {
            ((List) oldVal).add("Test");
        }
        return oldVal;
    } else if (property.getPropertyType() == SQLIndex.class) {
        ((SQLIndex) oldVal).setName("modified index");
        return oldVal;
    } else if (property.getPropertyType() == Color.class) {
        if (oldVal == null) {
            return new Color(0xFAC157);
        } else {
            Color oldColor = (Color) oldVal;
            return new Color((oldColor.getRGB() + 0xF00) % 0x1000000);
        }
    } else if (property.getPropertyType() == ChildMergeActionType.class) {
        if (oldVal != null && oldVal.equals(ChildMergeActionType.DELETE_ALL_DUP_CHILD)) {
            return ChildMergeActionType.UPDATE_DELETE_ON_CONFLICT;
        } else {
            return ChildMergeActionType.DELETE_ALL_DUP_CHILD;
        }
    } else if (property.getPropertyType() == TableMergeRules.class) {
        if (oldVal == null) {
            return mmo;
        } else {
            return null;
        }
    } else if (property.getPropertyType() == PoolFilterSetting.class) {
        if (oldVal != PoolFilterSetting.EVERYTHING) {
            return PoolFilterSetting.EVERYTHING;
        } else {
            return PoolFilterSetting.INVALID_ONLY;
        }
    } else if (property.getPropertyType() == AutoValidateSetting.class) {
        if (oldVal != AutoValidateSetting.NOTHING) {
            return AutoValidateSetting.NOTHING;
        } else {
            return AutoValidateSetting.SERP_CORRECTABLE;
        }
    } else if (property.getPropertyType() == TableIndex.class) {
        CachableTable cachableTable = new CachableTable("newValue");
        TableIndex tableIndex = new TableIndex(cachableTable, "newValueIndex");
        if (tableIndex.getTableIndex() == null) {
            tableIndex.setTableIndex(new SQLIndex());
        } else {
            tableIndex.setTableIndex(null);
        }
        return tableIndex;
    } else if (property.getPropertyType() == CachableTable.class) {
        CachableTable cachableTable = new CachableTable("newValue");
        return cachableTable;
    } else {
        throw new RuntimeException("This test case lacks the ability to modify values for " + property.getName()
                + " (type " + property.getPropertyType().getName() + ")");
    }
}

From source file:com.qmetry.qaf.automation.data.BaseDataBean.java

/**
 * This will fill random data except those properties which has skip=true in
 * {@link Randomizer} annotation. Use {@link Randomizer} annotation to
 * specify data value to be generated for specific property.
 * /*from  w ww.j a  va2s.c o  m*/
 * @see Randomizer
 */
public void fillRandomData() {
    Field[] fields = getFields();
    for (Field field : fields) {
        logger.debug("NAME :: " + field.getName());
        if (!(Modifier.isFinal(field.getModifiers()))) {
            RandomizerTypes type = RandomizerTypes.MIXED;
            int len = 10;
            long min = 0, max = 0;
            String prefix = "", suffix = "";
            String format = "";
            String[] list = {};

            Randomizer randomizer = field.getAnnotation(Randomizer.class);

            if (randomizer != null) {
                if (randomizer.skip()) {
                    continue;
                }
                type = field.getType() == Date.class ? RandomizerTypes.DIGITS_ONLY : randomizer.type();
                len = randomizer.length();
                prefix = randomizer.prefix();
                suffix = randomizer.suffix();
                min = randomizer.minval();
                max = min > randomizer.maxval() ? min : randomizer.maxval();
                format = randomizer.format();
                list = randomizer.dataset();
            } else {
                // @Since 2.1.2 randomizer annotation is must for random
                // value
                // generation
                continue;
            }

            String str = "";
            if ((list == null) || (list.length == 0)) {
                str = StringUtil.isBlank(format)
                        ? RandomStringUtils.random(len, !type.equals(RandomizerTypes.DIGITS_ONLY),
                                !type.equals(RandomizerTypes.LETTERS_ONLY))
                        : StringUtil.getRandomString(format);
            } else {
                str = getRandomValue(list);
            }

            try {
                // deal with IllegalAccessException
                field.setAccessible(true);
                Method setter = null;
                try {
                    setter = this.getClass().getMethod("set" + StringUtil.getTitleCase(field.getName()),
                            String.class);
                } catch (Exception e) {

                }

                if ((field.getType() == String.class) || (null != setter)) {
                    if ((list == null) || (list.length == 0)) {
                        if ((min == max) && (min == 0)) {
                            str = StringUtil.isBlank(format)
                                    ? RandomStringUtils.random(len, !type.equals(RandomizerTypes.DIGITS_ONLY),
                                            !type.equals(RandomizerTypes.LETTERS_ONLY))
                                    : StringUtil.getRandomString(format);

                        } else {
                            str = String.valueOf((int) (Math.random() * ((max - min) + 1)) + min);

                        }
                    }
                    String rStr = prefix + str + suffix;
                    if (null != setter) {
                        setter.setAccessible(true);
                        setter.invoke(this, rStr);
                    } else {
                        field.set(this, rStr);
                    }
                } else {
                    String rStr = "";
                    if ((min == max) && (min == 0)) {
                        rStr = RandomStringUtils.random(len, false, true);
                    } else {
                        rStr = String.valueOf((int) (Math.random() * ((max - min) + 1)) + min);

                    }

                    if (field.getType() == Integer.TYPE) {
                        field.setInt(this, Integer.parseInt(rStr));
                    } else if (field.getType() == Float.TYPE) {
                        field.setFloat(this, Float.parseFloat(rStr));

                    } else if (field.getType() == Double.TYPE) {
                        field.setDouble(this, Double.parseDouble(rStr));

                    } else if (field.getType() == Long.TYPE) {
                        field.setLong(this, Long.parseLong(rStr));

                    } else if (field.getType() == Short.TYPE) {
                        field.setShort(this, Short.parseShort(rStr));
                    } else if (field.getType() == Date.class) {
                        logger.info("filling date " + rStr);
                        int days = Integer.parseInt(rStr);
                        field.set(this, DateUtil.getDate(days));
                    } else if (field.getType() == Boolean.TYPE) {
                        field.setBoolean(this, RandomUtils.nextBoolean());

                    }
                }
            } catch (IllegalArgumentException e) {

                logger.error("Unable to fill random data in field " + field.getName(), e);
            } catch (IllegalAccessException e) {
                logger.error("Unable to Access " + field.getName(), e);
            } catch (InvocationTargetException e) {
                logger.error("Unable to Access setter for " + field.getName(), e);

            }
        }

    }

}

From source file:net.dmulloy2.ultimatearena.types.ArenaConfig.java

@Override
public Map<String, Object> serialize() {
    Map<String, Object> data = new LinkedHashMap<>();

    for (Field field : ArenaConfig.class.getDeclaredFields()) {
        try {/*from w w  w .  ja va  2s. com*/
            if (Modifier.isTransient(field.getModifiers()))
                continue;

            boolean accessible = field.isAccessible();

            field.setAccessible(true);

            if (field.getType().equals(Integer.TYPE)) {
                if (field.getInt(this) != 0)
                    data.put(field.getName(), field.getInt(this));
            } else if (field.getType().equals(Long.TYPE)) {
                if (field.getLong(this) != 0)
                    data.put(field.getName(), field.getLong(this));
            } else if (field.getType().equals(Boolean.TYPE)) {
                if (field.getBoolean(this))
                    data.put(field.getName(), field.getBoolean(this));
            } else if (field.getType().isAssignableFrom(Collection.class)) {
                if (!((Collection<?>) field.get(this)).isEmpty())
                    data.put(field.getName(), field.get(this));
            } else if (field.getType().isAssignableFrom(String.class)) {
                if ((String) field.get(this) != null)
                    data.put(field.getName(), field.get(this));
            } else if (field.getType().isAssignableFrom(Map.class)) {
                if (!((Map<?, ?>) field.get(this)).isEmpty())
                    data.put(field.getName(), field.get(this));
            } else {
                if (field.get(this) != null)
                    data.put(field.getName(), field.get(this));
            }

            field.setAccessible(accessible);
        } catch (Throwable ex) {
        }
    }

    serializeCustomOptions(data);
    return data;
}

From source file:org.apache.jackrabbit.core.persistence.db.OraclePersistenceManager.java

/**
 * Creates a temporary oracle.sql.BLOB instance via reflection and spools
 * the contents of the specified stream.
 *///from  w  ww .ja v a2s. c  om
protected Blob createTemporaryBlob(InputStream in) throws Exception {
    /*
    BLOB blob = BLOB.createTemporary(con, false, BLOB.DURATION_SESSION);
    blob.open(BLOB.MODE_READWRITE);
    OutputStream out = blob.getBinaryOutputStream();
    ...
    out.flush();
    out.close();
    blob.close();
    return blob;
    */
    Method createTemporary = blobClass.getMethod("createTemporary",
            new Class[] { Connection.class, Boolean.TYPE, Integer.TYPE });
    Object blob = createTemporary.invoke(null,
            new Object[] { ConnectionFactory.unwrap(con), Boolean.FALSE, durationSessionConstant });
    Method open = blobClass.getMethod("open", new Class[] { Integer.TYPE });
    open.invoke(blob, new Object[] { modeReadWriteConstant });
    Method getBinaryOutputStream = blobClass.getMethod("getBinaryOutputStream", new Class[0]);
    OutputStream out = (OutputStream) getBinaryOutputStream.invoke(blob);
    try {
        IOUtils.copy(in, out);
    } finally {
        try {
            out.flush();
        } catch (IOException ioe) {
        }
        out.close();
    }
    Method close = blobClass.getMethod("close", new Class[0]);
    close.invoke(blob);
    return (Blob) blob;
}

From source file:org.apache.beehive.controls.system.jdbc.JdbcControlImpl.java

/**
 * Create and exec a {@link PreparedStatement}
 *
 * @param method the method to invoke/* w  w w . ja va2s.co  m*/
 * @param args the method's arguments
 * @return the return value from the {@link PreparedStatement}
 * @throws Throwable any exception that occurs; the caller should handle these appropriately
 */
protected Object execPreparedStatement(Method method, Object[] args) throws Throwable {

    final SQL methodSQL = (SQL) _context.getMethodPropertySet(method, SQL.class);
    if (methodSQL == null || methodSQL.statement() == null) {
        throw new ControlException("Method " + method.getName() + " is missing @SQL annotation");
    }

    setTypeMappers(methodSQL.typeMappersOverride());

    //
    // build the statement and execute it
    //

    PreparedStatement ps = null;
    try {
        Class returnType = method.getReturnType();

        SqlStatement sqlStatement = _sqlParser.parse(methodSQL.statement());
        ps = sqlStatement.createPreparedStatement(_context, _connection, _cal, method, args);

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("PreparedStatement: "
                    + sqlStatement.createPreparedStatementString(_context, _connection, method, args));
        }

        //
        // special processing for batch updates
        //
        if (sqlStatement.isBatchUpdate()) {
            return ps.executeBatch();
        }

        //
        // execute the statement
        //
        boolean hasResults = ps.execute();

        //
        // callable statement processing
        //
        if (sqlStatement.isCallableStatement()) {
            SQLParameter[] params = (SQLParameter[]) args[0];
            for (int i = 0; i < params.length; i++) {
                if (params[i].dir != SQLParameter.IN) {
                    params[i].value = ((CallableStatement) ps).getObject(i + 1);
                }
            }
            return null;
        }

        //
        // process returned data
        //
        ResultSet rs = null;
        int updateCount = ps.getUpdateCount();

        if (hasResults) {
            rs = ps.getResultSet();
        }

        if (sqlStatement.getsGeneratedKeys()) {
            rs = ps.getGeneratedKeys();
            hasResults = true;
        }

        if (!hasResults && updateCount > -1) {
            boolean moreResults = ps.getMoreResults();
            int tempUpdateCount = ps.getUpdateCount();

            while ((moreResults && rs == null) || tempUpdateCount > -1) {
                if (moreResults) {
                    rs = ps.getResultSet();
                    hasResults = true;
                    moreResults = false;
                    tempUpdateCount = -1;
                } else {
                    moreResults = ps.getMoreResults();
                    tempUpdateCount = ps.getUpdateCount();
                }
            }
        }

        Object returnObject = null;
        if (hasResults) {

            //
            // if a result set mapper was specified in the methods annotation, use it
            // otherwise find the mapper for the return type in the hashmap
            //
            final Class resultSetMapperClass = methodSQL.resultSetMapper();
            final ResultSetMapper rsm;
            if (!UndefinedResultSetMapper.class.isAssignableFrom(resultSetMapperClass)) {
                if (ResultSetMapper.class.isAssignableFrom(resultSetMapperClass)) {
                    rsm = (ResultSetMapper) resultSetMapperClass.newInstance();
                } else {
                    throw new ControlException(
                            "Result set mappers must be subclasses of ResultSetMapper.class!");
                }
            } else {
                if (_resultMappers.containsKey(returnType)) {
                    rsm = _resultMappers.get(returnType);
                } else {
                    if (_xmlObjectClass != null && _xmlObjectClass.isAssignableFrom(returnType)) {
                        rsm = _resultMappers.get(_xmlObjectClass);
                    } else {
                        rsm = DEFAULT_MAPPER;
                    }
                }
            }

            returnObject = rsm.mapToResultType(_context, method, rs, _cal);
            if (rsm.canCloseResultSet() == false) {
                getResources().add(ps);
            }

            //
            // empty ResultSet
            //
        } else {
            if (returnType.equals(Void.TYPE)) {
                returnObject = null;
            } else if (returnType.equals(Integer.TYPE)) {
                returnObject = new Integer(updateCount);
            } else if (!sqlStatement.isCallableStatement()) {
                throw new ControlException(
                        "Method " + method.getName() + "is DML but does not return void or int");
            }
        }
        return returnObject;

    } finally {
        // Keep statements open that have in-use result sets
        if (ps != null && !getResources().contains(ps)) {
            ps.close();
        }
    }
}

From source file:org.enerj.apache.commons.beanutils.locale.LocaleConvertUtilsBean.java

/**
 *  Create all {@link LocaleConverter} types for specified locale.
 *
 * @param locale The Locale//from   w w w  .ja  v  a 2 s.  c  om
 * @return The FastHashMap instance contains the all {@link LocaleConverter} types
 *  for the specified locale.
 */
protected FastHashMap create(Locale locale) {

    FastHashMap converter = new FastHashMap();
    converter.setFast(false);

    converter.put(BigDecimal.class, new BigDecimalLocaleConverter(locale, applyLocalized));
    converter.put(BigInteger.class, new BigIntegerLocaleConverter(locale, applyLocalized));

    converter.put(Byte.class, new ByteLocaleConverter(locale, applyLocalized));
    converter.put(Byte.TYPE, new ByteLocaleConverter(locale, applyLocalized));

    converter.put(Double.class, new DoubleLocaleConverter(locale, applyLocalized));
    converter.put(Double.TYPE, new DoubleLocaleConverter(locale, applyLocalized));

    converter.put(Float.class, new FloatLocaleConverter(locale, applyLocalized));
    converter.put(Float.TYPE, new FloatLocaleConverter(locale, applyLocalized));

    converter.put(Integer.class, new IntegerLocaleConverter(locale, applyLocalized));
    converter.put(Integer.TYPE, new IntegerLocaleConverter(locale, applyLocalized));

    converter.put(Long.class, new LongLocaleConverter(locale, applyLocalized));
    converter.put(Long.TYPE, new LongLocaleConverter(locale, applyLocalized));

    converter.put(Short.class, new ShortLocaleConverter(locale, applyLocalized));
    converter.put(Short.TYPE, new ShortLocaleConverter(locale, applyLocalized));

    converter.put(String.class, new StringLocaleConverter(locale, applyLocalized));

    // conversion format patterns of java.sql.* types should correspond to default
    // behaviour of toString and valueOf methods of these classes
    converter.put(java.sql.Date.class, new SqlDateLocaleConverter(locale, "yyyy-MM-dd"));
    converter.put(java.sql.Time.class, new SqlTimeLocaleConverter(locale, "HH:mm:ss"));
    converter.put(java.sql.Timestamp.class, new SqlTimestampLocaleConverter(locale, "yyyy-MM-dd HH:mm:ss.S"));

    converter.setFast(true);

    return converter;
}

From source file:org.fhcrc.cpl.toolbox.filehandler.TabLoader.java

public Object[] loadColsAsArrays() throws IOException {
    initColNameMap();/*from  w w w.j  a v a  2 s  . c o  m*/
    ColumnDescriptor[] columns = getColumns();
    Object[] valueLists = new Object[columns.length];

    for (int i = 0; i < valueLists.length; i++) {
        if (!columns[i].load)
            continue;

        Class clazz = columns[i].clazz;
        if (clazz.isPrimitive()) {
            if (clazz.equals(Double.TYPE))
                valueLists[i] = new DoubleArray();
            else if (clazz.equals(Float.TYPE))
                valueLists[i] = new FloatArray();
            else if (clazz.equals(Integer.TYPE))
                valueLists[i] = new IntegerArray();
        } else {
            valueLists[i] = new ArrayList();
        }
    }

    BufferedReader reader = null;
    try {
        reader = getReader();
        int line = 0;

        String s;
        for (int skip = 0; skip < _skipLines; skip++) {
            //noinspection UnusedAssignment
            s = reader.readLine();
            line++;
        }

        while ((s = reader.readLine()) != null) {
            line++;
            if ("".equals(s.trim()))
                continue;

            String[] fields = parseLine(s);
            for (int i = 0; i < fields.length && i < columns.length; i++) {
                if (!columns[i].load)
                    continue;

                String value = fields[i];

                Class clazz = columns[i].clazz;
                if (clazz.isPrimitive()) {
                    if (clazz.equals(Double.TYPE))
                        ((DoubleArray) valueLists[i]).add(Double.parseDouble(value));
                    else if (clazz.equals(Float.TYPE))
                        ((FloatArray) valueLists[i]).add(Float.parseFloat(value));
                    else if (clazz.equals(Integer.TYPE))
                        ((IntegerArray) valueLists[i]).add(Integer.parseInt(value));
                } else {
                    try {
                        if ("".equals(value))
                            ((List<Object>) valueLists[i]).add(columns[i].missingValues);
                        else
                            ((List<Object>) valueLists[i]).add(ConvertUtils.convert(value, columns[i].clazz));
                    } catch (Exception x) {
                        if (_throwOnErrors)
                            throw new ConversionException(
                                    "Conversion error: line " + line + " column " + (i + 1), x);

                        ((List<Object>) valueLists[i]).add(columns[i].errorValues);
                    }
                }

            }
        }
    } finally {
        if (null != reader)
            reader.close();
    }

    Object[] returnArrays = new Object[columns.length];
    for (int i = 0; i < columns.length; i++) {
        if (!columns[i].load)
            continue;

        Class clazz = columns[i].clazz;
        if (clazz.isPrimitive()) {
            if (clazz.equals(Double.TYPE))
                returnArrays[i] = ((DoubleArray) valueLists[i]).toArray(null);
            else if (clazz.equals(Float.TYPE))
                returnArrays[i] = ((FloatArray) valueLists[i]).toArray(null);
            else if (clazz.equals(Integer.TYPE))
                returnArrays[i] = ((IntegerArray) valueLists[i]).toArray(null);
        } else {
            Object[] values = (Object[]) Array.newInstance(columns[i].clazz, ((List) valueLists[i]).size());
            returnArrays[i] = ((List<Object>) valueLists[i]).toArray(values);
        }
    }

    return returnArrays;
}

From source file:com.netflix.governator.lifecycle.LifecycleManager.java

private void assignConfiguration(Object obj, Field field) throws Exception {
    Configuration configuration = field.getAnnotation(Configuration.class);
    String configurationName = configuration.value();
    ConfigurationKey key = new ConfigurationKey(configurationName, KeyParser.parse(configurationName));

    Object value = null;/*  ww w .j  av a 2 s . co  m*/

    boolean has = configurationProvider.has(key);
    if (has) {
        try {
            if (String.class.isAssignableFrom(field.getType())) {
                value = configurationProvider.getString(key);
            } else if (Boolean.class.isAssignableFrom(field.getType())
                    || Boolean.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getBoolean(key);
            } else if (Integer.class.isAssignableFrom(field.getType())
                    || Integer.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getInteger(key);
            } else if (Long.class.isAssignableFrom(field.getType())
                    || Long.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getLong(key);
            } else if (Double.class.isAssignableFrom(field.getType())
                    || Double.TYPE.isAssignableFrom(field.getType())) {
                value = configurationProvider.getDouble(key);
            } else if (Date.class.isAssignableFrom(field.getType())) {
                value = parseDate(configurationName, configurationProvider.getString(key), configuration);
                if (null == value) {
                    field = null;
                }
            } else {
                log.error("Field type not supported: " + field.getType());
                field = null;
            }
        } catch (IllegalArgumentException e) {
            if (!Date.class.isAssignableFrom(field.getType())) {
                ignoreTypeMismtachIfConfigured(configuration, configurationName, e);
                field = null;
            }
        } catch (ConversionException e) {
            if (!Date.class.isAssignableFrom(field.getType())) {
                ignoreTypeMismtachIfConfigured(configuration, configurationName, e);
                field = null;
            }
        }
    }

    if (field != null) {
        String defaultValue = String.valueOf(field.get(obj));
        String documentationValue;
        if (has) {
            field.set(obj, value);
            documentationValue = String.valueOf(value);
        } else {
            documentationValue = "";
        }
        configurationDocumentation.registerConfiguration(field, configurationName, has, defaultValue,
                documentationValue, configuration.documentation());
    }
}

From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java

/**
 * /*from w  w  w . j av a2  s .c  o m*/
 * @param json
 * @param key
 * @param toField
 * @return
 * @throws JSONException
 */
public static Object getFromJsonByField2(JSONObject json, String key, Field toField) throws JSONException {
    final Object o = json.get(key);
    final Class<?> fieldType = toField.getType();
    if (o != JSONObject.NULL) {
        if (fieldType.equals(Integer.class) || fieldType.equals(Integer.TYPE)) {
            return json.getInt(key);
        } else if (fieldType.equals(String.class)) {
            return o;
        } else if (fieldType.equals(Long.class) || fieldType.equals(Long.TYPE)) {
            return json.getLong(key);
        } else if (fieldType.equals(Boolean.class) || fieldType.equals(Boolean.TYPE)) {
            return json.getBoolean(key);
        } else if (fieldType.equals(Float.class) || fieldType.equals(Float.TYPE)) {
            return (float) json.getDouble(key);
        } else if (fieldType.equals(Double.class) || fieldType.equals(Double.TYPE)) {
            return json.getDouble(key);
        } else {
            return o;
        }
    }

    return JSONObject.NULL;
}