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.twitter.elephantbird.pig.piggybank.Invoker.java

private static Class<?> stringToClass(String klass) throws FrontendException {
    if ("string".equalsIgnoreCase(klass)) {
        return String.class;
    } else if ("int".equalsIgnoreCase(klass)) {
        return Integer.TYPE;
    } else if ("double".equalsIgnoreCase(klass)) {
        return Double.TYPE;
    } else if ("float".equalsIgnoreCase(klass)) {
        return Float.TYPE;
    } else if ("long".equalsIgnoreCase(klass)) {
        return Long.TYPE;
    } else if ("double[]".equalsIgnoreCase(klass)) {
        return DOUBLE_ARRAY_CLASS;
    } else if ("int[]".equalsIgnoreCase(klass)) {
        return INT_ARRAY_CLASS;
    } else if ("long[]".equalsIgnoreCase(klass)) {
        return LONG_ARRAY_CLASS;
    } else if ("float[]".equalsIgnoreCase(klass)) {
        return FLOAT_ARRAY_CLASS;
    } else if ("string[]".equalsIgnoreCase(klass)) {
        return STRING_ARRAY_CLASS;
    } else {/*from ww  w  .j av a2s . c  om*/
        throw new FrontendException("unable to find matching class for " + klass);
    }

}

From source file:org.yccheok.jstock.gui.POIUtils.java

private static void handlePrimitive(Method method, Class<?> clazz) {
    if (clazz == Boolean.TYPE) {
        parameterTypeMap.put(Boolean.class, method);
    } else if (clazz == Character.TYPE) {
        parameterTypeMap.put(Character.class, method);
    } else if (clazz == Byte.TYPE) {
        parameterTypeMap.put(Byte.class, method);
    } else if (clazz == Short.TYPE) {
        parameterTypeMap.put(Short.class, method);
    } else if (clazz == Integer.TYPE) {
        parameterTypeMap.put(Integer.class, method);
    } else if (clazz == Long.TYPE) {
        parameterTypeMap.put(Long.class, method);
    } else if (clazz == Float.TYPE) {
        parameterTypeMap.put(Float.class, method);
    } else if (clazz == Double.TYPE) {
        parameterTypeMap.put(Double.class, method);
    } // ... and so on for the other six primitive types (void doesn't matter)
}

From source file:com.github.dozermapper.core.converters.DateConverter.java

public Object convert(Class destClass, Object srcObj) {
    final Class srcFieldClass = srcObj.getClass();

    long time;//w ww. ja  va 2s  .  c o m
    int nanos = 0;
    if (Calendar.class.isAssignableFrom(srcFieldClass)) {
        Calendar inVal = (Calendar) srcObj;
        time = inVal.getTime().getTime();
    } else if (Timestamp.class.isAssignableFrom(srcFieldClass)) {
        Timestamp timestamp = (Timestamp) srcObj;
        time = timestamp.getTime();
        nanos = timestamp.getNanos();
    } else if (java.util.Date.class.isAssignableFrom(srcFieldClass)) {
        time = ((java.util.Date) srcObj).getTime();
    } else if (XMLGregorianCalendar.class.isAssignableFrom(srcFieldClass)) {
        time = ((XMLGregorianCalendar) srcObj).toGregorianCalendar().getTimeInMillis();
    } else if (dateFormat != null && String.class.isAssignableFrom(srcObj.getClass())) {
        try {
            if ("".equals(srcObj)) {
                return null;
            }
            time = dateFormat.parse((String) srcObj).getTime();
        } catch (ParseException e) {
            throw new ConversionException("Unable to parse source object using specified date format", e);
        }
        // Default conversion
    } else {
        try {
            time = Long.parseLong(srcObj.toString());
        } catch (NumberFormatException e) {
            throw new ConversionException("Unable to determine time in millis of source object", e);
        }
    }

    try {
        if (Calendar.class.isAssignableFrom(destClass)) {
            Constructor constructor = destClass.getConstructor();
            Calendar result = (Calendar) constructor.newInstance();
            result.setTimeInMillis(time);
            return result;
        }

        if (dateFormat != null && String.class.isAssignableFrom(destClass)) {
            return dateFormat.format(new java.util.Date(time));
        }

        Constructor constructor = destClass.getConstructor(Long.TYPE);
        Object result = constructor.newInstance(time);
        if (nanos != 0 && (Timestamp.class.isAssignableFrom(destClass))) {
            ((Timestamp) result).setNanos(nanos);
        }
        return result;
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}

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

private String initMatchers(GenericMethod method, GenericClass retvalType) {

    String matchers = "";
    Type[] types = method.getParameterTypes();
    List<GenericClass> parameterClasses = method.getParameterClasses();
    for (int i = 0; i < types.length; i++) {
        if (i > 0) {
            matchers += " , ";
        }// w w  w  .  j  a  v  a 2s  . c  o m

        Type type = types[i];
        GenericClass genericParameter = parameterClasses.get(i);
        if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
            matchers += "anyInt()";
        } else if (type.equals(Long.TYPE) || type.equals(Long.class)) {
            matchers += "anyLong()";
        } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
            matchers += "anyBoolean()";
        } else if (type.equals(Double.TYPE) || type.equals(Double.class)) {
            matchers += "anyDouble()";
        } else if (type.equals(Float.TYPE) || type.equals(Float.class)) {
            matchers += "anyFloat()";
        } else if (type.equals(Short.TYPE) || type.equals(Short.class)) {
            matchers += "anyShort()";
        } else if (type.equals(Character.TYPE) || type.equals(Character.class)) {
            matchers += "anyChar()";
        } else if (type.equals(String.class)) {
            matchers += "anyString()";
        } else {
            if (type.getTypeName().equals(Object.class.getName())) {
                /*
                Ideally here we should use retvalType to understand if the target class
                is using generics and if this method parameters would need to be handled
                accordingly. However, doing it does not seem so trivial...
                so a current workaround is that, when a method takes an Object as input (which is
                that would happen in case of Generics T), we use the undetermined "any()"
                 */
                matchers += "any()";
            } else {
                if (type instanceof Class) {
                    matchers += "any(" + ((Class) type).getCanonicalName() + ".class)";
                } else {
                    //what to do here? is it even possible?
                    matchers += "any(" + genericParameter.getRawClass().getCanonicalName() + ".class)";
                    // matchers += "any(" + type.getTypeName() + ".class)";
                }
            }
        }
    }

    return matchers;
}

