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.quartz.jobs.ee.jmx.JMXInvokerJob.java

public void execute(JobExecutionContext context) throws JobExecutionException {
    try {/*from www.  j av  a 2s .co  m*/
        Object[] params = null;
        String[] types = null;
        String objName = null;
        String objMethod = null;

        JobDataMap jobDataMap = context.getMergedJobDataMap();

        String[] keys = jobDataMap.getKeys();
        for (int i = 0; i < keys.length; i++) {
            String value = jobDataMap.getString(keys[i]);
            if ("JMX_OBJECTNAME".equalsIgnoreCase(keys[i])) {
                objName = value;
            } else if ("JMX_METHOD".equalsIgnoreCase(keys[i])) {
                objMethod = value;
            } else if ("JMX_PARAMDEFS".equalsIgnoreCase(keys[i])) {
                String[] paramdefs = split(value, ",");
                params = new Object[paramdefs.length];
                types = new String[paramdefs.length];
                for (int k = 0; k < paramdefs.length; k++) {
                    String parts[] = split(paramdefs[k], ":");
                    if (parts.length < 2) {
                        throw new Exception(
                                "Invalid parameter definition: required parts missing " + paramdefs[k]);
                    }
                    switch (parts[0].charAt(0)) {
                    case 'i':
                        params[k] = new Integer(jobDataMap.getString(parts[1]));
                        types[k] = Integer.TYPE.getName();
                        break;
                    case 'I':
                        params[k] = new Integer(jobDataMap.getString(parts[1]));
                        types[k] = Integer.class.getName();
                        break;
                    case 'l':
                        params[k] = new Long(jobDataMap.getString(parts[1]));
                        types[k] = Long.TYPE.getName();
                        break;
                    case 'L':
                        params[k] = new Long(jobDataMap.getString(parts[1]));
                        types[k] = Long.class.getName();
                        break;
                    case 'f':
                        params[k] = new Float(jobDataMap.getString(parts[1]));
                        types[k] = Float.TYPE.getName();
                        break;
                    case 'F':
                        params[k] = new Float(jobDataMap.getString(parts[1]));
                        types[k] = Float.class.getName();
                        break;
                    case 'd':
                        params[k] = new Double(jobDataMap.getString(parts[1]));
                        types[k] = Double.TYPE.getName();
                        break;
                    case 'D':
                        params[k] = new Double(jobDataMap.getString(parts[1]));
                        types[k] = Double.class.getName();
                        break;
                    case 's':
                        params[k] = jobDataMap.getString(parts[1]);
                        types[k] = String.class.getName();
                        break;
                    case 'b':
                        params[k] = new Boolean(jobDataMap.getString(parts[1]));
                        types[k] = Boolean.TYPE.getName();
                        break;
                    case 'B':
                        params[k] = new Boolean(jobDataMap.getString(parts[1]));
                        types[k] = Boolean.class.getName();
                        break;
                    }
                }
            }
        }

        if (objName == null || objMethod == null) {
            throw new Exception("Required parameters missing");
        }

        context.setResult(invoke(objName, objMethod, params, types));
    } catch (Exception e) {
        String m = "Caught a " + e.getClass().getName() + " exception : " + e.getMessage();
        getLog().error(m, e);
        throw new JobExecutionException(m, e, false);
    }
}

From source file:io.openmessaging.rocketmq.utils.BeanUtils.java

public static void setProperties(Class<?> clazz, Object obj, String methodName, Object value)
        throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    Class<?> parameterClass = getMethodClass(clazz, methodName);
    Method setterMethod = clazz.getMethod(methodName, parameterClass);
    if (parameterClass == Boolean.TYPE) {
        setterMethod.invoke(obj, Boolean.valueOf(value.toString()));
    } else if (parameterClass == Integer.TYPE) {
        setterMethod.invoke(obj, Integer.valueOf(value.toString()));
    } else if (parameterClass == Double.TYPE) {
        setterMethod.invoke(obj, Double.valueOf(value.toString()));
    } else if (parameterClass == Float.TYPE) {
        setterMethod.invoke(obj, Float.valueOf(value.toString()));
    } else if (parameterClass == Long.TYPE) {
        setterMethod.invoke(obj, Long.valueOf(value.toString()));
    } else// w ww  .ja v  a 2s.co  m
        setterMethod.invoke(obj, value);
}

