本文整理汇总了Java中org.apache.commons.lang3.ClassUtils.isPrimitiveOrWrapper方法的典型用法代码示例。如果您正苦于以下问题:Java ClassUtils.isPrimitiveOrWrapper方法的具体用法?Java ClassUtils.isPrimitiveOrWrapper怎么用?Java ClassUtils.isPrimitiveOrWrapper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.ClassUtils
的用法示例。
在下文中一共展示了ClassUtils.isPrimitiveOrWrapper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: objToString
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
public String objToString(Object value) {
final StringBuilder buf = new StringBuilder();
for (Field f : value.getClass().getDeclaredFields()) {
f.setAccessible(true);
try {
buf.append("\"" + f.getName() + "\": ");
if (ClassUtils.isPrimitiveOrWrapper(value.getClass()) || value instanceof String) {
buf.append("\"" + value + "\"");
} else {
buf.append(valueToString(f.get(value)));
}
buf.append(", ");
} catch (IllegalArgumentException | IllegalAccessException e) {
// Silently ignore errors
e.printStackTrace();
}
}
buf.replace(buf.length() - 2, buf.length(), "");
return buf.toString();
}
示例2: listToString
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
public String listToString(Collection<?> list) {
final StringBuilder buf = new StringBuilder();
buf.append("'[");
if (!list.isEmpty()) {
for (Object o : list) {
if (ClassUtils.isPrimitiveOrWrapper(o.getClass()) || o instanceof String) {
buf.append("\"" + o + "\"");
} else {
buf.append(valueToString(o));
}
buf.append(", ");
}
buf.replace(buf.length() - 2, buf.length(), "");
}
buf.append("]'");
return buf.toString();
}
示例3: mapToString
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
public String mapToString(Map<?, ?> map) {
final StringBuilder buf = new StringBuilder();
buf.append("{");
if (!map.isEmpty()) {
for (Entry<?, ?> o : map.entrySet()) {
final Object v = o.getValue();
if (v != null) {
buf.append("'" + o.getKey() + "': ");
if (ClassUtils.isPrimitiveOrWrapper(v.getClass()) || v instanceof String) {
buf.append("'" + v + "'");
} else {
buf.append(valueToString(v));
}
buf.append(", ");
}
}
buf.replace(buf.length() - 2, buf.length(), "");
}
buf.append("}");
return buf.toString();
}
示例4: toString
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
@Override
public String toString() {
class BusinessObjectToStringBuilder extends ReflectionToStringBuilder {
private BusinessObjectToStringBuilder(Object object) {
super(object);
}
@Override
public boolean accept(Field field) {
// ignore printing out byte arrays in toString methods
if (byte[].class.isAssignableFrom(field.getType())) {
return false;
}
return String.class.isAssignableFrom(field.getType())
|| ClassUtils.isPrimitiveOrWrapper(field.getType());
}
}
return new BusinessObjectToStringBuilder(this).toString();
}
示例5: getBeanFieldsRecursively
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
public static Set<String> getBeanFieldsRecursively(Class<?> clazz, String prefix) {
Set<String> result = new TreeSet<>();
prefix = prefix.length() == 0 ? prefix : prefix + ".";
while (clazz != null) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
String fieldName = prefix + field.getName();
Class<?> fieldType = field.getType();
result.add(fieldName);
if (!ClassUtils.isPrimitiveOrWrapper(fieldType))
result.addAll(getBeanFieldsRecursively(fieldType, fieldName));
}
clazz = clazz.getSuperclass();
}
return result;
}
示例6: isJavaType
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* Check if the given class is a Java type
*
* @param type A class
* @return True when the property type is a Java type, else False
*/
public static boolean isJavaType(Class<?> type) {
return (ClassUtils.isPrimitiveOrWrapper(type)
|| Class.class.equals(type)
|| String.class.equals(type)
|| Collection.class.isAssignableFrom(type)
|| Void.class.isAssignableFrom(type));
}
示例7: isTerminalType
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private static boolean isTerminalType(Class type) {
return ClassUtils.isPrimitiveOrWrapper(type)
|| type.isEnum()
|| Date.class.isAssignableFrom(type)
|| String.class.equals(type)
|| Object.class.equals(type);
}
示例8: valueToString
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
public String valueToString(Object value) {
if (value == null) {
return "";
}
final Class<?> vClass = value.getClass();
String str;
if (Collection.class.isAssignableFrom(vClass)) {
str = listToString((Collection<?>) value);
} else if (Map.class.isAssignableFrom(vClass)) {
str = mapToString((Map<?, ?>) value);
} else if (ClassUtils.isPrimitiveOrWrapper(vClass) || value instanceof String || vClass.isEnum()) {
str = value.toString();
// Use double backslash because of YAML syntax
str = str.replace("\\", "\\\\");
// Escape quotes
str = str.replace("\"", "\\\"");
// Quote variables with spaces
if (str.contains(" ")) {
str = "\"" + str + "\"";
}
} else {
str = objToString(value);
}
return str;
}
示例9: readFieldsAsMap
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* 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: getObjectMap
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
public static Map<String, Object> getObjectMap(Object o) {
if (ClassUtils.isPrimitiveOrWrapper(o.getClass()) || (o instanceof String)) {
Map<String, Object> objectMap = new HashMap<String, Object>();
objectMap.put("fake_var_" + o.getClass().getName().replace('.', '_'), o);
return objectMap;
} else {
return getAllVars(o, 0, "");
}
}
示例11: printDefaultValue
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private void printDefaultValue( StringBuilder c, Object pfield, TLine line ) {
if( !map.ignoreDefaultValue() ) {
c.append( "acc.accept( " );
if( ClassUtils.isPrimitiveOrWrapper( pfield.getClass() ) ) c.append( pfield );
else map.function( c, line.function, () -> c.append( "\"" ).append( pfield ).append( "\"" ) );
c.append( " );\n" );
} else c.append( "{}\n" );
}
示例12: isPrimitive
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private boolean isPrimitive(Class clazz) {
return clazz == String.class || ClassUtils.isPrimitiveOrWrapper(clazz) || LocalDate.class.getPackage().equals(clazz
.getPackage()) || clazz.isEnum();
}
示例13: isPrimitive
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
@Override
public boolean isPrimitive() {
return ClassUtils.isPrimitiveOrWrapper(clazz) || clazz.isAssignableFrom(String.class);
}
示例14: isSupportedType
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private static boolean isSupportedType(Class<?> clazz) {
return !(ClassUtils.isPrimitiveOrWrapper(clazz) || clazz == Object.class || Map.class.isAssignableFrom(clazz));
}
示例15: isSimple
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private boolean isSimple(Class<?> type) {
return type == String.class || type == Date.class || Enum.class.isAssignableFrom(type) || ClassUtils.isPrimitiveOrWrapper(type);
}