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.openTwoFactor.clientExt.net.sf.ezmorph.primitive.LongMorpher.java

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

From source file:org.eclipse.gyrex.monitoring.internal.mbeans.MetricSetMBean.java

private OpenType detectType(final Class type) {
    if ((Long.class == type) || (Long.TYPE == type)) {
        return SimpleType.LONG;
    } else if ((Integer.class == type) || (Integer.TYPE == type)) {
        return SimpleType.INTEGER;
    } else if ((Double.class == type) || (Double.TYPE == type)) {
        return SimpleType.DOUBLE;
    } else if ((Float.class == type) || (Float.TYPE == type)) {
        return SimpleType.FLOAT;
    } else if ((Byte.class == type) || (Byte.TYPE == type)) {
        return SimpleType.BYTE;
    } else if ((Short.class == type) || (Short.TYPE == type)) {
        return SimpleType.SHORT;
    } else if ((Boolean.class == type) || (Boolean.TYPE == type)) {
        return SimpleType.BOOLEAN;
    } else if (BigDecimal.class == type) {
        return SimpleType.BIGDECIMAL;
    } else if (BigInteger.class == type) {
        return SimpleType.BIGINTEGER;
    } else if ((Character.class == type) || (Character.TYPE == type)) {
        return SimpleType.CHARACTER;
    }/* w w  w.  j  a  v a2 s .co  m*/

    // last fallback to strings
    if (isConvertibleToString(type)) {
        return SimpleType.STRING;
    }

    // give up
    return null;
}

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

public static Object convertToObject(Class<?> clazz) {
    if (clazz.isPrimitive()) {
        if (clazz.equals(Long.TYPE)) {
            return new Long(0L);
        } else if (clazz.equals(Integer.TYPE)) {
            return new Integer(0);
        } else if (clazz.equals(Float.TYPE)) {
            return new Float(0F);
        } else if (clazz.equals(Double.TYPE)) {
            return new Double(0D);
        } else if (clazz.equals(Boolean.TYPE)) {
            return new Boolean(false);
        }//from   w w  w. j ava  2  s.  c  om
    }
    return null;

}

From source file:org.rimudb.PropertyNode.java

public PropertyNode(DataObjectNode parent, Element element, int keySeqeunce) {
    this.name = element.getFirstChild().getNodeValue();
    this.sourceName = this.name;
    this.parent = parent;

    if (parent == null) {
        log.warn("Parent of " + name + " is null");
    }//from w  w  w .  ja v a  2  s.co m

    try {
        pdesc = parent.getPropertyDescriptor(name);
        if (pdesc == null) {
            throw new NullPointerException(
                    "PropertyDescriptor for " + parent.getName() + "." + name + " could not be found.");
        }
        read = pdesc.getReadMethod();
        if (read == null && log.isDebugEnabled()) {
            log.debug("Read method for " + parent.getName() + "." + name + " could not be found.");
        }
        write = pdesc.getWriteMethod();
        if (write == null && log.isDebugEnabled()) {
            log.debug("Write method for " + parent.getName() + "." + name + " could not be found.");
        }
        if (write != null) {
            Class[] parmTypes = write.getParameterTypes();
            parmType = parmTypes[0];
            if (parmType == Integer.TYPE) {
                parmType = Integer.class;
            }
            if (parmType == Long.TYPE) {
                parmType = Long.class;
            }
            if (parmType == Boolean.TYPE) {
                parmType = Boolean.class;
            }
            valueConstructor = null;
            if (parmType != java.sql.Timestamp.class && parmType != java.sql.Date.class) {
                try {
                    valueConstructor = parmType.getConstructor(new Class[] { String.class });
                } catch (NoSuchMethodException e) {
                    log.error("Cannot find a constructor: " + parmType.getName() + "(String s)", e);
                }
            }
        }

        // Set some attributes
        String source = element.getAttribute("source");
        if (source == null)
            source = "";
        fromParent = source.equalsIgnoreCase("parent"); // bypass elements for parent
        constant = source.equalsIgnoreCase("constant");

        String trim = element.getAttribute("trim");
        if (trim == null)
            trim = "none";
        if (trim.equalsIgnoreCase("both"))
            this.trimMode = TRIMBOTH;
        if (trim.equalsIgnoreCase("right"))
            this.trimMode = TRIMRIGHT;

        if (fromParent) {
            sourceName = element.getAttribute("sourceName");
            if (sourceName == null || sourceName.trim().length() == 0) {
                sourceName = this.name;
            }

            sourceParent = element.getAttribute("sourceParent");

            String sourceIsIdentityStr = element.getAttribute("sourceIsIdentity");
            sourceIsIdentity = (sourceIsIdentityStr != null && sourceIsIdentityStr.equalsIgnoreCase("true"));
        }

    } catch (Exception e) {
        log.error("in PropertyNode.PropertyNode", e);
    }

}