From source file:org.apache.pig.builtin.Invoker.java

private static Class<?> unPrimitivize(Class<?> klass) {
    if (klass.equals(Integer.TYPE)) {
        return Integer.class;
    }/*from  w ww  .ja  va  2  s  .c om*/
    if (klass.equals(Long.TYPE)) {
        return Long.class;
    } else if (klass.equals(Float.TYPE)) {
        return Float.class;
    } else if (klass.equals(Double.TYPE)) {
        return Double.class;
    } else {
        return klass;
    }
}

From source file:org.apache.click.util.RequestTypeConverter.java

/**
 * Return the converted value for the given value object and target type.
 *
 * @param value the value object to convert
 * @param toType the target class type to convert the value to
 * @return a converted value into the specified type
 *///from  w w  w  .  j  a  v  a 2 s  .c  om
protected Object convertValue(Object value, Class<?> toType) {
    Object result = null;

    if (value != null) {

        // If array -> array then convert components of array individually
        if (value.getClass().isArray() && toType.isArray()) {
            Class<?> componentType = toType.getComponentType();

            result = Array.newInstance(componentType, Array.getLength(value));

            for (int i = 0, icount = Array.getLength(value); i < icount; i++) {
                Array.set(result, i, convertValue(Array.get(value, i), componentType));
            }

        } else {
            if ((toType == Integer.class) || (toType == Integer.TYPE)) {
                result = Integer.valueOf((int) OgnlOps.longValue(value));

            } else if ((toType == Double.class) || (toType == Double.TYPE)) {
                result = new Double(OgnlOps.doubleValue(value));

            } else if ((toType == Boolean.class) || (toType == Boolean.TYPE)) {
                result = Boolean.valueOf(value.toString());

            } else if ((toType == Byte.class) || (toType == Byte.TYPE)) {
                result = Byte.valueOf((byte) OgnlOps.longValue(value));

            } else if ((toType == Character.class) || (toType == Character.TYPE)) {
                result = Character.valueOf((char) OgnlOps.longValue(value));

            } else if ((toType == Short.class) || (toType == Short.TYPE)) {
                result = Short.valueOf((short) OgnlOps.longValue(value));

            } else if ((toType == Long.class) || (toType == Long.TYPE)) {
                result = Long.valueOf(OgnlOps.longValue(value));

            } else if ((toType == Float.class) || (toType == Float.TYPE)) {
                result = new Float(OgnlOps.doubleValue(value));

            } else if (toType == BigInteger.class) {
                result = OgnlOps.bigIntValue(value);

            } else if (toType == BigDecimal.class) {
                result = bigDecValue(value);

            } else if (toType == String.class) {
                result = OgnlOps.stringValue(value);

            } else if (toType == java.util.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.util.Date(time);
                }

            } else if (toType == java.sql.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Date(time);
                }

            } else if (toType == java.sql.Time.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Time(time);
                }

            } else if (toType == java.sql.Timestamp.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Timestamp(time);
                }
            }
        }

    } else {
        if (toType.isPrimitive()) {
            result = OgnlRuntime.getPrimitiveDefaultValue(toType);
        }
    }
    return result;
}

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

@Test
public void testTo_convertToLong() throws Exception {
    assertEquals(10, (long) Convert.to(Long.class, 10));
    assertEquals(10, (long) Convert.to(Long.class, 10.0));
    assertEquals(10, (long) Convert.to(Long.class, 10.0f));
    assertEquals(10, (long) Convert.to(Long.class, 10l));
    assertEquals(10, (long) Convert.to(Long.class, (short) 10));
    assertEquals(10, (long) Convert.to(Long.class, (byte) 10));
    assertEquals(10, (long) Convert.to(Long.class, Complex.valueOf(10)));
    assertEquals(1, (long) Convert.to(Long.class, Logical.TRUE));
    assertEquals(1, (long) Convert.to(Long.class, true));

    assertEquals(10, (long) Convert.to(Long.TYPE, 10));
    assertEquals(10, (long) Convert.to(Long.TYPE, 10.0));
    assertEquals(10, (long) Convert.to(Long.TYPE, 10.0f));
    assertEquals(10, (long) Convert.to(Long.TYPE, 10l));
    assertEquals(10, (long) Convert.to(Long.TYPE, (short) 10));
    assertEquals(10, (long) Convert.to(Long.TYPE, (byte) 10));
    assertEquals(10, (long) Convert.to(Long.TYPE, Complex.valueOf(10)));
    assertEquals(1, (long) Convert.to(Long.TYPE, Logical.TRUE));
    assertEquals(1, (long) Convert.to(Long.TYPE, true));
}