From source file:com.flipkart.polyguice.config.ApacheCommonsConfigProvider.java

@Override
public Object getValue(String path, Class<?> type) {
    if (!rootConfig.containsKey(path)) {
        return null;
    }//  ww w.ja  va 2s.  co  m
    if (type.equals(Byte.TYPE) || type.equals(Byte.class)) {
        return rootConfig.getByte(path, null);
    } else if (type.equals(Short.TYPE) || type.equals(Short.class)) {
        return rootConfig.getShort(path, null);
    } else if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
        return rootConfig.getInteger(path, null);
    } else if (type.equals(Long.TYPE) || type.equals(Long.class)) {
        return rootConfig.getLong(path, null);
    } else if (type.equals(Float.TYPE) || type.equals(Float.class)) {
        return rootConfig.getFloat(path, null);
    } else if (type.equals(Double.TYPE) || type.equals(Double.class)) {
        return rootConfig.getDouble(path, null);
    } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
        return rootConfig.getBoolean(path, null);
    } else if (type.equals(String.class)) {
        return rootConfig.getString(path);
    } else if (type.equals(BigInteger.class)) {
        return rootConfig.getBigInteger(path);
    } else if (type.equals(BigDecimal.class)) {
        return rootConfig.getBigDecimal(path);
    } else if (type.equals(Properties.class)) {
        return rootConfig.getProperties(path);
    } else if (type.equals(String[].class)) {
        return rootConfig.getStringArray(path);
    } else if (type.equals(TimeInterval.class)) {
        String interval = rootConfig.getString(path);
        if (interval == null) {
            return null;
        }
        return new TimeInterval(interval);
    }
    return null;
}

From source file:org.openflexo.antar.binding.TypeUtils.java

public static Class toPrimitive(Class<?> aClass) {
    if (isDouble(aClass)) {
        return Double.TYPE;
    }// w  w  w .  java2  s.co  m
    if (isFloat(aClass)) {
        return Float.TYPE;
    }
    if (isLong(aClass)) {
        return Long.TYPE;
    }
    if (isInteger(aClass)) {
        return Integer.TYPE;
    }
    if (isShort(aClass)) {
        return Short.TYPE;
    }
    if (isByte(aClass)) {
        return Byte.TYPE;
    }
    if (isBoolean(aClass)) {
        return Boolean.TYPE;
    }
    if (isChar(aClass)) {
        return Character.TYPE;
    }
    return aClass;
}

From source file:org.briljantframework.data.Na.java

/**
 * Returns the {@code NA} value for the class {@code T}. For reference types (excluding
 * {@link Complex} and {@link Logical}) {@code NA} is represented as {@code null}, but for
 * primitive types a special convention is used.
 *
 * <ul>/*from   w  w w. j a v  a  2 s. c om*/
 * <li>{@code double}: {@link Na#DOUBLE}</li>
 * <li>{@code int}: {@link Na#INT}</li>
 * <li>{@code long}: {@link Long#MAX_VALUE}</li>
 * <li>{@link Logical}: {@link Logical#NA}</li>
 * <li>{@link Complex}: {@link Na#COMPLEX}</li>
 * </ul>
 *
 * @param cls the class
 * @param <T> the type of {@code cls}
 * @return a {@code NA} value of type {@code T}
 */
@SuppressWarnings("unchecked")
public static <T> T of(Class<T> cls) {
    if (cls == null) {
        return null;
    } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) {
        return (T) BOXED_DOUBLE;
    } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) {
        return (T) BOXED_FLOAT;
    } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) {
        return (T) BOXED_LONG;
    } else if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) {
        return (T) BOXED_INT;
    } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) {
        return (T) BOXED_SHORT;
    } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) {
        return (T) BOXED_BYTE;
    } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) {
        return (T) BOXED_CHAR;
    } else if (Logical.class.equals(cls)) {
        return (T) Logical.NA;
    } else if (Complex.class.equals(cls)) {
        return (T) COMPLEX;
    } else {
        return null;
    }
}

