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:bboss.org.apache.velocity.runtime.resource.loader.URLResourceLoader.java

/**
 * @see bboss.org.apache.velocity.runtime.resource.loader.ResourceLoader#init(org.apache.commons.collections.ExtendedProperties)
 *///from   w  w  w  . j av  a2s .com
public void init(ExtendedProperties configuration) {
    log.trace("URLResourceLoader : initialization starting.");

    roots = configuration.getStringArray("root");
    if (log.isDebugEnabled()) {
        for (int i = 0; i < roots.length; i++) {
            log.debug("URLResourceLoader : adding root '" + roots[i] + "'");
        }
    }

    timeout = configuration.getInt("timeout", -1);
    if (timeout > 0) {
        try {
            Class[] types = new Class[] { Integer.TYPE };
            Method conn = URLConnection.class.getMethod("setConnectTimeout", types);
            Method read = URLConnection.class.getMethod("setReadTimeout", types);
            timeoutMethods = new Method[] { conn, read };
            log.debug("URLResourceLoader : timeout set to " + timeout);
        } catch (NoSuchMethodException nsme) {
            log.debug("URLResourceLoader : Java 1.5+ is required to customize timeout!", nsme);
            timeout = -1;
        }
    }

    // init the template paths map
    templateRoots = new HashMap();

    log.trace("URLResourceLoader : initialization complete.");
}

From source file:org.apache.hadoop.metrics2.lib.MethodMetric.java

static boolean isInt(Class<?> type) {
    boolean ret = type == Integer.TYPE || type == Integer.class;
    return ret;/*w  w  w  . ja v a  2s.  c  om*/
}

From source file:foundation.stack.datamill.configuration.impl.Classes.java

public static boolean isAssignable(Class<?> clazz, final Class<?> toClass) {
    if (toClass == null) {
        return false;
    }//w ww. j av  a2 s . c  o m

    if (clazz == null) {
        return !toClass.isPrimitive();
    }

    if (clazz.isPrimitive() && !toClass.isPrimitive()) {
        clazz = primitiveToWrapper(clazz);
        if (clazz == null) {
            return false;
        }
    }
    if (toClass.isPrimitive() && !clazz.isPrimitive()) {
        clazz = wrapperToPrimitive(clazz);
        if (clazz == null) {
            return false;
        }
    }

    if (clazz.equals(toClass)) {
        return true;
    }
    if (clazz.isPrimitive()) {
        if (!toClass.isPrimitive()) {
            return false;
        }
        if (Integer.TYPE.equals(clazz)) {
            return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass);
        }
        if (Long.TYPE.equals(clazz)) {
            return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass);
        }
        if (Boolean.TYPE.equals(clazz)) {
            return false;
        }
        if (Double.TYPE.equals(clazz)) {
            return false;
        }
        if (Float.TYPE.equals(clazz)) {
            return Double.TYPE.equals(toClass);
        }
        if (Character.TYPE.equals(clazz)) {
            return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass)
                    || Double.TYPE.equals(toClass);
        }
        if (Short.TYPE.equals(clazz)) {
            return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass)
                    || Double.TYPE.equals(toClass);
        }
        if (Byte.TYPE.equals(clazz)) {
            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(clazz);
}

From source file:com.dicksoft.ocr.xml.Parser.java

/**
 * Download and parse the specified data set.
 * // ww w . j  a  v a  2  s  . c o m
 * @param <T>
 * @param clazz
 *            the Class of the type to be parsed
 * @param elements
 *            the set of elements to add parsed data to
 * @throws NotParseableException
 *             if the contract of Parseable is breached
 */
public static <T extends Parseable> void parse(Class<T> clazz, Set<T> elements) throws NotParseableException {
    int numElements = 0;
    try {
        numElements = parseSize(
                (String) clazz.getMethod(Parseable.LIST_URL_METHOD, new Class[0]).invoke(null, new Object[0]));
        for (int i = 0; i < numElements; i++) {
            String xml = null;
            try {
                xml = HttpUtil.fetchText(
                        (String) clazz.getMethod(Parseable.ELEMENT_URL_METHOD, new Class[] { Integer.TYPE })
                                .invoke(null, new Object[] { i }));
            } catch (IOException e) {
                LOG.debug("Composer with ID " + i + "was not found.");
                continue;
            }
            elements.add(clazz.cast(
                    clazz.getMethod("parse", new Class[] { String.class }).invoke(null, new Object[] { xml })));
        }
    } catch (IllegalArgumentException e) {
        throw new NotParseableException(e);
    } catch (SecurityException e) {
        throw new NotParseableException(e);
    } catch (IllegalAccessException e) {
        throw new NotParseableException(e);
    } catch (InvocationTargetException e) {
        throw new NotParseableException(e);
    } catch (NoSuchMethodException e) {
        throw new NotParseableException(e);
    }
}

From source file:it.greenvulcano.gvesb.http.ProtocolFactory.java

