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:Main.java

/**
 * This method parses the given value into the specified primitive or wrapper class.
 * @param clazz - primitive or wrapper class used to parse
 * @param value - string to be parsed//w w  w .  j a  va  2  s  . c om
 * @return object of type clazz parsed from the string
 * @author Trisan Bepler
 */
public static Object toObject(Class<?> clazz, String value) {
    if (Boolean.TYPE == clazz)
        return Boolean.parseBoolean(value);
    if (Byte.TYPE == clazz)
        return Byte.parseByte(value);
    if (Short.TYPE == clazz)
        return Short.parseShort(value);
    if (Integer.TYPE == clazz)
        return Integer.parseInt(value);
    if (Long.TYPE == clazz)
        return Long.parseLong(value);
    if (Float.TYPE == clazz)
        return Float.parseFloat(value);
    if (Double.TYPE == clazz)
        return Double.parseDouble(value);
    if (Boolean.class == clazz)
        return Boolean.parseBoolean(value);
    if (Byte.class == clazz)
        return Byte.parseByte(value);
    if (Short.class == clazz)
        return Short.parseShort(value);
    if (Integer.class == clazz)
        return Integer.parseInt(value);
    if (Long.class == clazz)
        return Long.parseLong(value);
    if (Float.class == clazz)
        return Float.parseFloat(value);
    if (Double.class == clazz)
        return Double.parseDouble(value);
    if (Character.class == clazz)
        return value.charAt(0);
    if (Character.TYPE == clazz)
        return value.charAt(0);
    return value;
}

From source file:Main.java

private static String getColumnType(Class<?> fieldType) {
    if (String.class == fieldType) {
        return "TEXT";
    }// w  ww.  ja v  a 2  s .c o  m
    if ((Integer.TYPE == fieldType) || (Integer.class == fieldType)) {
        return "INTEGER";
    }
    if ((Long.TYPE == fieldType) || (Long.class == fieldType)) {
        return "BIGINT";
    }
    if ((Float.TYPE == fieldType) || (Float.class == fieldType)) {
        return "FLOAT";
    }
    if ((Short.TYPE == fieldType) || (Short.class == fieldType)) {
        return "INT";
    }
    if ((Double.TYPE == fieldType) || (Double.class == fieldType)) {
        return "DOUBLE";
    }
    if (Blob.class == fieldType) {
        return "BLOB";
    }

    return "TEXT";
}

From source file:Main.java

private static boolean isWideningPrimitiveNumberConversion(final Class source, final Class target) {
    if (target == Short.TYPE && (source == Byte.TYPE)) {
        return true;
    } else if (target == Integer.TYPE && (source == Short.TYPE || source == Byte.TYPE)) {
        return true;
    } else if (target == Long.TYPE && (source == Integer.TYPE || source == Short.TYPE || source == Byte.TYPE)) {
        return true;
    } else if (target == Float.TYPE
            && (source == Long.TYPE || source == Integer.TYPE || source == Short.TYPE || source == Byte.TYPE)) {
        return true;
    } else if (target == Double.TYPE && (source == Float.TYPE || source == Long.TYPE || source == Integer.TYPE
            || source == Short.TYPE || source == Byte.TYPE)) {
        return true;
    } else {/*ww w .  ja v  a 2 s  .co m*/
        return false;
    }
}

From source file:PrimitiveUtils.java

public static Object read(String value, Class type) {
    Object ret = value;//w  w  w. j a va  2  s.  com
    if (Integer.TYPE.equals(type)) {
        ret = Integer.valueOf(value);
    }
    if (Byte.TYPE.equals(type)) {
        ret = Byte.valueOf(value);
    }
    if (Short.TYPE.equals(type)) {
        ret = Short.valueOf(value);
    }
    if (Long.TYPE.equals(type)) {
        ret = Long.valueOf(value);
    }
    if (Float.TYPE.equals(type)) {
        ret = Float.valueOf(value);
    }
    if (Double.TYPE.equals(type)) {
        ret = Double.valueOf(value);
    }
    if (Boolean.TYPE.equals(type)) {
        ret = Boolean.valueOf(value);
    }
    if (Character.TYPE.equals(type)) {
        ret = value.charAt(0);
    }
    // TODO others.
    return ret;
}

From source file:Main.java

public static ContentValues objectToContentValues(Object object) {
    if (object == null) {
        throw new IllegalArgumentException("please check your argument");
    }//w  w  w .  j a  va  2 s. c  om
    ContentValues contentValues = new ContentValues();
    try {
        Field[] fields = object.getClass().getDeclaredFields();
        for (Field field : fields) {
            String fieldName = field.getName();
            Type type = field.getType();
            field.setAccessible(true);
            if (type.equals(String.class)) {
                contentValues.put(fieldName, field.get(object).toString());
            } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
                contentValues.put(fieldName, field.getInt(object));
            } else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
                contentValues.put(fieldName, field.getFloat(object));
            } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
                contentValues.put(fieldName, field.getLong(object));
            } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
                contentValues.put(fieldName, field.getDouble(object));
            } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
                contentValues.put(fieldName, field.getBoolean(object));
            }
        }
    } catch (IllegalAccessException | IllegalArgumentException e) {
        e.printStackTrace();
    }
    return contentValues;
}

From source file:Main.java

/**
 * Creates a class identifier of form Labc/abc;, from a Class.
 *///from   www  .  j a  va  2s .  c  o  m
