org.apache.commons.lang3.ClassUtils#isPrimitiveOrWrapper ( )源码实例Demo

下面列出了org.apache.commons.lang3.ClassUtils#isPrimitiveOrWrapper ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: servicecomb-java-chassis   文件: SwaggerUtils.java
public static boolean isBean(Type type) {
  if (type == null) {
    return false;
  }

  JavaType javaType = TypeFactory.defaultInstance().constructType(type);
  if (javaType.isContainerType() || javaType.isEnumType()) {
    return false;
  }

  Class<?> cls = javaType.getRawClass();
  if (ClassUtils.isPrimitiveOrWrapper(cls)) {
    return false;
  }

  return (cls != String.class
      && cls != Date.class
      && cls != LocalDate.class
      && cls != byte[].class
      && cls != File.class
      && !cls.getName().equals("org.springframework.web.multipart.MultipartFile")
      && !Part.class.isAssignableFrom(cls));
}
 
public static boolean needConvert(Object obj, JavaType invocationTimeType) {
  if (obj == null || ClassUtils.isPrimitiveOrWrapper(obj.getClass()) || invocationTimeType.isPrimitive()
      || ProtoConst.OBJECT_TYPE.equals(invocationTimeType)) {
    return false;
  }

  if (obj.getClass() == invocationTimeType.getRawClass()) {
    return false;
  }

  if (invocationTimeType.getRawClass().isAssignableFrom(obj.getClass())) {
    if (invocationTimeType.getContentType() == null) {
      return false;
    }
  }

  return true;
}
 
源代码3 项目: incubator-gobblin   文件: GsonInterfaceAdapter.java
@Override
public <R> TypeAdapter<R> create(Gson gson, TypeToken<R> type) {
  if (ClassUtils.isPrimitiveOrWrapper(type.getRawType()) || type.getType() instanceof GenericArrayType
      || CharSequence.class.isAssignableFrom(type.getRawType())
      || (type.getType() instanceof ParameterizedType && (Collection.class.isAssignableFrom(type.getRawType())
          || Map.class.isAssignableFrom(type.getRawType())))) {
    // delegate primitives, arrays, collections, and maps
    return null;
  }
  if (!this.baseClass.isAssignableFrom(type.getRawType())) {
    // delegate anything not assignable from base class
    return null;
  }
  TypeAdapter<R> adapter = new InterfaceAdapter<>(gson, this, type);
  return adapter;
}
 
源代码4 项目: DataDefender   文件: TypeConverter.java
private static int getConversionScore(Class<?> from, Class<?> to) {
    if (from.equals(to)) {
        return Integer.MAX_VALUE;
    } else if (ClassUtils.isAssignable(from, to)) {
        return Integer.MAX_VALUE - 1;
    } else if (String.class.equals(to)) {
        return Integer.MAX_VALUE - 2;
    } else if (ClassUtils.isPrimitiveOrWrapper(to) && String.class.isAssignableFrom(from)) {
        return Integer.MAX_VALUE - 3 - primitiveOrder.indexOf(to);
    }
    List<Class<?>> ordered = buildOrderedListForType(to);
    if (ordered.contains(from)) {
        return Integer.MAX_VALUE - 100 - ordered.indexOf(from);
    }
    int ind = 0;
    for (Class<?> conv : ordered) {
        ++ind;
        if (isConvertible(conv, to)) {
            return Integer.MAX_VALUE - 200 - ind;
        }
    }
    return Integer.MIN_VALUE;
}
 
