List of usage examples for java.lang Long TYPE
Class TYPE
To view the source code for java.lang Long TYPE.
Click Source Link
From source file:org.opoo.util.ClassUtils.java
public static boolean isCompatibleType(Object value, Class type) { // Do object check first, then primitives if (value == null || type.isInstance(value)) { return true; } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) { return true; } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) { return true; } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) { return true; } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) { return true; } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) { return true; } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) { return true; } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) { return true; } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) { return true; } else {/*from ww w.j a va 2 s.c o m*/ return false; } }
From source file:org.seasar.struts.lessconfig.factory.AbstractValidatorAnnotationHandler.java
protected String getAutoTypeValidatorName(PropertyDesc propDesc) { Class paramType = propDesc.getPropertyType(); if (paramType.isArray()) { paramType = paramType.getComponentType(); }/*from ww w .ja va 2 s .c om*/ if (paramType.equals(Byte.class) || paramType.equals(Byte.TYPE)) { return "byte"; } else if (Date.class.isAssignableFrom(paramType)) { return "date"; } else if (paramType.equals(Double.class) || paramType.equals(Double.TYPE)) { return "double"; } else if (paramType.equals(Float.class) || paramType.equals(Float.TYPE)) { return "float"; } else if (paramType.equals(Integer.class) || paramType.equals(Integer.TYPE)) { return "integer"; } else if (paramType.equals(Long.class) || paramType.equals(Long.TYPE)) { return "long"; } else if (paramType.equals(Short.class) || paramType.equals(Short.TYPE)) { return "short"; } return null; }
From source file:nz.co.senanque.validationengine.ValidationUtils.java
public static Comparable<?> convertTo(final Class<Comparable<?>> clazz, Object obj) { if (obj == null) { return null; }//from w w w . java2 s . co m if (clazz.isAssignableFrom(obj.getClass())) { return (Comparable<?>) obj; } final String oStr = String.valueOf(obj); if (clazz.equals(String.class)) { return oStr; } if (clazz.equals(Long.class) || clazz.equals(Long.TYPE)) { if (Number.class.isAssignableFrom(obj.getClass())) { return new Long(((Number) obj).longValue()); } return Long.valueOf(oStr); } if (clazz.equals(Integer.class) || clazz.equals(Integer.TYPE)) { if (Number.class.isAssignableFrom(obj.getClass())) { return new Integer(((Number) obj).intValue()); } return Integer.valueOf(oStr); } if (clazz.equals(Double.class) || clazz.equals(Double.TYPE)) { if (Number.class.isAssignableFrom(obj.getClass())) { return new Double(((Number) obj).doubleValue()); } return Double.valueOf(oStr); } if (clazz.equals(Float.class) || clazz.equals(Float.TYPE)) { if (Number.class.isAssignableFrom(obj.getClass())) { return new Float(((Number) obj).floatValue()); } return Float.valueOf(oStr); } if (clazz.equals(BigDecimal.class)) { return new BigDecimal(oStr); } if (clazz.equals(java.util.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(java.sql.Date.class)) { return java.sql.Date.valueOf(oStr); } return null; }
From source file:com.aliyun.fs.oss.utils.OSSClientAgent.java
@SuppressWarnings("unchecked") private AppendObjectResult appendObject(String bucket, String key, File file, Long position, Configuration conf, boolean retry) throws IOException, ServiceException, ClientException { try {/* www. j av a 2s . co m*/ Class AppendObjectRequestClz = ResourceLoader.getInstance().getUrlClassLoader(conf) .loadClass("com.aliyun.oss.model.AppendObjectRequest"); Constructor cons = AppendObjectRequestClz.getConstructor(String.class, String.class, File.class); Object appendObjectRequest = cons.newInstance(bucket, key, file); Method method0 = AppendObjectRequestClz.getMethod("setPosition", Long.TYPE); method0.invoke(appendObjectRequest, position); Method method = this.ossClientClz.getMethod("appendObject", AppendObjectRequestClz); Object ret = method.invoke(this.ossClient, appendObjectRequest); return gson.fromJson(gson.toJson(ret), AppendObjectResult.class); } catch (Exception e) { if (retry && updateOSSClient(e)) { return appendObject(bucket, key, file, position, conf, false); } else { handleException(e); return null; } } }
From source file:com.aol.one.patch.DefaultPatcher.java
private List<MethodData> generateMethodData(List<String> methodNames, JsonNode valueNode) { List<MethodData> dataList = new ArrayList<>(); if (valueNode.isTextual()) { for (String methodName : methodNames) { dataList.add(new MethodData(methodName, String.class, valueNode.asText())); }//from w w w. j a va 2s .c o m } else if (valueNode.isNumber()) { for (String methodName : methodNames) { if (valueNode.isIntegralNumber()) { dataList.add(new MethodData(methodName, Long.TYPE, valueNode.asLong())); dataList.add(new MethodData(methodName, Long.class, valueNode.asLong())); dataList.add(new MethodData(methodName, Integer.TYPE, valueNode.asInt())); dataList.add(new MethodData(methodName, Integer.class, valueNode.asInt())); dataList.add(new MethodData(methodName, Short.TYPE, (short) valueNode.asInt())); dataList.add(new MethodData(methodName, Short.class, (short) valueNode.asInt())); } else { dataList.add(new MethodData(methodName, Double.TYPE, valueNode.asDouble())); dataList.add(new MethodData(methodName, Double.class, valueNode.asDouble())); dataList.add(new MethodData(methodName, Float.TYPE, valueNode.asDouble())); dataList.add(new MethodData(methodName, Float.class, valueNode.asDouble())); } } } else if (valueNode.isBoolean()) { for (String methodName : methodNames) { dataList.add(new MethodData(methodName, Boolean.TYPE, valueNode.asBoolean())); dataList.add(new MethodData(methodName, Boolean.class, valueNode.asBoolean())); } } // default for (String methodName : methodNames) { dataList.add(new MethodData(methodName, JsonNode.class, valueNode)); } return dataList; }
From source file:com.projity.field.FieldConverter.java
private FieldConverter() { instance = this; stringConverter = new StringConverter(false); compactStringConverter = new StringConverter(true); ConvertUtils.register(stringConverter, String.class); // Wrapper class ConvertUtils.register(new DateConverter(), Date.class); // Wrapper class ConvertUtils.register(new CalendarConverter(), GregorianCalendar.class); // Wrapper class ConvertUtils.register(new DurationConverter(), Duration.class); // Wrapper class ConvertUtils.register(new WorkConverter(), Work.class); // Wrapper class ConvertUtils.register(new MoneyConverter(), Money.class); // Wrapper class Converter longConverter = new LongConverter(); ConvertUtils.register(longConverter, Long.TYPE); // Native type ConvertUtils.register(longConverter, Long.class); // Wrapper class Converter doubleConverter = new DoubleConverter(); ConvertUtils.register(doubleConverter, Double.TYPE); // Native type ConvertUtils.register(doubleConverter, Double.class); // Wrapper class // short context converters HashMap<Class, Converter> compactMap = new HashMap<Class, Converter>(); contextMaps.put(COMPACT_CONVERTER_CONTEXT, compactMap); compactMap.put(String.class, compactStringConverter); // no need for duration or money as parsing is done in long form }
From source file:org.robobinding.util.ClassUtils.java
/** * <p>//from w w w .ja va2 s.c o m * Checks if one {@code Class} can be assigned to a variable of another * {@code Class}. * </p> * * <p> * Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method, this * method takes into account widenings of primitive classes and {@code null} * s. * </p> * * <p> * Primitive widenings allow an int to be assigned to a long, float or * double. This method returns the correct result for these cases. * </p> * * <p> * {@code Null} may be assigned to any reference type. This method will * return {@code true} if {@code null} is passed in and the toClass is * non-primitive. * </p> * * <p> * Specifically, this method tests whether the type represented by the * specified {@code Class} parameter can be converted to the type * represented by this {@code Class} object via an identity conversion * widening primitive or widening reference conversion. See * <em><a href="http://docs.oracle.com/javase/specs/">The Java Language Specification</a></em> * , sections 5.1.1, 5.1.2 and 5.1.4 for details. * </p> * * @param cls * the Class to check, may be null * @param toClass * the Class to try to assign into, returns false if null * @param autoboxing * whether to use implicit autoboxing/unboxing between primitives * and wrappers * @return {@code true} if assignment possible */ public static boolean isAssignable(Class<?> cls, final Class<?> toClass, final boolean autoboxing) { if (toClass == null) { return false; } // have to check for null, as isAssignableFrom doesn't if (cls == null) { return !toClass.isPrimitive(); } // autoboxing: if (autoboxing) { if (cls.isPrimitive() && !toClass.isPrimitive()) { cls = primitiveToWrapper(cls); if (cls == null) { return false; } } if (toClass.isPrimitive() && !cls.isPrimitive()) { cls = wrapperToPrimitive(cls); if (cls == null) { return false; } } } if (cls.equals(toClass)) { return true; } if (cls.isPrimitive()) { if (toClass.isPrimitive() == false) { return false; } if (Integer.TYPE.equals(cls)) { return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Long.TYPE.equals(cls)) { return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Boolean.TYPE.equals(cls)) { return false; } if (Double.TYPE.equals(cls)) { return false; } if (Float.TYPE.equals(cls)) { return Double.TYPE.equals(toClass); } if (Character.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Short.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Byte.TYPE.equals(cls)) { return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } // should never get here return false; } return toClass.isAssignableFrom(cls); }
From source file:org.jdto.util.ClassUtils.java
/** * <p>Checks if one/* w w w . ja va 2 s. c o m*/ * <code>Class</code> can be assigned to a variable of another * <code>Class</code>.</p> * * <p>Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method, * this method takes into account widenings of primitive classes and * <code>null</code>s.</p> * * <p>Primitive widenings allow an int to be assigned to a long, float or * double. This method returns the correct result for these cases.</p> * * <p><code>Null</code> may be assigned to any reference type. This method * will return * <code>true</code> if * <code>null</code> is passed in and the toClass is non-primitive.</p> * * <p>Specifically, this method tests whether the type represented by the * specified * <code>Class</code> parameter can be converted to the type represented by * this * <code>Class</code> object via an identity conversion widening primitive * or widening reference conversion. See <em><a * href="http://java.sun.com/docs/books/jls/">The Java Language * Specification</a></em>, sections 5.1.1, 5.1.2 and 5.1.4 for details.</p> * * @param cls the Class to check, may be null * @param toClass the Class to try to assign into, returns false if null * @param autoboxing whether to use implicit autoboxing/unboxing between * primitives and wrappers * @return * <code>true</code> if assignment possible * @since 2.5 */ public static boolean isAssignable(Class cls, Class toClass, boolean autoboxing) { if (toClass == null) { return false; } // have to check for null, as isAssignableFrom doesn't if (cls == null) { return !(toClass.isPrimitive()); } //autoboxing: if (autoboxing) { if (cls.isPrimitive() && !toClass.isPrimitive()) { cls = primitiveToWrapper(cls); if (cls == null) { return false; } } if (toClass.isPrimitive() && !cls.isPrimitive()) { cls = wrapperToPrimitive(cls); if (cls == null) { return false; } } } if (cls.equals(toClass)) { return true; } if (cls.isPrimitive()) { if (toClass.isPrimitive() == false) { return false; } if (Integer.TYPE.equals(cls)) { return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Long.TYPE.equals(cls)) { return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Boolean.TYPE.equals(cls)) { return false; } if (Double.TYPE.equals(cls)) { return false; } if (Float.TYPE.equals(cls)) { return Double.TYPE.equals(toClass); } if (Character.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Short.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Byte.TYPE.equals(cls)) { return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } // should never get here return false; } return toClass.isAssignableFrom(cls); }
From source file:pe.com.mmh.sisgap.utils.BasicDynaBean.java
/** * Return the value of a simple property with the specified name. * * @param name Name of the property whose value is to be retrieved * * @exception IllegalArgumentException if there is no property * of the specified name//from w w w.j a v a 2s. co m */ public Object get(String name) { // Return any non-null value for the specified property Object value = values.get(name); if (value != null) { return (value); } // Return a null value for a non-primitive property Class type = getDynaProperty(name).getType(); if (!type.isPrimitive()) { return (value); } // Manufacture default values for primitive properties if (type == Boolean.TYPE) { return (Boolean.FALSE); } else if (type == Byte.TYPE) { return (new Byte((byte) 0)); } else if (type == Character.TYPE) { return (new Character((char) 0)); } else if (type == Double.TYPE) { return (new Double((double) 0.0)); } else if (type == Float.TYPE) { return (new Float((float) 0.0)); } else if (type == Integer.TYPE) { return (new Integer((int) 0)); } else if (type == Long.TYPE) { return (new Long((int) 0)); } else if (type == Short.TYPE) { return (new Short((short) 0)); } else { return (null); } }
From source file:org.romaframework.core.schema.SchemaHelper.java
public static Object assignDefaultValueToLiteral(SchemaClass type) { Object value;//from www .j a v a 2 s . com if (type.isOfType(Integer.TYPE)) { value = Integer.valueOf(0); } else if (type.isOfType(Long.TYPE)) { value = Long.valueOf(0); } else if (type.isOfType(Short.TYPE)) { value = Short.valueOf((short) 0); } else if (type.isOfType(Byte.TYPE)) { value = Byte.valueOf((byte) 0); } else if (type.isOfType(Float.TYPE)) { value = Float.valueOf(0); } else if (type.isOfType(Double.TYPE)) { value = Double.valueOf(0); } else { value = null; } return value; }