From source file:org.romaframework.core.schema.SchemaClassElement.java

@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object convertValue(Object iFieldValue, SchemaClassDefinition expectedType) {
    if (expectedType == null || expectedType.getSchemaClass().isArray())
        return iFieldValue;

    SchemaClass typeClass = expectedType.getSchemaClass();
    if (typeClass.equals(Roma.schema().getSchemaClass(iFieldValue)))
        return iFieldValue;

    String textValue = null;//from   ww w. j a  v a  2s . c o  m
    if (iFieldValue instanceof String) {
        textValue = (String) iFieldValue;
    } else if (iFieldValue != null) {
        textValue = iFieldValue.toString();
    }

    Object value = null;

    if (textValue != null) {
        // TRY A SOFT CONVERSION
        if (typeClass.isOfType(Integer.class) || typeClass.isOfType(Integer.TYPE)) {
            try {
                value = textValue.equals("") ? null : Integer.parseInt(textValue);
            } catch (Exception e) {
                value = textValue.equals("") ? null : Double.valueOf(textValue).intValue();
            }
        } else if (typeClass.isOfType(Long.class) || typeClass.isOfType(Long.TYPE)) {
            value = textValue.equals("") ? null : Long.parseLong(textValue);
        } else if (typeClass.isOfType(Short.class) || typeClass.isOfType(Short.TYPE)) {
            value = textValue.equals("") ? null : Short.parseShort(textValue);
        } else if (typeClass.isOfType(Byte.class) || typeClass.isOfType(Byte.TYPE)) {
            value = textValue.equals("") ? null : Byte.parseByte(textValue);
        } else if (typeClass.isOfType(Character.class) || typeClass.isOfType(Character.TYPE)) {
            if (textValue.length() > 0) {
                value = new Character(textValue.charAt(0));
            }
        } else if (typeClass.isOfType(Float.class) || typeClass.isOfType(Float.TYPE)) {
            value = textValue.equals("") ? null : Float.parseFloat(textValue);
        } else if (typeClass.isOfType(Double.class) || typeClass.isOfType(Double.TYPE)) {
            value = textValue.equals("") ? null : Double.parseDouble(textValue);
        } else if (typeClass.isOfType(BigDecimal.class)) {
            value = textValue.equals("") ? null : new BigDecimal(textValue);
        } else if (iFieldValue != null && !typeClass.isArray() && iFieldValue.getClass().isArray()) {
            // DESTINATION VALUE IS NOT AN ARRAY: ASSIGN THE FIRST ONE ELEMENT
            value = ((Object[]) iFieldValue)[0];
        } else if (typeClass.isEnum()) {
            value = Enum.valueOf((Class) typeClass.getLanguageType(), textValue.toUpperCase());
        } else {
            value = iFieldValue;
        }
    }

    if (value != null) {
        // TODO is this the right place to do this...?
        Class<?> valueClass = value.getClass();
        // SUCH A MONSTER!!! MOVE THIS LOGIC IN SchemaClass.isAssignableFrom...
        if (value instanceof VirtualObject
                && !(typeClass.getLanguageType() instanceof Class<?>
                        && ((Class<?>) typeClass.getLanguageType()).isAssignableFrom(VirtualObject.class))
                && ((VirtualObject) value).getSuperClassObject() != null) {
            if (ComposedEntity.class
                    .isAssignableFrom(((VirtualObject) value).getSuperClassObject().getClass())) {
                value = ((VirtualObject) value).getSuperClassObject();
                valueClass = value.getClass();
            }
        }

        if (value instanceof ComposedEntity<?> && !typeClass.isAssignableFrom(valueClass)) {
            value = ((ComposedEntity<?>) value).getEntity();
        }
    }

    if (value == null && typeClass.isPrimitive()) {
        log.warn("Cannot set the field value to null for primitive types! Field: " + getEntity() + "." + name
                + " of class " + expectedType.getName() + ". Setting value to 0.");
        // SET THE VALUE TO 0
        value = SchemaHelper.assignDefaultValueToLiteral(typeClass);
    }
    return value;
}

