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.3 Narrowing Primitive Conversions</em>
 * .//from  ww  w.j a v  a  2 s . c  om
 *
 * <code>
 * <blockquote>The following 22 specific conversions on primitive types
 *  are called the narrowing primitive conversions:
 * <ul>
 * <li>short to byte or char</li>
 * <li>char to byte or short</li>
 * <li>int to byte, short, or char</li>
 * <li>long to byte, short, char, or int</li>
 * <li>float to byte, short, char, int, or long</li>
 * <li>double to byte, short, char, int, long, or float </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 isPrimitiveNarrowing(Class<?> from, Class<?> to) {
    Assert.isTrue(Primitives.isPrimitive(from), "mustBeAPrimitive", "form");
    Assert.isTrue(Primitives.isPrimitive(to), "mustBeAPrimitive", "to");
    boolean isPrimitiveNarrowing = false;

    if (isIdentity(from, Double.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveDoubleNarrowing(to);
    } else if (isIdentity(from, Short.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveShortNarrowing(to);
    } else if (isIdentity(from, Character.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveCharacterNarrowing(to);
    } else if (isIdentity(from, Integer.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveIntegerNarrowing(to);
    } else if (isIdentity(from, Long.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveLongNarrowing(to);
    } else if (isIdentity(from, Float.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveFloatNarrowing(to);
    }
    /*
     * must be a byte
     */
    return isPrimitiveNarrowing;
}

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

public Object morph(Object value) {
    if (value != null && type.isAssignableFrom(value.getClass())) {
        // no conversion needed
        return value;
    }/*from w ww.jav  a2 s . co  m*/

    String str = String.valueOf(value).trim();

    if (!type.isPrimitive() && (value == null || str.length() == 0 || "null".equalsIgnoreCase(str))) {
        // if empty string and class != primitive treat it like null
        return null;
    }

    if (isDecimalNumber(type)) {
        if (Float.class.isAssignableFrom(type) || Float.TYPE == type) {
            return morphToFloat(str);
        } else if (Double.class.isAssignableFrom(type) || Double.TYPE == type) {
            return morphToDouble(str);
        } else {
            return morphToBigDecimal(str);
        }
    } else {
        if (Byte.class.isAssignableFrom(type) || Byte.TYPE == type) {
            return morphToByte(str);
        } else if (Short.class.isAssignableFrom(type) || Short.TYPE == type) {
            return morphToShort(str);
        } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE == type) {
            return morphToInteger(str);
        } else if (Long.class.isAssignableFrom(type) || Long.TYPE == type) {
            return morphToLong(str);
        } else {
            return morphToBigInteger(str);
        }
    }
}

From source file:com.cyclopsgroup.waterview.utils.TypeUtils.java

private static Map getNonePrimitiveTypeMap() {
    if (nonePrimitiveTypeMap == null) {
        nonePrimitiveTypeMap = new Hashtable();
        nonePrimitiveTypeMap.put(Boolean.TYPE, Boolean.class);
        nonePrimitiveTypeMap.put(Byte.TYPE, Byte.class);
        nonePrimitiveTypeMap.put(Character.TYPE, Character.class);
        nonePrimitiveTypeMap.put(Short.TYPE, Short.class);
        nonePrimitiveTypeMap.put(Integer.TYPE, Integer.class);
        nonePrimitiveTypeMap.put(Long.TYPE, Long.class);
        nonePrimitiveTypeMap.put(Float.TYPE, Float.class);
        nonePrimitiveTypeMap.put(Double.TYPE, Double.class);
    }/*from  w  ww.  j a v  a2 s  . com*/

    return nonePrimitiveTypeMap;
}

From source file:com.projity.util.ClassUtils.java

/**
 * Given a type, return a value that signifies that there are multiple values.  This can occur in a dialog which works on multile objects at once.  If type is unknown, a new one is constructed
 * @param clazz/*  w ww .  j  a v a 2 s .c  o m*/
 * @return
 */
public static Object getMultipleValueForType(Class clazz) {
    if (clazz == String.class)
        return STRING_MULTIPLE_VALUES;
    else if (clazz == Double.class || clazz == Double.TYPE)
        return DOUBLE_MULTIPLE_VALUES;
    else if (clazz == Integer.class || clazz == Integer.TYPE)
        return INTEGER_MULTIPLE_VALUES;
    else if (clazz == Long.class || clazz == Long.TYPE)
        return LONG_MULTIPLE_VALUES;
    else if (clazz == Float.class || clazz == Float.TYPE)
        return FLOAT_MULTIPLE_VALUES;
    else if (clazz == Boolean.class)
        return BOOLEAN_MULTIPLE_VALUES;
    else if (clazz == Rate.class)
        return RATE_MULTIPLE_VALUES;
    else {
        try {
            return clazz.newInstance();
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        }
        return null;
    }
}

From source file:org.acmsl.commons.utils.ConversionUtils.java

/**
 * Converts given String to long if given value is not null.
 * @param value the value to convert./*from  ww w .ja  v  a 2s.  com*/
 * @return the converted value.
 */
@Nullable
public Long toLongIfNotNull(@Nullable final String value) {
    Long result = null;

    @Nullable
    final Converter t_Converter = ConvertUtils.lookup(Long.TYPE);

    if (t_Converter != null) {
        @Nullable
        final Object t_Result = t_Converter.convert(Long.TYPE, value);

        if (t_Result instanceof Long) {
            result = (Long) t_Result;
        }
    }

    return result;
}

From source file:org.cloudata.core.common.io.CObjectWritable.java

/** Write a {@link CWritable}, {@link String}, primitive type, or an array of
 * the preceding. *///from  w  w  w .ja  v a  2 s.  c o  m
public static void writeObject(DataOutput out, Object instance, Class declaredClass, CloudataConf conf,
        boolean arrayComponent) throws IOException {

    if (instance == null) { // null
        instance = new NullInstance(declaredClass, conf);
        declaredClass = CWritable.class;
        arrayComponent = false;
    }

    if (!arrayComponent) {
        CUTF8.writeString(out, declaredClass.getName()); // always write declared
        //System.out.println("Write:declaredClass.getName():" + declaredClass.getName());
    }

    if (declaredClass.isArray()) { // array
        int length = Array.getLength(instance);
        out.writeInt(length);
        //System.out.println("Write:length:" + length);

        if (declaredClass.getComponentType() == Byte.TYPE) {
            out.write((byte[]) instance);
        } else if (declaredClass.getComponentType() == ColumnValue.class) {
            //ColumnValue?  Deserialize? ?? ?   ?? ?  .
            writeColumnValue(out, instance, declaredClass, conf, length);
        } else {
            for (int i = 0; i < length; i++) {
                writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf,
                        !declaredClass.getComponentType().isArray());
            }
        }
    } else if (declaredClass == String.class) { // String
        CUTF8.writeString(out, (String) instance);

    } else if (declaredClass.isPrimitive()) { // primitive type

        if (declaredClass == Boolean.TYPE) { // boolean
            out.writeBoolean(((Boolean) instance).booleanValue());
        } else if (declaredClass == Character.TYPE) { // char
            out.writeChar(((Character) instance).charValue());
        } else if (declaredClass == Byte.TYPE) { // byte
            out.writeByte(((Byte) instance).byteValue());
        } else if (declaredClass == Short.TYPE) { // short
            out.writeShort(((Short) instance).shortValue());
        } else if (declaredClass == Integer.TYPE) { // int
            out.writeInt(((Integer) instance).intValue());
        } else if (declaredClass == Long.TYPE) { // long
            out.writeLong(((Long) instance).longValue());
        } else if (declaredClass == Float.TYPE) { // float
            out.writeFloat(((Float) instance).floatValue());
        } else if (declaredClass == Double.TYPE) { // double
            out.writeDouble(((Double) instance).doubleValue());
        } else if (declaredClass == Void.TYPE) { // void
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }
    } else if (declaredClass.isEnum()) { // enum
        CUTF8.writeString(out, ((Enum) instance).name());
    } else if (CWritable.class.isAssignableFrom(declaredClass)) { // Writable
        if (instance.getClass() == declaredClass) {
            out.writeShort(TYPE_SAME); // ? ?? ? ?? 
            //System.out.println("Write:TYPE_SAME:" + TYPE_SAME);

        } else {
            out.writeShort(TYPE_DIFF);
            //System.out.println("Write:TYPE_DIFF:" + TYPE_DIFF);
            CUTF8.writeString(out, instance.getClass().getName());
            //System.out.println("Write:instance.getClass().getName():" + instance.getClass().getName());
        }
        ((CWritable) instance).write(out);
        //System.out.println("Write:instance value");

    } else {
        throw new IOException("Can't write: " + instance + " as " + declaredClass);
    }
}

From source file:nz.co.senanque.validationengine.ConvertUtils.java

public static Object getPrimitiveTypeForNull(Class<?> clazz) {
    if (clazz.equals(Long.TYPE)) {
        return 0L;
    } else if (clazz.equals(Integer.TYPE)) {
        return 0;
    } else if (clazz.equals(Float.TYPE)) {
        return 0.0F;
    } else if (clazz.equals(Double.TYPE)) {
        return 0.0D;
    } else if (clazz.equals(Boolean.TYPE)) {
        return false;
    }/*from   w  ww. j a v a  2s .c  om*/
    return null;
}

From source file:org.cocoa4android.util.sbjson.SBJsonWriter.java

/**
 *  /*  ww w  . j  av  a  2  s.c  o  m*/
 * @param clazz   
 * @return
 */
public static boolean isNumber(Class<?> clazz) {
    return (clazz != null) && ((Byte.TYPE.isAssignableFrom(clazz)) || (Short.TYPE.isAssignableFrom(clazz))
            || (Integer.TYPE.isAssignableFrom(clazz)) || (Long.TYPE.isAssignableFrom(clazz))
            || (Float.TYPE.isAssignableFrom(clazz)) || (Double.TYPE.isAssignableFrom(clazz))
            || (Number.class.isAssignableFrom(clazz)));
}

From source file:org.gradle.internal.reflect.JavaReflectionUtil.java

public static Class<?> getWrapperTypeForPrimitiveType(Class<?> type) {
    if (type == Character.TYPE) {
        return Character.class;
    } else if (type == Boolean.TYPE) {
        return Boolean.class;
    } else if (type == Long.TYPE) {
        return Long.class;
    } else if (type == Integer.TYPE) {
        return Integer.class;
    } else if (type == Short.TYPE) {
        return Short.class;
    } else if (type == Byte.TYPE) {
        return Byte.class;
    } else if (type == Float.TYPE) {
        return Float.class;
    } else if (type == Double.TYPE) {
        return Double.class;
    }// w ww.ja v a 2s .co m
    throw new IllegalArgumentException(
            String.format("Don't know the wrapper type for primitive type %s.", type));
}

From source file:nz.co.senanque.validationengine.ConvertUtils.java

public static Object getObjectForNull(Class<?> clazz) {
    if (clazz.equals(Long.TYPE)) {
        return new Long(0);
    } else if (clazz.equals(Integer.TYPE)) {
        return new Integer(0);
    } else if (clazz.equals(Float.TYPE)) {
        return new Float(0.0F);
    } else if (clazz.equals(Double.TYPE)) {
        return new Double(0.0D);
    } else if (clazz.equals(Boolean.TYPE)) {
        return new Boolean(false);
    }/*ww  w .j  a va2  s . com*/
    return null;
}