Example usage for java.lang Long TYPE

List of usage examples for java.lang Long TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type long .

Usage

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   www  . j  a  v a  2 s . c  om*/

    return typeMap;
}

From source file:org.kuali.rice.krad.data.jpa.Filter.java

/**
 * Coerces the {@code attributeValue} using the given {@code type}.
 *
 * @param type the type to use to coerce the value.
 * @param attributeName the attribute name of the field to coerce.
 * @param attributeValue the value to coerce.
 * @return the coerced value./*  w  w w  .ja  va2 s .  co  m*/
 */
private static Object coerceValue(Class<?> type, String attributeName, String attributeValue) {
    try {
        if (Character.TYPE.equals(type) || Character.class.isAssignableFrom(type)) {
            return Character.valueOf(attributeValue.charAt(0));
        } else if (Boolean.TYPE.equals(type) || Boolean.class.isAssignableFrom(type)) {
            return Boolean.valueOf(attributeValue);
        } else if (Short.TYPE.equals(type) || Short.class.isAssignableFrom(type)) {
            return Short.valueOf(attributeValue);
        } else if (Integer.TYPE.equals(type) || Integer.class.isAssignableFrom(type)) {
            return Integer.valueOf(attributeValue);
        } else if (Long.TYPE.equals(type) || Long.class.isAssignableFrom(type)) {
            return Long.valueOf(attributeValue);
        } else if (Double.TYPE.equals(type) || Double.class.isAssignableFrom(type)) {
            return Double.valueOf(attributeValue);
        } else if (Float.TYPE.equals(type) || Float.class.isAssignableFrom(type)) {
            return Float.valueOf(attributeValue);
        }
    } catch (NumberFormatException nfe) {
        LOG.error("Could not coerce the value " + attributeValue + " for the field " + attributeName, nfe);
    }

    return attributeValue;
}

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.xwtec.xwserver.util.json.JSONArray.java

/**
 * Creates a JSONArray.<br>// w ww .  j  a  va2 s  .c  o  m
 * Inspects the object type to call the correct JSONArray factory method.
 * Accepts JSON formatted strings, arrays, Collections and Enums.
 *
 * @param object
 * @throws JSONException if the object can not be converted to a proper
 *         JSONArray.
 */
public static JSONArray fromObject(Object object, JsonConfig jsonConfig) {
    if (object instanceof JSONString) {
        return _fromJSONString((JSONString) object, jsonConfig);
    } else if (object instanceof JSONArray) {
        return _fromJSONArray((JSONArray) object, jsonConfig);
    } else if (object instanceof Collection) {
        return _fromCollection((Collection) object, jsonConfig);
    } else if (object instanceof JSONTokener) {
        return _fromJSONTokener((JSONTokener) object, jsonConfig);
    } else if (object instanceof String) {
        return _fromString((String) object, jsonConfig);
    } else if (object != null && object.getClass().isArray()) {
        Class type = object.getClass().getComponentType();
        if (!type.isPrimitive()) {
            return _fromArray((Object[]) object, jsonConfig);
        } else {
            if (type == Boolean.TYPE) {
                return _fromArray((boolean[]) object, jsonConfig);
            } else if (type == Byte.TYPE) {
                return _fromArray((byte[]) object, jsonConfig);
            } else if (type == Short.TYPE) {
                return _fromArray((short[]) object, jsonConfig);
            } else if (type == Integer.TYPE) {
                return _fromArray((int[]) object, jsonConfig);
            } else if (type == Long.TYPE) {
                return _fromArray((long[]) object, jsonConfig);
            } else if (type == Float.TYPE) {
                return _fromArray((float[]) object, jsonConfig);
            } else if (type == Double.TYPE) {
                return _fromArray((double[]) object, jsonConfig);
            } else if (type == Character.TYPE) {
                return _fromArray((char[]) object, jsonConfig);
            } else {
                throw new JSONException("Unsupported type");
            }
        }
    } else if (JSONUtils.isBoolean(object) || JSONUtils.isFunction(object) || JSONUtils.isNumber(object)
            || JSONUtils.isNull(object) || JSONUtils.isString(object) || object instanceof JSON) {
        fireArrayStartEvent(jsonConfig);
        JSONArray jsonArray = new JSONArray().element(object, jsonConfig);
        fireElementAddedEvent(0, jsonArray.get(0), jsonConfig);
        fireArrayStartEvent(jsonConfig);
        return jsonArray;
    } else if (object instanceof Enum) {
        return _fromArray((Enum) object, jsonConfig);
    } else if (object instanceof Annotation || (object != null && object.getClass().isAnnotation())) {
        throw new JSONException("Unsupported type");
    } else if (JSONUtils.isObject(object)) {
        fireArrayStartEvent(jsonConfig);
        JSONArray jsonArray = new JSONArray().element(JSONObject.fromObject(object, jsonConfig));
        fireElementAddedEvent(0, jsonArray.get(0), jsonConfig);
        fireArrayStartEvent(jsonConfig);
        return jsonArray;
    } else {
        throw new JSONException("Unsupported type");
    }
}

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);
        }/* w w  w  .  j  a  v a  2 s .com*/
        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: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;
        }//from www.  j a v  a2s  .c o  m
        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:com.link_intersystems.lang.Conversions.java