public static String ci(Class n) {
    if (n.isArray()) {
        n = n.getComponentType();
        if (n.isPrimitive()) {
            if (n == Byte.TYPE) {
                return "[B";
            } else if (n == Boolean.TYPE) {
                return "[Z";
            } else if (n == Short.TYPE) {
                return "[S";
            } else if (n == Character.TYPE) {
                return "[C";
            } else if (n == Integer.TYPE) {
                return "[I";
            } else if (n == Float.TYPE) {
                return "[F";
            } else if (n == Double.TYPE) {
                return "[D";
            } else if (n == Long.TYPE) {
                return "[J";
            } else {
                throw new RuntimeException("Unrecognized type in compiler: " + n.getName());
            }
        } else {
            return "[" + ci(n);
        }
    } else {
        if (n.isPrimitive()) {
            if (n == Byte.TYPE) {
                return "B";
            } else if (n == Boolean.TYPE) {
                return "Z";
            } else if (n == Short.TYPE) {
                return "S";
            } else if (n == Character.TYPE) {
                return "C";
            } else if (n == Integer.TYPE) {
                return "I";
            } else if (n == Float.TYPE) {
                return "F";
            } else if (n == Double.TYPE) {
                return "D";
            } else if (n == Long.TYPE) {
                return "J";
            } else if (n == Void.TYPE) {
                return "V";
            } else {
                throw new RuntimeException("Unrecognized type in compiler: " + n.getName());
            }
        } else {
            return "L" + p(n) + ";";
        }
    }
}

From source file:sim.portrayal.inspector.TimeSeriesChartingPropertyInspector.java

public static Class[] types() {
    return new Class[] { Number.class, Boolean.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE,
            Double.TYPE, Valuable.class };
}

From source file:Main.java

public static boolean isConvertible(Class<?> srcPrimitive, Class<?> tgtPrimitive) {
    if (Boolean.TYPE.equals(srcPrimitive)) {
        return Boolean.TYPE.equals(tgtPrimitive);
    } else if (Byte.TYPE.equals(tgtPrimitive)) {
        return Byte.TYPE.equals(tgtPrimitive) || Short.TYPE.equals(tgtPrimitive)
                || Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive)
                || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive);
    } else if (Character.TYPE.equals(srcPrimitive)) {
        return Character.TYPE.equals(tgtPrimitive) || Integer.TYPE.equals(tgtPrimitive)
                || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive)
                || Double.TYPE.equals(tgtPrimitive);
    } else if (Double.TYPE.equals(srcPrimitive)) {
        return Double.TYPE.equals(tgtPrimitive);
    } else if (Float.TYPE.equals(srcPrimitive)) {
        return Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive);
    } else if (Integer.TYPE.equals(srcPrimitive)) {
        return Integer.TYPE.equals(tgtPrimitive) || Long.TYPE.equals(tgtPrimitive)
                || Float.TYPE.equals(tgtPrimitive) || Double.TYPE.equals(tgtPrimitive);
    } else if (Long.TYPE.equals(srcPrimitive)) {
        return Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive)
                || Double.TYPE.equals(tgtPrimitive);
    } else if (Short.TYPE.equals(srcPrimitive)) {
        return Short.TYPE.equals(tgtPrimitive) || Integer.TYPE.equals(tgtPrimitive)
                || Long.TYPE.equals(tgtPrimitive) || Float.TYPE.equals(tgtPrimitive)
                || Double.TYPE.equals(tgtPrimitive);
    }//ww  w .j ava  2s. c  om
    return false;
}

From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java

/**
 * ?,?,//  w ww  . j  a  v a 2s  .c  o m
 * 
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
private static <T> T getInternalDefaultValue(Class<T> clazz) {
    if (!clazz.isPrimitive()) {
        return null;
    }
    if (Short.TYPE.equals(clazz)) {
        return (T) Short.valueOf((short) 0);
    }
    if (Integer.TYPE.equals(clazz)) {
        return (T) Integer.valueOf(0);
    }
    if (Long.TYPE.equals(clazz)) {
        return (T) Long.valueOf(0);
    }
    if (Boolean.TYPE.equals(clazz)) {
        return (T) Boolean.valueOf(false);
    }
    if (Float.TYPE.equals(clazz)) {
        return (T) Float.valueOf(0);
    }
    if (Double.TYPE.equals(clazz)) {
        return (T) Double.valueOf(0);
    }
    if (Byte.TYPE.equals(clazz)) {
        return (T) Byte.valueOf((byte) 0);
    }
    if (Character.TYPE.equals(clazz)) {
        return (T) Character.valueOf('\0');
    }
    return null;
}

From source file:Main.java

private static Class<?>[] getArgsClasses(Object[] paramArrayOfObject) {
    Class[] arrayOfClass = null;//from  www . j a v a 2 s. c  om
    if (paramArrayOfObject != null) {
        arrayOfClass = new Class[paramArrayOfObject.length];

        for (int i = 0; i < paramArrayOfObject.length; ++i) {
            if (paramArrayOfObject[i] != null) {
                arrayOfClass[i] = paramArrayOfObject[i].getClass();
                if (arrayOfClass[i] == Integer.class) {
                    arrayOfClass[i] = Integer.TYPE;
                } else if (arrayOfClass[i] != String.class) {
                    if (arrayOfClass[i] == Boolean.class) {
                        arrayOfClass[i] = Boolean.TYPE;
                    } else if (arrayOfClass[i] == Long.class) {
                        arrayOfClass[i] = Long.TYPE;
                    }
                }
            }
        }
    }

    return arrayOfClass;
}