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:com.boylesoftware.web.impl.UserInputControllerMethodArgHandler.java

/**
 * Create new handler.//  w ww.  j a v a  2 s . c om
 *
 * @param validatorFactory Validator factory.
 * @param beanClass User input bean class.
 * @param validationGroups Validation groups to apply during bean
 * validation, or empty array to use the default group.
 *
 * @throws UnavailableException If an error happens.
 */
UserInputControllerMethodArgHandler(final ValidatorFactory validatorFactory, final Class<?> beanClass,
        final Class<?>[] validationGroups) throws UnavailableException {

    this.validatorFactory = validatorFactory;

    this.beanClass = beanClass;
    this.validationGroups = validationGroups;

    try {
        final BeanInfo beanInfo = Introspector.getBeanInfo(this.beanClass);
        final PropertyDescriptor[] propDescs = beanInfo.getPropertyDescriptors();
        final List<FieldDesc> beanFields = new ArrayList<>();
        for (final PropertyDescriptor propDesc : propDescs) {
            final String propName = propDesc.getName();
            final Class<?> propType = propDesc.getPropertyType();
            final Method propGetter = propDesc.getReadMethod();
            final Method propSetter = propDesc.getWriteMethod();

            if ((propGetter == null) || (propSetter == null))
                continue;

            Field propField = null;
            for (Class<?> c = this.beanClass; !c.equals(Object.class); c = c.getSuperclass()) {
                try {
                    propField = c.getDeclaredField(propName);
                    break;
                } catch (final NoSuchFieldException e) {
                    // nothing, continue the loop
                }
            }
            final boolean noTrim = (((propField != null) && propField.isAnnotationPresent(NoTrim.class))
                    || (propGetter.isAnnotationPresent(NoTrim.class)));

            Class<? extends Binder> binderClass = null;
            String format = null;
            String errorMessage = Bind.DEFAULT_MESSAGE;
            Bind bindAnno = null;
            if (propField != null)
                bindAnno = propField.getAnnotation(Bind.class);
            if (bindAnno == null)
                bindAnno = propGetter.getAnnotation(Bind.class);
            if (bindAnno != null) {
                binderClass = bindAnno.binder();
                format = bindAnno.format();
                errorMessage = bindAnno.message();
            }
            if (binderClass == null) {
                if ((String.class).isAssignableFrom(propType))
                    binderClass = StringBinder.class;
                else if ((Boolean.class).isAssignableFrom(propType) || propType.equals(Boolean.TYPE))
                    binderClass = BooleanBinder.class;
                else if ((Integer.class).isAssignableFrom(propType) || propType.equals(Integer.TYPE))
                    binderClass = IntegerBinder.class;
                else if (propType.isEnum())
                    binderClass = EnumBinder.class;
                else // TODO: add more standard binders
                    throw new UnavailableException(
                            "Unsupported user input bean field type " + propType.getName() + ".");
            }

            beanFields.add(new FieldDesc(propDesc, noTrim, binderClass.newInstance(), format, errorMessage));
        }
        this.beanFields = beanFields.toArray(new FieldDesc[beanFields.size()]);
    } catch (final IntrospectionException e) {
        this.log.error("error introspecting user input bean", e);
        throw new UnavailableException("Specified user input bean" + " class could not be introspected.");
    } catch (final IllegalAccessException | InstantiationException e) {
        this.log.error("error instatiating binder", e);
        throw new UnavailableException("Used user input bean field binder" + " could not be instantiated.");
    }

    this.beanPool = new FastPool<>(new PoolableObjectFactory<PoolableUserInput>() {

        @Override
        public PoolableUserInput makeNew(final FastPool<PoolableUserInput> pool, final int pooledObjectId) {

            try {
                return new PoolableUserInput(pool, pooledObjectId, beanClass.newInstance());
            } catch (final InstantiationException | IllegalAccessException e) {
                throw new RuntimeException("Error instatiating user input bean.", e);
            }
        }
    }, "UserInputBeansPool_" + beanClass.getSimpleName());
}

From source file:com.sf.ddao.orm.RSMapperFactoryRegistry.java