源代码5 项目: DataDefender   文件: TypeConverter.java
/**
 * Converts the passed value to the passed type if possible.
 *
 * Conversion is performed in the following order:
 *  - Returned as-is if the value is of the same type or a sub-class of the
 *    type.
 *  - If type is java.lang.String, call toString on value and return it.
 *  - If value is a primitive, primitive wrapper, or String, and type
 *    represents one of those as well, an attempt is made to convert from/to
 *    as needed.
 *  - Otherwise, look for a constructor in the passed type that accepts a
 *    single argument of:
 *    o value itself (as its type or an interface/superclass)
 *    o A String argument, in which case toString is called on value
 *    o If value is primitive, the primitive type or it's wrapper
 *    o If value is a String, a primitive or wrapper argument
 *
 * @param value
 * @param type
 * @return
 */
public static Object convert(Object value, Class<?> type)
    throws InstantiationException,
    IllegalAccessException,
    IllegalArgumentException,
    InvocationTargetException {
    if (ClassUtils.isAssignable(value.getClass(), type)) {
        return value;
    } else if (String.class.equals(type)) {
        return value.toString();
    } else if (ClassUtils.isPrimitiveOrWrapper(type) && value instanceof String) {
        return ConvertUtils.convert(value, type);
    }
    Constructor<?> constr = getConvertibleConstructor(value.getClass(), type);
    Class<?> pt = (constr != null && constr.getParameterCount() > 0) ? constr.getParameterTypes()[0] : null;
    if (!ClassUtils.isAssignable(value.getClass(), pt)) {
        if (pt != null && ClassUtils.isAssignable(String.class, pt)) {
            return constr.newInstance(value.toString());
        } else if (pt != null && ClassUtils.isPrimitiveOrWrapper(pt) && value instanceof String) {
            return constr.newInstance(ConvertUtils.convert(value, pt));
        }
        // try anyway...
    }

    return constr.newInstance(value);
}
 
源代码6 项目: rice   文件: BusinessObjectBase.java
@Override
public String toString() {
       class BusinessObjectToStringBuilder extends ReflectionToStringBuilder {

           private BusinessObjectToStringBuilder(Object object) {
               super(object);
           }

           @Override
           public boolean accept(Field field) {
               return String.class.isAssignableFrom(field.getType())
                       || ClassUtils.isPrimitiveOrWrapper(field.getType());
           }

       }

       return new BusinessObjectToStringBuilder(this).toString();
   }
 
源代码7 项目: loc-framework   文件: LocOkHttpClient.java
private boolean isPrimitiveType(Type type) {
  if (type instanceof Class) {
    Class clazz = (Class) type;
    if (ClassUtils.isPrimitiveOrWrapper(clazz) || ClassUtils
        .isAssignable(clazz, String.class)) {
      return true;
    }
  }
  return false;
}
 
源代码8 项目: ctsms   文件: IndexResource.java
private static boolean isTerminalType(Class<?> type) {
	return ClassUtils.isPrimitiveOrWrapper(type)
			|| type.isEnum()
			|| Date.class.isAssignableFrom(type)
			|| String.class.equals(type)
			|| Object.class.equals(type);
}
 
源代码9 项目: confucius-commons   文件: ReflectionUtils.java
/**
 * Read fields value as {@link Map}
 *
 * @param object
 *         object to be read
 * @return fields value as {@link Map}
 */
