本文整理匯總了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);
}