public static RowMapperFactory getScalarRowMapperFactory(final Type itemType, final String name, boolean req) {
    if (itemType == String.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getString(name);
            }//  ww w  .  j a  v  a2s  .c o  m
        };
    }
    if (itemType == Integer.class || itemType == Integer.TYPE) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getInt(name);
            }
        };
    }
    if (itemType == URL.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getURL(name);
            }
        };
    }
    if (itemType == BigInteger.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                final BigDecimal res = rs.getBigDecimal(name);
                return res == null ? null : res.toBigInteger();
            }
        };
    }
    if (itemType == BigDecimal.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBigDecimal(name);
            }
        };
    }
    if (itemType == InputStream.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBinaryStream(name);
            }
        };
    }
    if (itemType == Boolean.class || itemType == Boolean.TYPE) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBoolean(name);
            }
        };
    }
    if (itemType == Blob.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBlob(name);
            }
        };
    }
    if (itemType == java.sql.Date.class || itemType == java.util.Date.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getTimestamp(name);
            }
        };
    }
    if (itemType instanceof Class) {
        final Class itemClass = (Class) itemType;
        final ColumnMapper columnMapper = ColumnMapperRegistry.lookup(itemClass);
        if (columnMapper != null) {
            return new ScalarRMF() {
                public Object map(ResultSet rs) throws SQLException {
                    return columnMapper.map(rs, name);
                }
            };
        }
        final Converter converter = ConvertUtils.lookup(itemClass);
        if (converter != null) {
            return new ScalarRMF() {
                public Object map(ResultSet rs) throws SQLException {
                    String s = rs.getString(name);
                    if (s == null) {
                        return null;
                    }
                    return converter.convert(itemClass, s);
                }
            };
        }
        if (Enum.class.isAssignableFrom((Class<?>) itemType)) {
            return new ScalarRMF() {
                public Object map(ResultSet rs) throws SQLException {
                    String s = rs.getString(name);
                    if (s == null) {
                        return null;
                    }
                    //noinspection unchecked
                    return Enum.valueOf((Class<Enum>) itemType, s);
                }
            };
        }
    }
    if (req) {
        throw new IllegalArgumentException("no mapping defined for " + itemType);
    }
    return null;
}

From source file:com.higgses.griffin.annotation.app.GinInjector.java

/**
 * ??/*from   w w  w .ja  v  a  2 s  .c  om*/
 * 
 * @param object
 * @param field
 */
