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:net.sf.ehcache.config.BeanHandler.java

/**
 * Converts a string to an object of a particular class.
 *///from  w  ww .ja v  a  2 s.  c om
private static Object convert(final Class toClass, final String value) throws Exception {
    if (value == null) {
        return null;
    }
    if (toClass.isInstance(value)) {
        return value;
    }
    if (toClass == Long.class || toClass == Long.TYPE) {
        return Long.decode(value);
    }
    if (toClass == Integer.class || toClass == Integer.TYPE) {
        return Integer.decode(value);
    }
    if (toClass == Boolean.class || toClass == Boolean.TYPE) {
        return Boolean.valueOf(value);
    }
    throw new Exception("Cannot convert attribute value to class " + toClass.getName());
}

From source file:com.hellofyc.base.widget.BaseWebView.java

private Class<?> getClassFromJsonObject(Object obj) {
    Class<?> cls = obj.getClass();

    // js??int boolean string?
    if (cls == Integer.class) {
        cls = Integer.TYPE;
    } else if (cls == Boolean.class) {
        cls = Boolean.TYPE;/*from  w  w w  .j a  v a 2s .c  o m*/
    } else {
        cls = String.class;
    }

    return cls;
}

From source file:com.cyclopsgroup.waterview.utils.TypeUtils.java

private static synchronized Map getTypeMap() {
    if (typeMap == null) {
        typeMap = new Hashtable();
        typeMap.put("boolean", Boolean.TYPE);
        typeMap.put("byte", Byte.TYPE);
        typeMap.put("char", Character.TYPE);
        typeMap.put("short", Short.TYPE);
        typeMap.put("int", Integer.TYPE);
        typeMap.put("long", Long.TYPE);
        typeMap.put("float", Float.TYPE);
        typeMap.put("double", Double.TYPE);
        typeMap.put("string", String.class);
        typeMap.put("date", Date.class);
    }//from   w  w w .java 2s.  co m

    return typeMap;
}

From source file:org.briljantframework.data.resolver.Resolve.java

private static Resolver<Integer> initializeIntegerResolver() {
    Resolver<Integer> resolver = new Resolver<>(Integer.class);
    resolver.put(Number.class, Number::intValue);
    resolver.put(Double.class, Number::intValue);
    resolver.put(Double.TYPE, Number::intValue);
    resolver.put(Float.class, Number::intValue);
    resolver.put(Float.TYPE, Number::intValue);
    resolver.put(Long.class, Number::intValue);
    resolver.put(Long.TYPE, Number::intValue);
    resolver.put(Integer.class, Number::intValue);
    resolver.put(Integer.TYPE, Number::intValue);
    resolver.put(Short.class, Number::intValue);
    resolver.put(Short.TYPE, Number::intValue);
    resolver.put(Byte.class, Number::intValue);
    resolver.put(Byte.TYPE, Number::intValue);
    resolver.put(String.class, s -> {
        try {// w  ww. j  av  a  2 s  .  c o m
            return NumberUtils.createNumber(s).intValue();
        } catch (Exception e) {
            return null;
        }
    });
    return resolver;
}

From source file:nz.ac.otago.psyanlab.common.model.util.ModelUtils.java

/**
 * Checks to see the given ored set of return types intersects with the
 * given method's return type./*from  ww  w  .  j  ava2 s  . co m*/
 * 
 * @param method Method to test.
 * @param returnTypes Ored set of return types.
 * @return True if intersection.
 */
public static boolean returnTypeIntersects(Method method, int returnTypes) {
    if ((returnTypes & Type.TYPE_BOOLEAN) != 0 && method.getReturnType().equals(Boolean.TYPE)) {
        return true;
    }
    if ((returnTypes & Type.TYPE_INTEGER) != 0 && method.getReturnType().equals(Integer.TYPE)) {
        return true;
    }
    if ((returnTypes & Type.TYPE_FLOAT) != 0 && method.getReturnType().equals(Float.TYPE)) {
        return true;
    }
    if ((returnTypes & Type.TYPE_STRING) != 0 && method.getReturnType().equals(String.class)) {
        return true;
    }
    if (returnTypes == 0 && method.getReturnType().equals(Void.TYPE)) {
        return true;
    }
    return false;
}

From source file:org.getobjects.appserver.publisher.GoJavaMethod.java