From source file:org.apache.ode.il.DynamicService.java

@SuppressWarnings("unchecked")
private static Object convertFromOM(Class<?> clazz, OMElement elmt) {
    // Here comes the nasty code...
    if (elmt == null || elmt.getText().length() == 0 && !elmt.getChildElements().hasNext())
        return null;
    else if (clazz.equals(String.class)) {
        return elmt.getText();
    } else if (clazz.equals(Boolean.class) || clazz.equals(Boolean.TYPE)) {
        return (elmt.getText().equals("true") || elmt.getText().equals("yes")) ? Boolean.TRUE : Boolean.FALSE;
    } else if (clazz.equals(QName.class)) {
        // The getTextAsQName is buggy, it sometimes return the full text without extracting namespace
        return OMUtils.getTextAsQName(elmt);
    } else if (clazz.equals(ProcessInfoCustomizer.class)) {
        return new ProcessInfoCustomizer(elmt.getText());
    } else if (Node.class.isAssignableFrom(clazz)) {
        return OMUtils.toDOM(elmt.getFirstElement());
    } else if (clazz.equals(Long.TYPE) || clazz.equals(Long.class)) {
        return Long.parseLong(elmt.getText());
    } else if (clazz.equals(Integer.TYPE) || clazz.equals(Integer.class)) {
        return Integer.parseInt(elmt.getText());
    } else if (clazz.isArray()) {
        ArrayList<Object> alist = new ArrayList<Object>();
        Iterator<OMElement> children = elmt.getChildElements();
        Class<?> targetClazz = clazz.getComponentType();
        while (children.hasNext())
            alist.add(parseType(targetClazz, ((OMElement) children.next()).getText()));
        return alist.toArray((Object[]) Array.newInstance(targetClazz, alist.size()));
    } else if (XmlObject.class.isAssignableFrom(clazz)) {
        try {/*from w  w w.j  a  v  a2 s  .  c o m*/
            Class beanFactory = clazz.forName(clazz.getCanonicalName() + "$Factory");
            elmt.setNamespace(elmt.declareDefaultNamespace(""));
            elmt.setLocalName("xml-fragment");
            return beanFactory.getMethod("parse", XMLStreamReader.class).invoke(null,
                    elmt.getXMLStreamReaderWithoutCaching());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(
                    "Couldn't find class " + clazz.getCanonicalName() + ".Factory to instantiate xml bean", e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(
                    "Couldn't access class " + clazz.getCanonicalName() + ".Factory to instantiate xml bean",
                    e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException("Couldn't access xml bean parse method on class "
                    + clazz.getCanonicalName() + ".Factory " + "to instantiate xml bean", e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException("Couldn't find xml bean parse method on class "
                    + clazz.getCanonicalName() + ".Factory " + "to instantiate xml bean", e);
        }
    } else
        throw new RuntimeException(
                "Couldn't use element " + elmt + " to obtain a management method parameter.");
}

From source file:io.qdb.server.controller.JsonService.java

private ObjectMapper createMapper(boolean prettyPrint, boolean datesAsTimestamps, boolean borg) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
    mapper.configure(SerializationFeature.INDENT_OUTPUT, prettyPrint);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, datesAsTimestamps);

    SimpleModule module = new SimpleModule();
    module.addDeserializer(Date.class, dateDeserializer);
    module.addDeserializer(Integer.class, integerJsonDeserializer);
    module.addDeserializer(Integer.TYPE, integerJsonDeserializer);
    module.addDeserializer(Long.class, longJsonDeserializer);
    module.addDeserializer(Long.TYPE, longJsonDeserializer);
    if (!borg) {//  w w w .j  a va 2s .  c  om
        module.addSerializer(Integer.TYPE, integerSerializer);
        module.addSerializer(Integer.class, integerSerializer);
        module.addSerializer(Long.TYPE, longSerializer);
        module.addSerializer(Long.class, longSerializer);
    }
    if (!datesAsTimestamps)
        module.addSerializer(Date.class, new ISO8601DateSerializer());
    mapper.registerModule(module);

    return mapper;
}

From source file:org.trianacode.taskgraph.tool.ClassLoaders.java

public static Class forName(String className) throws ClassNotFoundException {
    className = getTextClassName(className);
    boolean isArray = false;
    int dims = 0;
    if (className.endsWith("[]")) {
        isArray = true;//from   w  ww .j  a  v  a2  s .  c  o m
        dims = className.substring(className.indexOf("[]"), className.length()).length() / 2;
        className = className.substring(0, className.indexOf("[]"));

    }
    Class cls;
    if (className.equals("boolean")) {
        cls = Boolean.TYPE;
    } else if (className.equals("char")) {
        cls = Character.TYPE;
    } else if (className.equals("byte")) {
        cls = Byte.TYPE;
    } else if (className.equals("short")) {
        cls = Short.TYPE;
    } else if (className.equals("int")) {
        cls = Integer.TYPE;
    } else if (className.equals("long")) {
        cls = Long.TYPE;
    } else if (className.equals("float")) {
        cls = Float.TYPE;
    } else if (className.equals("double")) {
        cls = Double.TYPE;
    } else if (className.equals("void")) {
        cls = void.class;
    } else {
        cls = loadClass(className);
    }
    if (isArray) {
        Object arr = Array.newInstance(cls, new int[dims]);
        cls = arr.getClass();
    }
    return cls;
}

From source file:org.apache.struts2.s1.DynaBeanPropertyAccessorTest.java

/**
 * Create and return a <code>DynaClass</code> instance for our test
 * <code>DynaBean</code>.//  w ww .ja  v a2s. co m
 */
protected DynaClass createDynaClass() {

    int intArray[] = new int[0];
    String stringArray[] = new String[0];

    DynaClass dynaClass = new BasicDynaClass("TestDynaClass", null, new DynaProperty[] {
            new DynaProperty("booleanProperty", Boolean.TYPE), new DynaProperty("booleanSecond", Boolean.TYPE),
            new DynaProperty("doubleProperty", Double.TYPE), new DynaProperty("floatProperty", Float.TYPE),
            new DynaProperty("intArray", intArray.getClass()),
            new DynaProperty("intIndexed", intArray.getClass()), new DynaProperty("intProperty", Integer.TYPE),
            new DynaProperty("listIndexed", List.class), new DynaProperty("longProperty", Long.TYPE),
            new DynaProperty("mappedProperty", Map.class), new DynaProperty("mappedIntProperty", Map.class),
            new DynaProperty("nullProperty", String.class), new DynaProperty("shortProperty", Short.TYPE),
            new DynaProperty("stringArray", stringArray.getClass()),
            new DynaProperty("stringIndexed", stringArray.getClass()),
            new DynaProperty("stringProperty", String.class), });
    return (dynaClass);

}

From source file:com.epam.catgenome.manager.externaldb.bindings.ExternalDBBindingTest.java

private Object createParam(Class type)
        throws IllegalAccessException, InvocationTargetException, InstantiationException {
    Object param;//  w  ww  .j av  a 2  s .  c o m
    if (type == String.class) {
        param = "test";
    } else if (type == Integer.class || type == Integer.TYPE) {
        param = RandomUtils.nextInt();
    } else if (type == Long.class || type == Long.TYPE) {
        param = RandomUtils.nextLong();
    } else if (type == Float.class || type == Float.TYPE) {
        param = RandomUtils.nextFloat();
    } else if (type == Double.class || type == Double.TYPE) {
        param = RandomUtils.nextDouble();
    } else if (type == Boolean.class || type == Boolean.TYPE) {
        param = RandomUtils.nextBoolean();
    } else if (type == BigInteger.class) {
        param = new BigInteger(TEST_BIGINTEGER);
    } else if (type == List.class) {
        param = new ArrayList<>();
    } else if (type == XMLGregorianCalendar.class) {
        try {
            param = DatatypeFactory.newInstance().newXMLGregorianCalendar();
        } catch (DatatypeConfigurationException e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    } else {
        Constructor[] constructors = type.getConstructors();
        param = constructors[0].newInstance();
    }

    return param;
}