private void injectResource(Object object, Field field) {
    if (field.isAnnotationPresent(GinInjectResource.class)) {
        GinInjectResource resourceJect = field.getAnnotation(GinInjectResource.class);
        int resourceID = resourceJect.id();
        try {
            Activity activity = null;
            if (object instanceof Activity) {
                activity = (Activity) object;
            } else if (object instanceof Fragment) {
                activity = ((Fragment) object).getActivity();
            }
            field.setAccessible(true);
            Resources resources = activity.getResources();
            String type = resources.getResourceTypeName(resourceID);
            if (type.equalsIgnoreCase("string")) {
                field.set(activity, activity.getResources().getString(resourceID));
            } else if (type.equalsIgnoreCase("drawable")) {
                field.set(activity, activity.getResources().getDrawable(resourceID));
            } else if (type.equalsIgnoreCase("layout")) {
                field.set(activity, activity.getResources().getLayout(resourceID));
            } else if (type.equalsIgnoreCase("array")) {
                if (field.getType().equals(int[].class)) {
                    field.set(activity, activity.getResources().getIntArray(resourceID));
                } else if (field.getType().equals(String[].class)) {
                    field.set(activity, activity.getResources().getStringArray(resourceID));
                } else {
                    field.set(activity, activity.getResources().getStringArray(resourceID));
                }

            } else if (type.equalsIgnoreCase("color")) {
                if (field.getType().equals(Integer.TYPE)) {
                    field.set(activity, activity.getResources().getColor(resourceID));
                } else {
                    field.set(activity, activity.getResources().getColorStateList(resourceID));
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:jp.terasoluna.fw.web.struts.reset.ResetterImpl.java

/**
 * ANVtH?[wv?peBZbg?B/*from   ww w  . ja  v a 2  s  . c om*/
 * v?peB^boolean^?ABoolean^??false??B
 * v~eBu^bp?[^???A0??B
 * v?peB^bp?[^OObject^??null??B<br>
 * ??A?entrynulln?B
 *
 * @param form ?NGXggpANVtH?[
 * @param entry Zbg?v?peB?lGg
 * @throws PropertyAccessException v?peBl?s??
 */
protected void resetValue(FormEx form, Entry<String, Object> entry) {
    if (log.isDebugEnabled()) {
        log.debug("resetValue(" + form + ", " + entry.getKey() + ") called.");
    }
    String propName = entry.getKey();
    try {
        Object value = entry.getValue();
        if (value == null) {
            return;
        }
        Class type = null;
        type = value.getClass();
        if (type != null) {
            // ^???B
            if (type == Boolean.TYPE || type == Boolean.class) {
                BeanUtil.setBeanProperty(form, propName, Boolean.FALSE);
            } else if (type == Byte.TYPE || type == Byte.class) {
                BeanUtil.setBeanProperty(form, propName, new Byte((byte) 0));
            } else if (type == Character.TYPE || type == Character.class) {
                BeanUtil.setBeanProperty(form, propName, new Character((char) 0));
            } else if (type == Double.TYPE || type == Double.class) {
                BeanUtil.setBeanProperty(form, propName, new Double(0.0));
            } else if (type == Float.TYPE || type == Float.class) {
                BeanUtil.setBeanProperty(form, propName, new Float((float) 0.0));
            } else if (type == Integer.TYPE || type == Integer.class) {
                BeanUtil.setBeanProperty(form, propName, new Integer(0));
            } else if (type == Long.TYPE || type == Long.class) {
                BeanUtil.setBeanProperty(form, propName, new Long(0));
            } else if (type == Short.TYPE || type == Short.class) {
                BeanUtil.setBeanProperty(form, propName, new Short((short) 0));
            } else {
                // v~eBu^?Abp?[^??null?
                BeanUtil.setBeanProperty(form, propName, null);
            }
        }
    } catch (PropertyAccessException e) {
        log.error("cannot access property " + form + "." + propName, e);
    }
}

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  .j  a v a2 s .c  o  m*/
        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:com.sun.socialsite.util.DebugBeanJsonConverter.java

@SuppressWarnings("boxing")
private <T> void callSetterWithValue(T pojo, Method method, JSONObject jsonObject, String fieldName)
        throws IllegalAccessException, InvocationTargetException, NoSuchFieldException, JSONException {

    log.debug("Calling setter [" + method.getName() + "]");

    Class<?> expectedType = method.getParameterTypes()[0];
    Object value = null;//  w w  w . j  a v  a2s .  c om

    if (!jsonObject.has(fieldName)) {
        // Skip
    } else if (expectedType.equals(List.class)) {
        ParameterizedType genericListType = (ParameterizedType) method.getGenericParameterTypes()[0];
        Type type = genericListType.getActualTypeArguments()[0];
        Class<?> rawType;
        Class<?> listElementClass;
        if (type instanceof ParameterizedType) {
            listElementClass = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0];
            rawType = (Class<?>) ((ParameterizedType) type).getRawType();
        } else {
            listElementClass = (Class<?>) type;
            rawType = listElementClass;
        }

        List<Object> list = Lists.newArrayList();
        JSONArray jsonArray = jsonObject.getJSONArray(fieldName);
        for (int i = 0; i < jsonArray.length(); i++) {
            if (org.apache.shindig.protocol.model.Enum.class.isAssignableFrom(rawType)) {
                list.add(convertEnum(listElementClass, jsonArray.getJSONObject(i)));
            } else {
                list.add(convertToObject(jsonArray.getString(i), listElementClass));
            }
        }

        value = list;

    } else if (expectedType.equals(Map.class)) {
        ParameterizedType genericListType = (ParameterizedType) method.getGenericParameterTypes()[0];
        Type[] types = genericListType.getActualTypeArguments();
        Class<?> valueClass = (Class<?>) types[1];

        // We only support keys being typed as Strings.
        // Nothing else really makes sense in json.
        Map<String, Object> map = Maps.newHashMap();
        JSONObject jsonMap = jsonObject.getJSONObject(fieldName);

        Iterator<?> keys = jsonMap.keys();
        while (keys.hasNext()) {
            String keyName = (String) keys.next();
            map.put(keyName, convertToObject(jsonMap.getString(keyName), valueClass));
        }

        value = map;

    } else if (org.apache.shindig.protocol.model.Enum.class.isAssignableFrom(expectedType)) {
        // TODO Need to stop using Enum as a class name :(
        value = convertEnum((Class<?>) ((ParameterizedType) method.getGenericParameterTypes()[0])
                .getActualTypeArguments()[0], jsonObject.getJSONObject(fieldName));
    } else if (expectedType.isEnum()) {
        if (jsonObject.has(fieldName)) {
            for (Object v : expectedType.getEnumConstants()) {
                if (v.toString().equals(jsonObject.getString(fieldName))) {
                    value = v;
                    break;
                }
            }
            if (value == null) {
                throw new IllegalArgumentException("No enum value  '" + jsonObject.getString(fieldName)
                        + "' in " + expectedType.getName());
            }
        }
    } else if (expectedType.equals(String.class)) {
        value = jsonObject.getString(fieldName);
    } else if (expectedType.equals(Date.class)) {
        // Use JODA ISO parsing for the conversion
        value = new DateTime(jsonObject.getString(fieldName)).toDate();
    } else if (expectedType.equals(Long.class) || expectedType.equals(Long.TYPE)) {
        value = jsonObject.getLong(fieldName);
    } else if (expectedType.equals(Integer.class) || expectedType.equals(Integer.TYPE)) {
        value = jsonObject.getInt(fieldName);
    } else if (expectedType.equals(Boolean.class) || expectedType.equals(Boolean.TYPE)) {
        value = jsonObject.getBoolean(fieldName);
    } else if (expectedType.equals(Float.class) || expectedType.equals(Float.TYPE)) {
        value = ((Double) jsonObject.getDouble(fieldName)).floatValue();
    } else if (expectedType.equals(Double.class) || expectedType.equals(Double.TYPE)) {
        value = jsonObject.getDouble(fieldName);
    } else {
        // Assume its an injected type
        value = convertToObject(jsonObject.getJSONObject(fieldName).toString(), expectedType);
    }

    if (value != null) {
        method.invoke(pojo, value);
    }
}

From source file:com.adobe.acs.commons.data.Spreadsheet.java

private Class getClassFromName(String typeStr) {
    switch (typeStr.toLowerCase()) {
    case "int":
    case "integer":
        return Integer.TYPE;
    case "long":
        return Long.TYPE;
    case "double":
    case "number":
        return Double.TYPE;
    case "date":
    case "calendar":
    case "cal":
    case "time":
        return Date.class;
    case "boolean":
    case "bool":
        return Boolean.TYPE;
    case "string":
    case "str":
    default:/*from   w ww  .  j av  a2 s .c om*/
        return String.class;
    }
}

From source file:org.jcommon.com.util.config.ConfigLoader.java

@SuppressWarnings("unchecked")
private static StringBuilder updateString(InputStream is, BaseConfigMBean config) throws FileNotFoundException {
    StringBuilder sb = new StringBuilder();
    if (is == null)
        throw new FileNotFoundException();
    try {//from w w w. j  av a 2 s  . c o m
        boolean empty = false;
        Document doc = null;
        try {
            doc = new SAXReader().read(is);
        } catch (Exception e) {
            empty = true;
            doc = DocumentHelper.createDocument();
        }

        Element root = doc.getRootElement();

        String element = null;
        Class<?> type = null;
        java.lang.reflect.Field[] fs = config.getClass().getDeclaredFields();
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n").append("<config>\n");
        for (java.lang.reflect.Field f : fs) {
            element = f.getName();
            if (getTextFromElement(root, element) == null && !empty)
                continue;
            Object value = null;
            type = f.getType();
            java.lang.reflect.Method m = getMethod(config.getClass(), "get" + element);
            if (m == null)
                m = getMethod(config.getClass(), "is" + element);
            if (m != null) {
                try {
                    value = m.invoke(config);
                    logger.info(element + ":" + value);
                } catch (Exception e) {
                    logger.warn(e);
                    continue;
                }
                if (String.class == type) {
                    String data = String.valueOf(value);
                    if (data.startsWith("{")) {
                        org.json.JSONObject jsonO = JsonUtils.getJSONObject(data);
                        if (jsonO != null) {
                            Iterator<String> it = jsonO.keys();
                            sb.append("   <" + element + " ");
                            for (; it != null && it.hasNext();) {
                                String k = it.next();
                                String v = jsonO.getString(k);
                                sb.append(k).append("=").append("\"" + v + "\" ");
                            }
                            sb.append("/>\n");
                            continue;
                        }
                    }
                    sb.append("   <" + element + ">").append(data).append("</" + element + ">\n");
                } else if ((java.lang.Integer.class == type || Integer.TYPE == type)
                        || (java.lang.Boolean.class == type || Boolean.TYPE == type)
                        || (java.lang.Long.class == type || Long.TYPE == type)
                        || (java.lang.Float.class == type || Float.TYPE == type)) {
                    sb.append("   <" + element + ">").append(String.valueOf(value))
                            .append("</" + element + ">\n");
                } else if (java.util.Collection.class.isAssignableFrom(type)) {
                    Collection<String> list = (Collection<String>) value;
                    for (String s : list) {
                        sb.append("   <" + element + ">").append(s).append("</" + element + ">\n");
                    }
                } else if (java.util.Map.class.isAssignableFrom(type)) {
                    Map<String, String> map = (Map<String, String>) value;
                    for (String s : map.keySet()) {
                        String v = map.get(s);
                        sb.append("   <" + element).append(" key=\"" + s + "\"").append(" value=\"" + v + "\"")
                                .append(" />\n");
                    }
                } else {
                    logger.info("not map Class:" + type);
                    continue;
                }
            } else
                logger.warn("can't find element:" + element);
        }
        sb.append("</config>");
        logger.info(String.format("Read config file:  %s", is));

    } catch (Throwable t) {
        //t.printStackTrace();
        logger.error("read config file error:" + is + "\n" + t.getMessage());
    }
    return sb;
}

From source file:org.apache.tapestry.param.ParameterManager.java

private IParameterConnector createConnector(IComponent component, String parameterName, IBinding binding,
        Class propertyType, Class requiredType) {
    // Could convert this code to use a Decorator, but then I'd need
    // some kind of factory for these parameter connectors.

    if (propertyType.equals(Boolean.TYPE))
        return new BooleanParameterConnector(component, parameterName, binding);

    if (propertyType.equals(Integer.TYPE))
        return new IntParameterConnector(component, parameterName, binding);

    if (propertyType.equals(Double.TYPE))
        return new DoubleParameterConnector(component, parameterName, binding);

    if (propertyType.equals(String.class))
        return new StringParameterConnector(component, parameterName, binding);

    // The default is for any kind of object type

    return new ObjectParameterConnector(component, parameterName, binding, requiredType);
}

From source file:com.haulmont.restapi.service.QueriesControllerManager.java

protected Object toObject(Class clazz, String value) throws ParseException {
    if (clazz.isArray()) {
        Class componentType = clazz.getComponentType();
        JsonParser jsonParser = new JsonParser();
        JsonArray jsonArray = jsonParser.parse(value).getAsJsonArray();
        List result = new ArrayList();
        for (JsonElement jsonElement : jsonArray) {
            String stringValue = (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString())
                    ? jsonElement.getAsJsonPrimitive().getAsString()
                    : jsonElement.toString();
            Object arrayElementValue = toObject(componentType, stringValue);
            result.add(arrayElementValue);
        }//from   w  w w  .j a  v a2  s  .  c o  m
        return result;
    }
    if (String.class == clazz)
        return value;
    if (Integer.class == clazz || Integer.TYPE == clazz || Byte.class == clazz || Byte.TYPE == clazz
            || Short.class == clazz || Short.TYPE == clazz)
        return Datatypes.getNN(Integer.class).parse(value);
    if (Date.class == clazz) {
        try {
            return Datatypes.getNN(Date.class).parse(value);
        } catch (ParseException e) {
            try {
                return Datatypes.getNN(java.sql.Date.class).parse(value);
            } catch (ParseException e1) {
                return Datatypes.getNN(Time.class).parse(value);
            }
        }
    }
    if (BigDecimal.class == clazz)
        return Datatypes.getNN(BigDecimal.class).parse(value);
    if (Boolean.class == clazz || Boolean.TYPE == clazz)
        return Datatypes.getNN(Boolean.class).parse(value);
    if (Long.class == clazz || Long.TYPE == clazz)
        return Datatypes.getNN(Long.class).parse(value);
    if (Double.class == clazz || Double.TYPE == clazz || Float.class == clazz || Float.TYPE == clazz)
        return Datatypes.getNN(Double.class).parse(value);
    if (UUID.class == clazz)
        return UUID.fromString(value);
    throw new IllegalArgumentException("Parameters of type " + clazz.getName() + " are not supported");
}