/**
 *
 * @param objectClass/*from  w  w  w  .  jav a  2 s . c  o  m*/
 *        Object class to instantiate
 * @param node
 *        The configuration of constructor parameters.
 * @return
 */
private static Object createObjectUsingConstructor(Class<?> objectClass, Node node) throws Exception {
    NodeList paramList = XMLConfig.getNodeList(node, "constructor-param");
    Class<?>[] types = new Class[paramList.getLength()];
    Object[] params = new Object[types.length];

    for (int i = 0; i < types.length; ++i) {
        Node paramNode = paramList.item(i);
        String type = XMLConfig.get(paramNode, "@type");
        String value = XMLConfig.getDecrypted(paramNode, "@value");
        Class<?> cls = null;
        if (type.equals("byte")) {
            cls = Byte.TYPE;
        } else if (type.equals("boolean")) {
            cls = Boolean.TYPE;
        } else if (type.equals("char")) {
            cls = Character.TYPE;
        } else if (type.equals("double")) {
            cls = Double.TYPE;
        } else if (type.equals("float")) {
            cls = Float.TYPE;
        } else if (type.equals("int")) {
            cls = Integer.TYPE;
        } else if (type.equals("long")) {
            cls = Long.TYPE;
        } else if (type.equals("short")) {
            cls = Short.TYPE;
        } else if (type.equals("String")) {
            cls = String.class;
        }
        types[i] = cls;
        params[i] = cast(value, cls);
    }

    Constructor<?> constr = objectClass.getConstructor(types);
    return constr.newInstance(params);
}

From source file:org.apache.velocity.runtime.resource.loader.URLResourceLoader.java

/**
 * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#init(org.apache.commons.collections.ExtendedProperties)
 *///from  ww  w  . java2 s  .c  o m
public void init(ExtendedProperties configuration) {
    Logger.debug(this, "URLResourceLoader : initialization starting.");

    roots = configuration.getStringArray("root");
    if (Logger.isDebugEnabled(this.getClass())) {
        for (int i = 0; i < roots.length; i++) {
            Logger.debug(this, "URLResourceLoader : adding root '" + roots[i] + "'");
        }
    }

    timeout = configuration.getInt("timeout", -1);
    if (timeout > 0) {
        try {
            Class[] types = new Class[] { Integer.TYPE };
            Method conn = URLConnection.class.getMethod("setConnectTimeout", types);
            Method read = URLConnection.class.getMethod("setReadTimeout", types);
            timeoutMethods = new Method[] { conn, read };
            Logger.debug(this, "URLResourceLoader : timeout set to " + timeout);
        } catch (NoSuchMethodException nsme) {
            Logger.debug(this, "URLResourceLoader : Java 1.5+ is required to customize timeout!", nsme);
            timeout = -1;
        }
    }

    // init the template paths map
    templateRoots = new HashMap();

    Logger.debug(this, "URLResourceLoader : initialization complete.");
}

From source file:de.micromata.genome.util.bean.SoftCastPropertyUtilsBean.java

public Class<?> getWrappedClass(Class<?> target) {
    if (target.isPrimitive() == false) {
        return target;
    }//from w  w  w . j a  v a 2s  .  co  m
    if (target == Integer.TYPE) {
        return Integer.class;
    }
    if (target == Long.TYPE) {
        return Long.class;
    }
    if (target == Byte.TYPE) {
        return Byte.class;
    }
    if (target == Short.TYPE) {
        return Short.class;
    }
    if (target == Float.TYPE) {
        return Short.class;
    }
    if (target == Double.TYPE) {
        return Double.class;
    }
    if (target == Character.TYPE) {
        return Character.class;
    }
    if (target == Boolean.TYPE) {
        return Boolean.class;
    }
    throw new RuntimeException("Unmapped basic type: " + target);
}

From source file:com.nfwork.dbfound.json.JSONDynaBean.java

public Object get(String name) {
    Object value = dynaValues.get(name);
    if (value != null) {
        return value;
    }/*from   w ww.j a v  a 2  s.  com*/

    Class type = getDynaProperty(name).getType();
    if (type == null) {
        throw new NullPointerException("Unspecified property type for " + name);
    }
    if (!type.isPrimitive()) {
        return value;
    }

    if (type == Boolean.TYPE) {
        return Boolean.FALSE;
    } else if (type == Byte.TYPE) {
        return new Byte((byte) 0);
    } else if (type == Character.TYPE) {
        return new Character((char) 0);
    } else if (type == Short.TYPE) {
        return new Short((short) 0);
    } else if (type == Integer.TYPE) {
        return new Integer(0);
    } else if (type == Long.TYPE) {
        return new Long(0);
    } else if (type == Float.TYPE) {
        return new Float(0.0);
    } else if (type == Double.TYPE) {
        return new Double(0);
    }

    return null;
}

From source file:org.briljantframework.data.vector.VectorsTest.java