From source file:de.micromata.genome.util.strings.converter.StandardStringConverter.java

@Override
public char getTypeChar(Object value) {
    if (value == null) {
        return ConvertedStringTypes.NULL.getShortType();
    }//from   w w  w  .ja  v a  2 s.  c om
    Class<?> cls = value.getClass();

    if (value instanceof String) {
        return ConvertedStringTypes.STRING.getShortType();
    }

    Class<?> vclass = value.getClass();

    if (value instanceof Boolean || vclass == Boolean.TYPE) {
        return ConvertedStringTypes.BOOLEAN.getShortType();
    }
    if (value instanceof Byte || vclass == Byte.TYPE) {
        return ConvertedStringTypes.BYTE.getShortType();
    }
    if (value instanceof Short || vclass == Short.TYPE) {
        return ConvertedStringTypes.SHORT.getShortType();
    }
    if (value instanceof Integer || vclass == Integer.TYPE) {
        return ConvertedStringTypes.INTEGER.getShortType();
    }
    if (value instanceof Long || vclass == Long.TYPE) {
        return ConvertedStringTypes.LONG.getShortType();
    }
    if (value instanceof Float || vclass == Float.TYPE) {
        return ConvertedStringTypes.FLOAT.getShortType();
    }
    if (value instanceof Double || vclass == Double.TYPE) {
        return ConvertedStringTypes.DOUBLE.getShortType();
    }
    if (value instanceof Character || vclass == Character.TYPE) {
        return ConvertedStringTypes.CHAR.getShortType();
    }
    if (value instanceof Date) {
        return ConvertedStringTypes.DATE.getShortType();
    }
    if (value instanceof BigDecimal) {
        return ConvertedStringTypes.BIGDECIMAL.getShortType();
    }
    if (value instanceof Character) {
        return ConvertedStringTypes.CHAR.getShortType();
    }
    if (value instanceof byte[]) {
        return ConvertedStringTypes.BYTEARRAY.getShortType();
    }
    if (value instanceof String[]) {
        return ConvertedStringTypes.STRINGARRAY.getShortType();
    }
    if (value instanceof Long[]) {
        return ConvertedStringTypes.LONGARRAY.getShortType();
    }

    // if (value instanceof Serializable)
    // return ConvertedStringTypes.XMLOBJECT;
    return ConvertedStringTypes.CUSTOM.getShortType();
}

From source file:edu.wisc.commons.httpclient.HttpParamsBean.java

public long getLongParameter(final String name, long defaultValue) {
    return getTypedParameter(name, defaultValue, Long.TYPE, new Function<Object, Long>() {
        public Long apply(Object value) {
            final Long longValue = Long.valueOf(value.toString());

            //If this parameter is supposed to be a long store it as such to save future parsing work
            delegate.setLongParameter(name, longValue);

            return longValue;
        }/*from   www  .j  a  v  a  2s. co  m*/
    });
}

From source file:org.dozer.converters.DateConverter.java

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

    long time;/*  w  ww .  j  a v  a 2s  .  c  om*/
    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;
        }
        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:com.alibaba.doris.admin.service.impl.ValueParseUtil.java