@Nonnull
public static Map<String, Object> readFieldsAsMap(Object object) {
    Map<String, Object> fieldsAsMap = Maps.newLinkedHashMap();
    Class<?> type = object.getClass();
    Field[] fields = type.getDeclaredFields();
    for (Field field : fields) {

        if (Modifier.isStatic(field.getModifiers())) { // To filter static fields
            continue;
        }

        field.setAccessible(true);

        try {
            String fieldName = field.getName();
            Object fieldValue = field.get(object);
            if (fieldValue != null) {
                Class<?> fieldValueType = fieldValue.getClass();
                if (ClassUtils.isPrimitiveOrWrapper(fieldValueType)) {
                } else if (fieldValueType.isArray()) {
                    fieldValue = toList(fieldValue);
                } else if ("java.lang".equals(fieldValueType.getPackage().getName())) {

                } else {
                    fieldValue = readFieldsAsMap(fieldValue);
                }
            }
            fieldsAsMap.put(fieldName, fieldValue);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    return fieldsAsMap;
}
 
源代码10 项目: Poseidon   文件: AbstractServiceClient.java
protected String encodeUrl(Object url) throws JsonProcessingException {
    if (url == null) {
        return "";
    }

    if (url instanceof String) {
        return encodeUrl((String) url);
    } else if (ClassUtils.isPrimitiveOrWrapper(url.getClass()) || url.getClass().isEnum()) {
        return String.valueOf(url);
    } else {
        return encodeUrl(objectMapper.writeValueAsString(url));
    }
}
 
源代码11 项目: DataDefender   文件: TypeConverter.java
/**
 * Returns true if an object of type "from" can be converted to type "to" by
 * the 'convert' method.
 *
 * @param from
 * @param to
 * @return
 */
public static boolean isConvertible(Class<?> from, Class<?> to) {
    if (ClassUtils.isAssignable(from, to) || String.class.equals(to)) {
        return true;
    } else if (ClassUtils.isPrimitiveOrWrapper(from) && String.class.isAssignableFrom(from)) {
        return true;
    }
    return (getConvertibleConstructor(from, to) != null);
}
 
源代码12 项目: DataDefender   文件: TypeConverter.java
private static List<Class<?>> buildOrderedListForType(Class<?> from) {
    List<Class<?>> list = new ArrayList<>();
    list.add(from);
    if (ClassUtils.isPrimitiveOrWrapper(from)) {
        list.add(from.isPrimitive() ? ClassUtils.primitiveToWrapper(from) : ClassUtils.wrapperToPrimitive(from));
    }
    if (String.class.equals(from)) {
        list.addAll(primitiveOrder);
    } else {
        list.add(String.class);
    }
    return list;
}
 
源代码13 项目: ob1k   文件: MemcachedClientBuilder.java
/**
 * Create a client builder for MessagePack values.
 * @return The builder
 */
public static <T> MemcachedClientBuilder<T> newMessagePackClient(final MessagePack messagePack, final Class<T> valueType) {
  if (!ClassUtils.isPrimitiveOrWrapper(valueType)) {
    messagePack.register(valueType);
  }
  return newClient(new MessagePackTranscoder<>(messagePack, valueType));
}
 
源代码14 项目: minnal   文件: PropertyUtil.java
/**
 * Check if the given type represents a "simple" value type:
 * a primitive, a String or other CharSequence, a Number, a Date,
 * a URI, a URL, a Locale or a Class.
 * 
 * @param clazz the type to check
 * @return whether the given type represents a "simple" value type
 */
public static boolean isSimpleValueType(Class<?> clazz) {
	return ClassUtils.isPrimitiveOrWrapper(clazz) || clazz.isEnum() ||
			CharSequence.class.isAssignableFrom(clazz) ||
			Number.class.isAssignableFrom(clazz) ||
			Date.class.isAssignableFrom(clazz) ||
			clazz.equals(URI.class) || clazz.equals(URL.class) ||
			clazz.equals(Locale.class) || clazz.equals(Class.class) || 
			clazz.equals(Serializable.class) || clazz.equals(Timestamp.class);
}
 
源代码15 项目: crnk-framework   文件: ActivitiResourceMapper.java
private boolean isPrimitive(Class clazz) {
	return clazz == String.class || ClassUtils.isPrimitiveOrWrapper(clazz) || LocalDate.class.getPackage().equals(clazz
			.getPackage()) || clazz.isEnum() || clazz == UUID.class;
}
 
源代码16 项目: glitr   文件: ReflectionUtil.java
private static boolean isSupportedType(Class<?> clazz) {
    return !(ClassUtils.isPrimitiveOrWrapper(clazz) || clazz == Object.class || Map.class.isAssignableFrom(clazz));
}
 
源代码17 项目: syncope   文件: ConnConfPropertyListView.java
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void populateItem(final ListItem<ConnConfProperty> item) {
    final ConnConfProperty property = item.getModelObject();

    final String label = StringUtils.isBlank(property.getSchema().getDisplayName())
            ? property.getSchema().getName() : property.getSchema().getDisplayName();

    final FieldPanel<? extends Serializable> field;
    boolean required = false;
    boolean isArray = false;

    if (property.getSchema().isConfidential()
            || IdMConstants.GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType())
            || IdMConstants.GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) {

        field = new AjaxPasswordFieldPanel("panel", label, new Model<>(), false);
        ((PasswordTextField) field.getField()).setResetPassword(false);

        required = property.getSchema().isRequired();
    } else {
        Class<?> propertySchemaClass;
        try {
            propertySchemaClass = ClassUtils.getClass(property.getSchema().getType());
            if (ClassUtils.isPrimitiveOrWrapper(propertySchemaClass)) {
                propertySchemaClass = ClassUtils.primitiveToWrapper(propertySchemaClass);
            }
        } catch (ClassNotFoundException e) {
            LOG.error("Error parsing attribute type", e);
            propertySchemaClass = String.class;
        }

        if (ClassUtils.isAssignable(Number.class, propertySchemaClass)) {
            @SuppressWarnings("unchecked")
            Class<Number> numberClass = (Class<Number>) propertySchemaClass;
            field = new AjaxSpinnerFieldPanel.Builder<>().build("panel", label, numberClass, new Model<>());
            required = property.getSchema().isRequired();
        } else if (ClassUtils.isAssignable(Boolean.class, propertySchemaClass)) {
            field = new AjaxCheckBoxPanel("panel", label, new Model<>());
        } else {
            field = new AjaxTextFieldPanel("panel", label, new Model<>());
            required = property.getSchema().isRequired();
        }

        if (propertySchemaClass.isArray()) {
            isArray = true;
        }
    }

    field.setIndex(item.getIndex());
    field.setTitle(property.getSchema().getHelpMessage(), true);

    final AbstractFieldPanel<? extends Serializable> fieldPanel;
    if (isArray) {
        final MultiFieldPanel multiFieldPanel = new MultiFieldPanel.Builder(
                new PropertyModel<>(property, "values")).setEventTemplate(true).build("panel", label, field);
        item.add(multiFieldPanel);
        fieldPanel = multiFieldPanel;
    } else {
        setNewFieldModel(field, property.getValues());
        item.add(field);
        fieldPanel = field;
    }

    if (required) {
        fieldPanel.addRequiredLabel();
    }

    if (withOverridable) {
        fieldPanel.showExternAction(addCheckboxToggle(property));
    }
}
 
源代码18 项目: feilong-core   文件: PropertyUtil.java
/**
 * 一般自定义的command 里面 就是些 string int,list map等对象.
 * 
 * <p>
 * 这些我们过滤掉,只取类型是 findedClassType的
 * </p>
 * 
 * @param obj
 *            the obj
 * @return true, if checks if is can find type
 * @since 1.6.3
 */
private static boolean isDonotSupportFindType(Object obj){
    //一般自定义的command 里面 就是些 string int,list map等对象
    //这些我们过滤掉,只取类型是 findedClassType的
    return ClassUtils.isPrimitiveOrWrapper(obj.getClass())//
                    || ClassUtil.isInstanceAnyClass(obj, CharSequence.class, Collection.class, Map.class);
}
 
源代码19 项目: metron   文件: KafkaEmitter.java
/**
 * The result of a profile's triage expressions must be a string or primitive type.
 *
 * This ensures that the value can be easily serialized and appended to a message destined for Kafka.
 *
 * @param value The value of a triage expression.
 * @return True, if the type of the value is valid.
 */
private boolean isValidType(Object value) {
  return value != null && (value instanceof String || ClassUtils.isPrimitiveOrWrapper(value.getClass()));
}