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:org.thingsplode.synapse.serializers.jackson.adapters.ParameterWrapperDeserializer.java

@Override
public ParameterWrapper deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    JsonNode node = jp.readValueAsTree();
    if (node != null && node.size() > 0 && node.isContainerNode()) {
        ParameterWrapper pw = ParameterWrapper.create();
        ArrayNode paramsNode = (ArrayNode) node.get("params");
        Iterator<JsonNode> elemIterator = paramsNode.elements();
        while (elemIterator.hasNext()) {
            JsonNode currentNode = elemIterator.next();
            if (currentNode.getNodeType() == JsonNodeType.OBJECT) {
                try {
                    String paramid = ((ObjectNode) currentNode).get("paramid").asText();
                    String typeName = ((ObjectNode) currentNode).get("type").asText();
                    Class paramType = null;
                    if (null != typeName)
                        switch (typeName) {
                        case "long":
                            paramType = Long.TYPE;
                            break;
                        case "byte":
                            paramType = Byte.TYPE;
                            break;
                        case "short":
                            paramType = Short.TYPE;
                            break;
                        case "int":
                            paramType = Integer.TYPE;
                            break;
                        case "float":
                            paramType = Float.TYPE;
                            break;
                        case "double":
                            paramType = Double.TYPE;
                            break;
                        case "boolean":
                            paramType = Boolean.TYPE;
                            break;
                        case "char":
                            paramType = Character.TYPE;
                            break;
                        default:
                            paramType = Class.forName(typeName);
                            break;
                        }//w  w w.j a v  a  2s.  c om
                    Object parameterObject = jp.getCodec().treeToValue(currentNode.get("value"), paramType);
                    pw.add(paramid, paramType, parameterObject);
                } catch (ClassNotFoundException ex) {
                    throw new JsonParseException(jp, ex.getMessage());
                }
            }
        }
        return pw;
    } else {
        return null;
    }
}

From source file:com.sf.ddao.factory.param.ParameterHelper.java

public static void bind(PreparedStatement preparedStatement, int idx, Object param, Class<?> clazz,
        Context context) throws SQLException {
    if (clazz == Integer.class || clazz == Integer.TYPE) {
        preparedStatement.setInt(idx, (Integer) param);
    } else if (clazz == String.class) {
        preparedStatement.setString(idx, (String) param);
    } else if (clazz == Long.class || clazz == Long.TYPE) {
        preparedStatement.setLong(idx, (Long) param);
    } else if (clazz == Boolean.class || clazz == Boolean.TYPE) {
        preparedStatement.setBoolean(idx, (Boolean) param);
    } else if (BigInteger.class.isAssignableFrom(clazz)) {
        BigInteger bi = (BigInteger) param;
        preparedStatement.setBigDecimal(idx, new BigDecimal(bi));
    } else if (Timestamp.class.isAssignableFrom(clazz)) {
        preparedStatement.setTimestamp(idx, (Timestamp) param);
    } else if (Date.class.isAssignableFrom(clazz)) {
        if (!java.sql.Date.class.isAssignableFrom(clazz)) {
            param = new java.sql.Date(((Date) param).getTime());
        }/*from  ww  w  . j  ava2 s  .  c  o  m*/
        preparedStatement.setDate(idx, (java.sql.Date) param);
    } else if (BoundParameter.class.isAssignableFrom(clazz)) {
        ((BoundParameter) param).bindParam(preparedStatement, idx, context);
    } else {
        throw new SQLException("Unimplemented type mapping for " + clazz);
    }
}

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  ava 2s . c om

    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:it.greenvulcano.gvesb.http.ProtocolFactory.java

/**
 *
 * @param objectClass/*from w ww  .j a  va 2 s .c  om*/
 *        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:de.micromata.genome.util.bean.SoftCastPropertyUtilsBean.java

public Class<?> getWrappedClass(Class<?> target) {
    if (target.isPrimitive() == false) {
        return target;
    }/*from   w  w w  .java2 s .  c om*/
    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:org.apache.hadoop.metrics2.lib.MethodMetric.java

static boolean isLong(Class<?> type) {
    return type == Long.TYPE || type == Long.class;
}

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 w  w . j ava2s  . 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: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.  ja va2s . c  om
 *
 * @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()));
    }
}

From source file:com.google.api.server.spi.request.RestServletRequestParamReaderTest.java

@Before
public void setUp() throws Exception {
    endpointMethod = EndpointMethod.create(TestApi.class,
            TestApi.class.getMethod("test", Long.TYPE, List.class, SimpleDate.class, TestResource.class));
    request = new MockHttpServletRequest();
    ServiceContext serviceContext = ServiceContext.create();
    serializationConfig = new ApiSerializationConfig();
    TypeLoader typeLoader = new TypeLoader();
    ApiConfig config = (new ApiConfig.Factory()).create(serviceContext, typeLoader, TestApi.class);
    ApiConfigAnnotationReader annotationReader = new ApiConfigAnnotationReader();
    annotationReader.loadEndpointClass(serviceContext, TestApi.class, config);
    annotationReader.loadEndpointMethods(serviceContext, TestApi.class,
            config.getApiClassConfig().getMethods());
    methodConfig = config.getApiClassConfig().getMethods().get(endpointMethod);
}

From source file:org.apache.hadoop.yarn.factories.impl.pb.RpcClientFactoryPBImpl.java

public Object getClient(Class<?> protocol, long clientVersion, InetSocketAddress addr, Configuration conf) {

    Constructor<?> constructor = cache.get(protocol);
    if (constructor == null) {
        Class<?> pbClazz = null;
        try {/*from  ww w.j av a  2s.co m*/
            pbClazz = localConf.getClassByName(getPBImplClassName(protocol));
        } catch (ClassNotFoundException e) {
            throw new YarnRuntimeException("Failed to load class: [" + getPBImplClassName(protocol) + "]", e);
        }
        try {
            constructor = pbClazz.getConstructor(Long.TYPE, InetSocketAddress.class, Configuration.class);
            constructor.setAccessible(true);
            cache.putIfAbsent(protocol, constructor);
        } catch (NoSuchMethodException e) {
            throw new YarnRuntimeException("Could not find constructor with params: " + Long.TYPE + ", "
                    + InetSocketAddress.class + ", " + Configuration.class, e);
        }
    }
    try {
        Object retObject = constructor.newInstance(clientVersion, addr, conf);
        return retObject;
    } catch (InvocationTargetException e) {
        throw new YarnRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new YarnRuntimeException(e);
    } catch (InstantiationException e) {
        throw new YarnRuntimeException(e);
    }
}