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.link_intersystems.lang.Conversions.java

/**
 * <em>java language specification - 5.1.2 Widening Primitive Conversion</em>
 * ./*from  w w w .  j  a v  a2 s.  c  o  m*/
 *
 * <code>
 * <blockquote>The following 19 specific conversions on primitive types
 *  are called the widening primitive conversions:
 * <ul>
 * <li>byte to short, int, long, float, or double</li>
 * <li>short to int, long, float, or double</li>
 * <li>char to int, long, float, or double</li>
 * <li>int to long, float, or double</li>
 * <li>long to float or double</li>
 * <li>float to double</li>
 * </blockquote>
 * </code>
 *
 * @param from
 *            the base type
 * @param to
 *            the widening type
 * @return true if from to to is a primitive widening.
 * @since 1.0.0.0
 */
public static boolean isPrimitiveWidening(Class<?> from, Class<?> to) {
    Assert.isTrue(Primitives.isPrimitive(from), PARAMETER_MUST_BE_A_PRIMITIVE, "form");
    Assert.isTrue(Primitives.isPrimitive(to), PARAMETER_MUST_BE_A_PRIMITIVE, "to");

    boolean isPrimitiveWidening = false;

    if (isIdentity(from, Byte.TYPE)) {
        isPrimitiveWidening = isPrimitiveByteWidening(to);
    } else if (isIdentity(from, Short.TYPE)) {
        isPrimitiveWidening = isPrimitiveShortWidening(to);
    } else if (isIdentity(from, Character.TYPE)) {
        isPrimitiveWidening = isPrimitiveCharacterWidening(to);
    } else if (isIdentity(from, Integer.TYPE)) {
        isPrimitiveWidening = isPrimitiveIntegerWidening(to);
    } else if (isIdentity(from, Long.TYPE)) {
        isPrimitiveWidening = isPrimitiveLongWidening(to);
    } else if (isIdentity(from, Float.TYPE)) {
        isPrimitiveWidening = isPrimitiveFloatWidening(to);
    }

    /*
     * must be a double - no widening available
     */
    return isPrimitiveWidening;
}

From source file:stroom.util.AbstractCommandLineTool.java

private Object getAsType(final PropertyDescriptor descriptor) {
    final Class<?> propertyClass = descriptor.getPropertyType();
    if (propertyClass.equals(String.class)) {
        return map.get(descriptor.getName());
    }/*  ww  w  .jav a  2s. c o  m*/
    if (propertyClass.equals(Boolean.class) || propertyClass.equals(Boolean.TYPE)) {
        return Boolean.parseBoolean(map.get(descriptor.getName()));
    }
    if (propertyClass.equals(Integer.class) || propertyClass.equals(Integer.TYPE)) {
        return Integer.parseInt(map.get(descriptor.getName()));
    }
    if (propertyClass.equals(Long.class) || propertyClass.equals(Long.TYPE)) {
        return Long.parseLong(map.get(descriptor.getName()));
    }
    throw new RuntimeException(
            "AbstractCommandLineTool does not know about properties of type " + propertyClass);
}

From source file:org.primeframework.mvc.parameter.convert.converters.NumberConverterTest.java

/**
 * Test the conversion from Strings./*from w ww  . j  a v a 2s . c om*/
 */