@Test
public void testInferType() throws Exception {
    assertEquals(VectorType.DOUBLE, VectorType.of(Double.class));
    assertEquals(VectorType.INT, VectorType.of(Integer.class));
    assertEquals(VectorType.LOGICAL, VectorType.of(Boolean.class));
    assertEquals(VectorType.LOGICAL, VectorType.of(Logical.class));
    assertEquals(VectorType.COMPLEX, VectorType.of(Complex.class));
    assertEquals(VectorType.STRING, VectorType.of(String.class));
    assertEquals(VectorType.DOUBLE, VectorType.of(Double.TYPE));
    assertEquals(VectorType.INT, VectorType.of(Integer.TYPE));
    assertEquals(VectorType.OBJECT, VectorType.of(null));
}

From source file:net.sf.qooxdoo.rpc.RemoteCallUtils.java

/**
 * Converts JSON types to "normal" java types.
 *
 * @param       obj                 the object to convert (must not be
 *                                  <code>null</code>, but can be
 *                                  <code>JSONObject.NULL</code>).
 * @param       targetType          the desired target type (must not be
 *                                  <code>null</code>).
 *
 * @return      the converted object./*from   w w  w  . jav a2 s . c o  m*/
 *
 * @exception   IllegalArgumentException    thrown if the desired
 *                                          conversion is not possible.
 */

public Object toJava(Object obj, Class targetType) {
    try {
        if (obj == JSONObject.NULL) {
            if (targetType == Integer.TYPE || targetType == Double.TYPE || targetType == Boolean.TYPE
                    || targetType == Long.TYPE || targetType == Float.TYPE) {
                // null does not work for primitive types
                throw new Exception();
            }
            return null;
        }
        if (obj instanceof JSONArray) {
            Class componentType;
            if (targetType == null || targetType == Object.class) {
                componentType = null;
            } else {
                componentType = targetType.getComponentType();
            }
            JSONArray jsonArray = (JSONArray) obj;
            int length = jsonArray.length();
            Object retVal = Array.newInstance((componentType == null ? Object.class : componentType), length);
            for (int i = 0; i < length; ++i) {
                Array.set(retVal, i, toJava(jsonArray.get(i), componentType));
            }
            return retVal;
        }
        if (obj instanceof JSONObject) {
            JSONObject jsonObject = (JSONObject) obj;
            JSONArray names = jsonObject.names();
            if (targetType == Map.class || targetType == HashMap.class || targetType == null
                    || targetType == Object.class) {
                HashMap retVal = new HashMap();
                if (names != null) {
                    int length = names.length();
                    String name;
                    for (int i = 0; i < length; ++i) {
                        name = names.getString(i);
                        retVal.put(name, toJava(jsonObject.get(name), null));
                    }
                }
                return retVal;
            }
            Object bean;
            String requestedTypeName = jsonObject.optString("class", null);
            if (requestedTypeName != null) {
                Class clazz = resolveClassHint(requestedTypeName, targetType);
                if (clazz == null || !targetType.isAssignableFrom(clazz)) {
                    throw new Exception();
                }
                bean = clazz.newInstance();
                // TODO: support constructor parameters
            } else {
                bean = targetType.newInstance();
            }
            if (names != null) {
                int length = names.length();
                String name;
                PropertyDescriptor desc;
                for (int i = 0; i < length; ++i) {
                    name = names.getString(i);
                    if (!"class".equals(name)) {
                        desc = PropertyUtils.getPropertyDescriptor(bean, name);
                        if (desc != null && desc.getWriteMethod() != null) {
                            PropertyUtils.setSimpleProperty(bean, name,
                                    toJava(jsonObject.get(name), desc.getPropertyType()));
                        }
                    }
                }
            }
            return bean;
        }
        if (targetType == null || targetType == Object.class) {
            return obj;
        }
        Class actualTargetType;
        Class sourceType = obj.getClass();
        if (targetType == Integer.TYPE) {
            actualTargetType = Integer.class;
        } else if (targetType == Boolean.TYPE) {
            actualTargetType = Boolean.class;
        } else if ((targetType == Double.TYPE || targetType == Double.class)
                && Number.class.isAssignableFrom(sourceType)) {
            return new Double(((Number) obj).doubleValue());
            // TODO: maybe return obj directly if it's a Double 
        } else if ((targetType == Float.TYPE || targetType == Float.class)
                && Number.class.isAssignableFrom(sourceType)) {
            return new Float(((Number) obj).floatValue());
        } else if ((targetType == Long.TYPE || targetType == Long.class)
                && Number.class.isAssignableFrom(sourceType)) {
            return new Long(((Number) obj).longValue());
        } else {
            actualTargetType = targetType;
        }
        if (!actualTargetType.isAssignableFrom(sourceType)) {
            throw new Exception();
        }
        return obj;
    } catch (IllegalArgumentException e) {
        throw e;
    } catch (Exception e) {
        throw new IllegalArgumentException("Cannot convert " + (obj == null ? null : obj.getClass().getName())
                + " to " + (targetType == null ? null : targetType.getName()));
    }
}