From source file:demo.config.PropertyConverter.java

/**
 * Converts the specified value to the target class. If the class is a
 * primitive type (Integer.TYPE, Boolean.TYPE, etc) the value returned will
 * use the wrapper type (Integer.class, Boolean.class, etc).
 * //from   ww w.  j  a va 2  s  . c  o m
 * @param cls
 *            the target class of the converted value
 * @param value
 *            the value to convert
 * @param params
 *            optional parameters used for the conversion
 * @return the converted value
 * @throws ConversionException
 *             if the value is not compatible with the requested type
 * 
 * @since 1.5
 */
static Object to(Class<?> cls, Object value, Object[] params) throws ConversionException {
    if (cls.isInstance(value)) {
        return value; // no conversion needed
    }

    if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) {
        return toBoolean(value);
    } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) {
        return toCharacter(value);
    } else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) {
        if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) {
            return toInteger(value);
        } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) {
            return toLong(value);
        } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) {
            return toByte(value);
        } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) {
            return toShort(value);
        } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) {
            return toFloat(value);
        } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) {
            return toDouble(value);
        } else if (BigInteger.class.equals(cls)) {
            return toBigInteger(value);
        } else if (BigDecimal.class.equals(cls)) {
            return toBigDecimal(value);
        }
    } else if (Date.class.equals(cls)) {
        return toDate(value, (String) params[0]);
    } else if (Calendar.class.equals(cls)) {
        return toCalendar(value, (String) params[0]);
    } else if (URL.class.equals(cls)) {
        return toURL(value);
    } else if (Locale.class.equals(cls)) {
        return toLocale(value);
    } else if (isEnum(cls)) {
        return convertToEnum(cls, value);
    } else if (Color.class.equals(cls)) {
        return toColor(value);
    } else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME)) {
        return toInternetAddress(value);
    } else if (InetAddress.class.isAssignableFrom(cls)) {
        return toInetAddress(value);
    }

    throw new ConversionException("The value '" + value + "' (" + value.getClass() + ")"
            + " can't be converted to a " + cls.getName() + " object");
}

From source file:com.github.jknack.handlebars.helper.MethodHelper.java

/**
 * Wrap (if possible) a primitive type to their wrapper.
 *
 * @param type The candidate type.// w w  w  .j  a  v  a  2  s  .  c o  m
 * @return A wrapper for the primitive type or the original type.
 */
private static Class<?> wrap(final Class<?> type) {
    if (type.isPrimitive()) {
        if (type == Integer.TYPE) {
            return Integer.class;
        } else if (type == Boolean.TYPE) {
            return Boolean.class;
        } else if (type == Character.TYPE) {
            return Character.class;
        } else if (type == Double.TYPE) {
            return Double.class;
        } else if (type == Long.TYPE) {
            return Long.class;
        } else if (type == Float.TYPE) {
            return Float.class;
        } else if (type == Short.TYPE) {
            return Short.class;
        } else if (type == Byte.TYPE) {
            return Byte.class;
        }
    }
    return type;
}

From source file:com.l2jfree.config.L2Properties.java

@SuppressWarnings("unchecked")
public Object getProperty(Class<?> expectedType, ConfigProperty configProperty) {
    final String name = configProperty.name();
    final String defaultValue = configProperty.value();

    if (expectedType == Boolean.class || expectedType == Boolean.TYPE) {
        return getBool(name, defaultValue);
    } else if (expectedType == Long.class || expectedType == Long.TYPE) {
        return getLong(name, defaultValue);
    } else if (expectedType == Integer.class || expectedType == Integer.TYPE) {
        return getInteger(name, defaultValue);
    } else if (expectedType == Short.class || expectedType == Short.TYPE) {
        return getShort(name, defaultValue);
    } else if (expectedType == Byte.class || expectedType == Byte.TYPE) {
        return getByte(name, defaultValue);
    } else if (expectedType == Double.class || expectedType == Double.TYPE) {
        return getDouble(name, defaultValue);
    } else if (expectedType == Float.class || expectedType == Float.TYPE) {
        return getFloat(name, defaultValue);
    } else if (expectedType == String.class) {
        return getString(name, defaultValue);
    } else if (expectedType.isEnum()) {
        return getEnum(name, (Class<? extends Enum>) expectedType, defaultValue);
    } else {/*from  w w  w  .jav a2  s .  c o m*/
        throw new IllegalStateException();
    }
}