@Test
public void fromStrings() {
    GlobalConverter converter = new NumberConverter(new MockConfiguration());
    Byte bw = (Byte) converter.convertFromStrings(Byte.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(bw);

    Short sw = (Short) converter.convertFromStrings(Short.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(sw);

    Integer iw = (Integer) converter.convertFromStrings(Integer.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(iw);

    Long lw = (Long) converter.convertFromStrings(Long.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(lw);

    Float fw = (Float) converter.convertFromStrings(Float.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(fw);

    Double dw = (Double) converter.convertFromStrings(Double.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(dw);

    byte b = (Byte) converter.convertFromStrings(Byte.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(b, 0);

    short s = (Short) converter.convertFromStrings(Short.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(s, 0);

    int i = (Integer) converter.convertFromStrings(Integer.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(i, 0);

    long l = (Long) converter.convertFromStrings(Long.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(l, 0);

    float f = (Float) converter.convertFromStrings(Float.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(f, 0, 0);

    double d = (Double) converter.convertFromStrings(Double.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(d, 0, 0);

    bw = (Byte) converter.convertFromStrings(Byte.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals((byte) bw, 1);

    sw = (Short) converter.convertFromStrings(Short.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals((short) sw, 1);

    iw = (Integer) converter.convertFromStrings(Integer.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals((int) iw, 1);

    lw = (Long) converter.convertFromStrings(Long.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals((long) lw, 1l);

    fw = (Float) converter.convertFromStrings(Float.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals(1f, fw, 0);

    dw = (Double) converter.convertFromStrings(Double.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals(1d, dw, 0);

    bw = (Byte) converter.convertFromStrings(Byte.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(bw);

    sw = (Short) converter.convertFromStrings(Short.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(sw);

    iw = (Integer) converter.convertFromStrings(Integer.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(iw);

    lw = (Long) converter.convertFromStrings(Long.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(lw);

    fw = (Float) converter.convertFromStrings(Float.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(fw);

    dw = (Double) converter.convertFromStrings(Double.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(dw);

    b = (Byte) converter.convertFromStrings(Byte.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(b, 0);

    s = (Short) converter.convertFromStrings(Short.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(s, 0);

    i = (Integer) converter.convertFromStrings(Integer.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(i, 0);

    l = (Long) converter.convertFromStrings(Long.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(l, 0);

    f = (Float) converter.convertFromStrings(Float.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(0, f, 0);

    d = (Double) converter.convertFromStrings(Double.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(d, 0, 0);

    try {
        converter.convertFromStrings(Byte.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }

    try {
        converter.convertFromStrings(Short.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }

    try {
        converter.convertFromStrings(Integer.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }

    try {
        converter.convertFromStrings(Long.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }

    try {
        converter.convertFromStrings(Float.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }

    try {
        converter.convertFromStrings(Double.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }
}

From source file:org.kuali.rice.krad.util.DataTypeUtil.java

/**
 * Determines if the given class is enough like a "long" to store values of it as a SearchableAttributeLongValue
 * @param type the class to determine the type of
 * @return true if it is like a "long", false otherwise
 *///from  w  w w  .  j  a  va2  s .co  m
public static boolean isIntsy(Class<?> type) {
    return java.lang.Integer.class.isAssignableFrom(type) || java.lang.Long.class.isAssignableFrom(type)
            || java.lang.Short.class.isAssignableFrom(type) || java.lang.Byte.class.isAssignableFrom(type)
            || java.math.BigInteger.class.isAssignableFrom(type) || type.equals(Integer.TYPE)
            || type.equals(Long.TYPE) || type.equals(Short.TYPE) || type.equals(Byte.TYPE);
}

From source file:ClassUtils.java

/**
 * Helper for invoking an instance method that takes a single parameter.
 * This method also handles parameters of primitive type.
 * /*from  www  .j  av a 2  s.c  o m*/
 * @param cl
 *            The class that the instance belongs to
 * @param instance
 *            The object on which we will invoke the method
 * @param methodName
 *            The method name
 * @param param
 *            The parameter
 * @throws Throwable
 */
public static Object invokeMethod(Class cl, Object instance, String methodName, Object param) throws Throwable {
    Class paramClass;
    if (param instanceof Integer)
        paramClass = Integer.TYPE;
    else if (param instanceof Long)
        paramClass = Long.TYPE;
    else if (param instanceof Short)
        paramClass = Short.TYPE;
    else if (param instanceof Boolean)
        paramClass = Boolean.TYPE;
    else if (param instanceof Double)
        paramClass = Double.TYPE;
    else if (param instanceof Float)
        paramClass = Float.TYPE;
    else if (param instanceof Character)
        paramClass = Character.TYPE;
    else if (param instanceof Byte)
        paramClass = Byte.TYPE;
    else
        paramClass = param.getClass();
    Method method = cl.getMethod(methodName, new Class[] { paramClass });
    try {
        return method.invoke(instance, new Object[] { param });
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
}

From source file:org.kordamp.ezmorph.primitive.LongMorpher.java

public Class<?> morphsTo() {
    return Long.TYPE;
}

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

@SuppressWarnings("unchecked")
private static <T> T convertNumber(Class<T> cls, Number num) {
    if (cls.equals(Double.class) || cls.equals(Double.TYPE)) {
        return (T) (Double) num.doubleValue();
    } else if (cls.equals(Float.class) || cls.equals(Float.TYPE)) {
        return (T) (Float) num.floatValue();
    } else if (cls.equals(Long.class) || cls.equals(Long.TYPE)) {
        return (T) (Long) num.longValue();
    } else if (cls.equals(Integer.class) || cls.equals(Integer.TYPE)) {
        return (T) (Integer) num.intValue();
    } else if (cls.equals(Short.class) || cls.equals(Short.TYPE)) {
        return (T) (Short) num.shortValue();
    } else if (cls.equals(Byte.class) || cls.equals(Byte.TYPE)) {
        return (T) (Byte) num.byteValue();
    } else if (Complex.class.equals(cls)) {
        return cls.cast(Complex.valueOf(num.doubleValue()));
    } else if (Logical.class.equals(cls)) {
        return cls.cast(num.intValue() == 1 ? Logical.TRUE : Logical.FALSE);
    } else if (Boolean.class.equals(cls)) {
        return cls.cast(num.intValue() == 1);
    } else {/*www.  ja  va  2 s .  co  m*/
        return Na.of(cls);
    }
}

From source file:com.browseengine.bobo.serialize.JSONSerializer.java

private static void loadObject(Object retObj, Field f, JSONObject jsonObj) throws JSONSerializationException {
    String key = f.getName();/*from w ww  . j  a  va2s. c  o m*/
    Class type = f.getType();
    try {
        if (type.isPrimitive()) {
            if (type == Integer.TYPE) {
                f.setInt(retObj, jsonObj.getInt(key));
            } else if (type == Long.TYPE) {
                f.setLong(retObj, jsonObj.getInt(key));
            } else if (type == Short.TYPE) {
                f.setShort(retObj, (short) jsonObj.getInt(key));
            } else if (type == Boolean.TYPE) {
                f.setBoolean(retObj, jsonObj.getBoolean(key));
            } else if (type == Double.TYPE) {
                f.setDouble(retObj, jsonObj.getDouble(key));
            } else if (type == Float.TYPE) {
                f.setFloat(retObj, (float) jsonObj.getDouble(key));
            } else if (type == Character.TYPE) {
                char ch = jsonObj.getString(key).charAt(0);
                f.setChar(retObj, ch);
            } else if (type == Byte.TYPE) {
                f.setByte(retObj, (byte) jsonObj.getInt(key));
            } else {
                throw new JSONSerializationException("Unknown primitive: " + type);
            }
        } else if (type == String.class) {
            f.set(retObj, jsonObj.getString(key));
        } else if (JSONSerializable.class.isAssignableFrom(type)) {
            JSONObject jObj = jsonObj.getJSONObject(key);
            JSONSerializable serObj = deSerialize(type, jObj);
            f.set(retObj, serObj);
        }
    } catch (Exception e) {
        throw new JSONSerializationException(e.getMessage(), e);
    }
}

From source file:org.kordamp.ezmorph.object.NumberMorpher.java

/**
 * Creates a new morpher for the target type with a default value.<br>
 * The defaultValue should be of the same class as the target type.
 *
 * @param type         must be a primitive or wrapper type. BigDecimal and BigInteger
 *                     are also supported.
 * @param defaultValue return value if the value to be morphed is null
 *///from www  .  j ava 2  s.  c o  m
public NumberMorpher(Class type, Number defaultValue) {
    super(true);

    if (type == null) {
        throw new MorphException("Must specify a type");
    }

    if (type != Byte.TYPE && type != Short.TYPE && type != Integer.TYPE && type != Long.TYPE
            && type != Float.TYPE && type != Double.TYPE && !Byte.class.isAssignableFrom(type)
            && !Short.class.isAssignableFrom(type) && !Integer.class.isAssignableFrom(type)
            && !Long.class.isAssignableFrom(type) && !Float.class.isAssignableFrom(type)
            && !Double.class.isAssignableFrom(type) && !BigInteger.class.isAssignableFrom(type)
            && !BigDecimal.class.isAssignableFrom(type)) {
        throw new MorphException("Must specify a Number subclass");
    }

    if (defaultValue != null && !type.isInstance(defaultValue)) {
        throw new MorphException("Default value must be of type " + type);
    }

    this.type = type;
    setDefaultValue(defaultValue);
}

From source file:com.puppycrawl.tools.checkstyle.api.AutomaticBean.java

/**
 * Creates a BeanUtilsBean that is configured to use
 * type converters that throw a ConversionException
 * instead of using the default value when something
 * goes wrong.//from   w ww .  ja  v a 2 s  .  c o  m
 *
 * @return a configured BeanUtilsBean
 */
private static BeanUtilsBean createBeanUtilsBean() {
    final ConvertUtilsBean cub = new ConvertUtilsBean();

    cub.register(new BooleanConverter(), Boolean.TYPE);
    cub.register(new BooleanConverter(), Boolean.class);
    cub.register(new ArrayConverter(boolean[].class, new BooleanConverter()), boolean[].class);
    cub.register(new ByteConverter(), Byte.TYPE);
    cub.register(new ByteConverter(), Byte.class);
    cub.register(new ArrayConverter(byte[].class, new ByteConverter()), byte[].class);
    cub.register(new CharacterConverter(), Character.TYPE);
    cub.register(new CharacterConverter(), Character.class);
    cub.register(new ArrayConverter(char[].class, new CharacterConverter()), char[].class);
    cub.register(new DoubleConverter(), Double.TYPE);
    cub.register(new DoubleConverter(), Double.class);
    cub.register(new ArrayConverter(double[].class, new DoubleConverter()), double[].class);
    cub.register(new FloatConverter(), Float.TYPE);
    cub.register(new FloatConverter(), Float.class);
    cub.register(new ArrayConverter(float[].class, new FloatConverter()), float[].class);
    cub.register(new IntegerConverter(), Integer.TYPE);
    cub.register(new IntegerConverter(), Integer.class);
    cub.register(new ArrayConverter(int[].class, new IntegerConverter()), int[].class);
    cub.register(new LongConverter(), Long.TYPE);
    cub.register(new LongConverter(), Long.class);
    cub.register(new ArrayConverter(long[].class, new LongConverter()), long[].class);
    cub.register(new ShortConverter(), Short.TYPE);
    cub.register(new ShortConverter(), Short.class);
    cub.register(new ArrayConverter(short[].class, new ShortConverter()), short[].class);
    cub.register(new RelaxedStringArrayConverter(), String[].class);

    // BigDecimal, BigInteger, Class, Date, String, Time, TimeStamp
    // do not use defaults in the default configuration of ConvertUtilsBean

    return new BeanUtilsBean(cub, new PropertyUtilsBean());
}