@SuppressWarnings("unchecked")
public Object coerceFormValueToArgumentType(final Object[] _v, final Class<?> _argType) {
    // FIXME: All this isn't nice. Cleanup and do it properly.
    // FIXME: Cache all the dynamic lookup
    if (_v == null)
        return null;

    if (_argType.isAssignableFrom(_v.getClass()))
        return _v;

    int vCount = _v.length;

    /* check whether the argument is some array-ish thing */

    if (_argType.isArray()) {
        final Class<?> itemType = _argType.getComponentType();
        final Object typedArray = java.lang.reflect.Array.newInstance(itemType, vCount);
        for (int i = 0; i < vCount; i++) {
            Object[] v = { _v[i] };
            Object sv = this.coerceFormValueToArgumentType(v, itemType);
            java.lang.reflect.Array.set(typedArray, i, sv);
        }/* www .  j a va  2  s  .  c  o m*/
        return typedArray;
    }

    if (_argType.isAssignableFrom(List.class))
        return UList.asList(_v);
    if (_argType.isAssignableFrom(Set.class))
        return new HashSet(UList.asList(_v));
    if (_argType.isAssignableFrom(Collection.class))
        return UList.asList(_v);

    /* empty assignment */

    if (vCount == 0) {
        if (!_argType.isPrimitive())
            return null; // all objects, return null

        if (_argType == Boolean.TYPE)
            return new Boolean(false);
        if (_argType == Integer.TYPE)
            return new Integer(-1);
        if (_argType == Double.TYPE)
            return new Double(-1.0);
        if (_argType == Float.TYPE)
            return new Float(-1.0);
        if (_argType == Short.TYPE)
            return new Integer(-1);
        if (_argType == Long.TYPE)
            return new Long(-1);
        log.error("Unexpected primitive arg type: " + _argType);
        return new GoInternalErrorException("Unexpected primitive type!");
    }

    /* check whether it is a directly assignable type */

    if (vCount == 1) {
        /* some type coercion. Can we reuse anything from KVC here? */
        // Note: Go supports various Zope form value formats, e.g. 'age:int'
        //       Check WOServletRequest for more.
        final Object v = _v[0];

        if (_argType.isAssignableFrom(v.getClass()))
            return v;

        /* some basic coercion */

        if (_argType.isPrimitive()) {
            if (_argType == Boolean.TYPE)
                return new Boolean(UObject.boolValue(v));

            if (_argType == Integer.TYPE || _argType == Short.TYPE)
                return new Integer(UObject.intValue(v));

            if (_argType == Long.TYPE)
                return new Long(UObject.intOrLongValue(v).longValue());
        } else if (_argType.isAssignableFrom(String.class))
            return v.toString();

        return v; // might crash
    }

    /* error out, return exception as value */

    log.error("Cannot convert form value to Java argument " + _argType + ": " + _v);
    return new GoInternalErrorException("Cannot convert form value to Java parameter");
}

From source file:org.apache.jackrabbit.core.persistence.bundle.Oracle9PersistenceManager.java

/**
 * Creates a temporary oracle.sql.BLOB instance via reflection and spools
 * the contents of the specified stream.
 *//*w w w . j  a v a  2  s.  co  m*/
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[] { connectionManager.getConnection(), Boolean.FALSE, duractionSessionConstant });
    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, null);
    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, null);
    return (Blob) blob;
}

From source file:com.medallia.spider.api.DynamicInputImpl.java

private static Object parseSingleValue(Class<?> rt, String v, AnnotatedElement anno,
        Map<Class<?>, InputArgParser<?>> inputArgParsers) {
    if (rt.isEnum()) {
        String vlow = v.toLowerCase();
        for (Enum e : rt.asSubclass(Enum.class).getEnumConstants()) {
            if (e.name().toLowerCase().equals(vlow))
                return e;
        }/*w  w  w. ja  va  2s  . c  om*/
        throw new AssertionError("Enum constant not found: " + v);
    } else if (rt == Integer.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Integer.valueOf(v) : null;
    } else if (rt == Integer.TYPE) {
        // primitive int must have a value
        return Integer.valueOf(v);
    } else if (rt == Long.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Long.valueOf(v) : null;
    } else if (rt == Long.TYPE) {
        // primitive long must have a value
        return Long.valueOf(v);
    } else if (rt == Double.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Double.valueOf(v) : null;
    } else if (rt == Double.TYPE) {
        // primitive double must have a value
        return Double.valueOf(v);
    } else if (rt == String.class) {
        return v;
    } else if (rt.isArray()) {
        Input.List ann = anno.getAnnotation(Input.List.class);
        if (ann == null)
            throw new AssertionError("Array type but no annotation (see " + Input.class + "): " + anno);
        String separator = ann.separator();
        String[] strVals = v.split(separator, -1);
        Class<?> arrayType = rt.getComponentType();
        Object a = Array.newInstance(arrayType, strVals.length);
        for (int i = 0; i < strVals.length; i++) {
            Array.set(a, i, parseSingleValue(arrayType, strVals[i], anno, inputArgParsers));
        }
        return a;
    } else if (inputArgParsers != null) {
        InputArgParser<?> argParser = inputArgParsers.get(rt);
        if (argParser != null) {
            return argParser.parse(v);
        }
    }
    throw new AssertionError("Unknown return type " + rt + " (val: " + v + ")");
}

From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java

private boolean supportedType(Class ret) {
    return ret == String.class || ret == Integer.class || ret == Integer.TYPE || ret == Long.class
            || ret == Long.TYPE || ret == java.io.File.class || ret == Boolean.class || ret == Boolean.TYPE;
}

From source file:com.link_intersystems.lang.Conversions.java

/**
 * long to byte, short, char, or int//from   w w  w.  j a  v  a2  s .  co m
 */
private static boolean isPrimitiveLongNarrowing(Class<?> to) {
    boolean isNarrowing = isPrimitiveIntegerNarrowing(to);

    isNarrowing |= isIdentity(to, Integer.TYPE);

    return isNarrowing;
}