/**
 * ?String ?://from   www. ja  va 2 s. co m
 * 
 * <pre>
 * short, int, long, float : 0
 * char, byte: 0
 * String: null
 * Map, List: null
 * Integer, Long, Float : null
 * Date: null
 * array: null
 * </pre>
 * 
 * @param strValue
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> T parseStringValue(String strValue, Class<T> clazz, boolean autoDefault) {

    if (DEF_NULL.equals(strValue)) {
        if (!clazz.isPrimitive()) {
            return null;
        }
        if (autoDefault) {
            return (T) getInternalDefaultValue(clazz);
        } else {
            return null;
        }
    }

    if (DEF_EMPTY.equals(strValue)) {
        if (clazz.isArray()) {
            return (T) Array.newInstance(clazz.getComponentType(), 0);
        }

        if (Map.class.isAssignableFrom(clazz)) {
            return (T) Collections.EMPTY_MAP;
        }

        if (List.class.isAssignableFrom(clazz)) {
            return (T) new ArrayList<Object>();
        }

        if (Set.class.isAssignableFrom(clazz)) {
            return (T) new HashSet<Object>();
        }

        if (String.class.equals(clazz)) {
            return (T) StringUtils.EMPTY;
        }

        if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) {
            return (T) Character.valueOf(' ');
        }

        if (autoDefault) {
            return (T) getInternalDefaultValue(clazz);
        } else {
            return null;
        }
    }

    if (StringUtils.isBlank(strValue)) {// ?
        if (autoDefault) {
            return (T) getInternalDefaultValue(clazz);
        } else {
            return null;
        }
    } else {

        if (String.class.equals(clazz)) {
            return (T) strValue;
        }

        if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) {
            return (T) Short.valueOf(strValue);
        }

        if (Integer.TYPE.equals(clazz) || Integer.class.equals(clazz)) {
            return (T) Integer.valueOf(strValue);
        }
        if (Long.TYPE.equals(clazz) || Long.class.equals(clazz)) {
            return (T) Long.valueOf(strValue);
        }
        if (Boolean.TYPE.equals(clazz) || Boolean.class.equals(clazz)) {
            return (T) Boolean.valueOf(strValue);
        }
        if (Float.TYPE.equals(clazz) || Float.class.equals(clazz)) {
            return (T) Float.valueOf(strValue);
        }
        if (Double.TYPE.equals(clazz) || Double.class.equals(clazz)) {
            return (T) Double.valueOf(strValue);
        }
        if (Byte.TYPE.equals(clazz) || Byte.class.equals(clazz)) {
            return (T) Byte.valueOf(strValue);
        }
        if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) {
            return (T) Character.valueOf(strValue.charAt(0));
        }

        if (clazz.isArray()) {
            final Class<?> componentType = clazz.getComponentType();
            // String[]
            if (String.class.equals(componentType)) {
                return (T) StringUtils.split(strValue, ',');
            }
            // ?char[]
            if (Character.TYPE.equals(componentType)) {
                return (T) strValue.toCharArray();
            }

            if (Character.class.equals(componentType)) {
                final char[] tmp = strValue.toCharArray();
                final Character[] result = new Character[tmp.length];
                for (int i = 0; i < result.length; i++) {
                    result[i] = tmp[i];
                }
                return (T) result;
            }

            if (Byte.TYPE.equals(componentType) || Byte.class.equals(componentType)) {
                return (T) (strValue == null ? null : strValue.getBytes());
            }
        }
    }

    return null;

}

From source file:net.yck.wkrdb.common.shared.PropertyConverter.java

/**
 * Performs a data type conversion from the specified value object to the
 * given target data class. If additional information is required for this
 * conversion, it is obtained from {@code DefaultConversionHandler.INSTANCE}
 * object. 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  w  w w  .  ja  v  a 2s  . c om*/
 *
 * @param cls
 *            the target class of the converted value
 * @param value
 *            the value to convert
 * @return the converted value
 * @throws ConversionException
 *             if the value is not compatible with the requested type
 */
public static Object to(Class<?> cls, Object value) throws ConversionException {
    if (cls.isInstance(value)) {
        return value; // no conversion needed
    }

    if (String.class.equals(cls)) {
        return String.valueOf(value);
    }
    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, DefaultConversionHandler.INSTANCE.getDateFormat());
    } else if (Calendar.class.equals(cls)) {
        return toCalendar(value, DefaultConversionHandler.INSTANCE.getDateFormat());
    } 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");
}