/**
 * float to byte, short, char, int, or long
 *//*from  www  .ja va2  s .  c o  m*/
private static boolean isPrimitiveFloatNarrowing(Class<?> to) {
    boolean isNarrowing = isPrimitiveLongNarrowing(to);

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

    return isNarrowing;
}

From source file:ArrayUtils.java

public static long[] insert(final long[] array, final long element) {
    long[] newArray = (long[]) copyArrayGrow1(array, Long.TYPE);
    newArray[lastIndex(newArray)] = element;
    return newArray;
}

From source file:me.crime.loader.DataBaseLoader.java

private void saveData(String method, String data, Object obj) throws SAXException {
    Method getMethod = getMethod("get" + method, obj);
    Method setMethod = getMethod("set" + method, obj);

    try {//from w  w w  . j  a v  a  2 s. co  m

        Object args[] = new Object[1];
        if (getMethod.getGenericReturnType() == Integer.TYPE) {
            args[0] = new Integer(data);
        } else if (getMethod.getGenericReturnType() == String.class) {
            args[0] = data;
        } else if (getMethod.getGenericReturnType() == Double.TYPE) {
            args[0] = new Double(data);
        } else if (getMethod.getGenericReturnType() == Long.TYPE) {
            args[0] = new Long(data);
        } else if (getMethod.getGenericReturnType() == Calendar.class) {
            String[] dt = data.split(":");
            Calendar cal = Calendar.getInstance();

            cal.set(Calendar.YEAR, Integer.parseInt(dt[0]));
            cal.set(Calendar.MONTH, Integer.parseInt(dt[1]));
            cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dt[2]));
            cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dt[3]));
            cal.set(Calendar.MINUTE, Integer.parseInt(dt[4]));
            cal.set(Calendar.SECOND, Integer.parseInt(dt[5]));
            cal.set(Calendar.MILLISECOND, Integer.parseInt(dt[5]));

            if (cal.get(Calendar.YEAR) < 10) {
                cal.set(Calendar.YEAR, 2000 + cal.get(Calendar.YEAR));
            }

            args[0] = cal;

        }
        setMethod.invoke(obj, args);

    } catch (Exception e) {
        DataBaseLoader.log_.error("saveData: " + method, e);
        throw new SAXException("saveData:", e);
    }

}

From source file:org.evosuite.testcase.fm.MethodDescriptor.java

public Object executeMatcher(int i) throws IllegalArgumentException {
    if (i < 0 || i >= getNumberOfInputParameters()) {
        throw new IllegalArgumentException("Invalid index: " + i);
    }/*from   w w w .  j av  a2  s. co m*/

    Type[] types = method.getParameterTypes();
    Type type = types[i];

    try {
        if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
            return Mockito.anyInt();
        } else if (type.equals(Long.TYPE) || type.equals(Long.class)) {
            return Mockito.anyLong();
        } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
            return Mockito.anyBoolean();
        } else if (type.equals(Double.TYPE) || type.equals(Double.class)) {
            return Mockito.anyDouble();
        } else if (type.equals(Float.TYPE) || type.equals(Float.class)) {
            return Mockito.anyFloat();
        } else if (type.equals(Short.TYPE) || type.equals(Short.class)) {
            return Mockito.anyShort();
        } else if (type.equals(Character.TYPE) || type.equals(Character.class)) {
            return Mockito.anyChar();
        } else if (type.equals(String.class)) {
            return Mockito.anyString();
        } else {
            return Mockito.any(type.getClass());
        }
    } catch (Exception e) {
        logger.error("Failed to executed Mockito matcher n{} of type {} in {}.{}: {}", i, type, className,
                methodName, e.getMessage());
        throw new EvosuiteError(e);
    }
}