本文整理汇总了Java中org.apache.commons.lang3.reflect.FieldUtils.getAllFieldsList方法的典型用法代码示例。如果您正苦于以下问题:Java FieldUtils.getAllFieldsList方法的具体用法?Java FieldUtils.getAllFieldsList怎么用?Java FieldUtils.getAllFieldsList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.reflect.FieldUtils
的用法示例。
在下文中一共展示了FieldUtils.getAllFieldsList方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createProxy
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static Object createProxy(Object realObject) {
try {
MethodInterceptor interceptor = new HammerKiller();
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(realObject.getClass());
enhancer.setCallbackType(interceptor.getClass());
Class classForProxy = enhancer.createClass();
Enhancer.registerCallbacks(classForProxy, new Callback[]{interceptor});
Object createdProxy = classForProxy.newInstance();
for (Field realField : FieldUtils.getAllFieldsList(realObject.getClass())) {
if (Modifier.isStatic(realField.getModifiers()))
continue;
realField.setAccessible(true);
realField.set(createdProxy, realField.get(realObject));
}
CreeperKiller.LOG.info("Removed HammerCore main menu hook, ads will no longer be displayed.");
return createdProxy;
} catch (Exception e) {
CreeperKiller.LOG.error("Failed to create a proxy for HammerCore ads, they will not be removed.", e);
}
return realObject;
}
示例2: traceObjectPath
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@Override
@Nullable
public final List<ObjectTreeAware> traceObjectPath(@NonNull final Object _objectToFind) {
for (final Field field : FieldUtils.getAllFieldsList(getClass())) {
try {
final List<ObjectTreeAware> result = findValue(FieldUtils.readField(this, field.getName(), true), _objectToFind);
if (result != null) {
return result;
}
} catch (IllegalAccessException _e) {
// safe to ignore
}
}
return null;
}
示例3: getAllFieldList
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* 获得 <code>klass</code> 排除某些 <code>excludeFieldNames</code> 之后的字段list.
*
* <h3>说明:</h3>
* <blockquote>
* <ol>
* <li>是所有字段的值(<b>不是属性</b>)</li>
* <li>自动过滤私有并且静态的字段,比如 LOGGER serialVersionUID</li>
* </ol>
* </blockquote>
*
* @param klass
* the klass
* @param excludeFieldNames
* 需要排除的field names,如果传递过来是null或者empty 那么不会判断
* @return 如果 <code>obj</code> 是null,抛出 {@link NullPointerException}<br>
* 如果 <code>excludeFieldNames</code> 是null或者empty,解析所有的field<br>
* 如果 {@link FieldUtils#getAllFieldsList(Class)} 是null或者empty,返回 {@link Collections#emptyList()}<br>
* 如果 <code>obj</code>没有字段或者字段都被参数 <code>excludeFieldNames</code> 排除掉了,返回 {@link Collections#emptyMap()}<br>
* @see FieldUtils#getAllFieldsList(Class)
* @since 1.7.1
*/
public static List<Field> getAllFieldList(final Class<?> klass,String...excludeFieldNames){
Validate.notNull(klass, "klass can't be null!");
//获得给定类的所有声明字段 {@link Field},包括所有的parents,包括 public/protect/private/inherited...
List<Field> fieldList = FieldUtils.getAllFieldsList(klass);
if (isNullOrEmpty(fieldList)){
return emptyList();
}
//---------------------------------------------------------------
Predicate<Field> excludeFieldPredicate = BeanPredicateUtil.containsPredicate("name", excludeFieldNames);
Predicate<Field> staticPredicate = new Predicate<Field>(){
@Override
public boolean evaluate(Field field){
int modifiers = field.getModifiers();
// 私有并且静态 一般是log 或者 serialVersionUID
boolean isStatic = Modifier.isStatic(modifiers);
String pattern = "[{}.{}],modifiers:[{}]{}";
LOGGER.trace(pattern, klass.getSimpleName(), field.getName(), modifiers, isStatic ? " [isStatic]" : EMPTY);
return isStatic;
}
};
return selectRejected(fieldList, PredicateUtils.orPredicate(excludeFieldPredicate, staticPredicate));
}
示例4: getFilterableOrRestrictableFieldNames
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Returns a list of fieldNames of the passed class that can be used to either
*
* <ul>
* <li>filter results with, see {@link validFieldNamesWithCastedValues}, or</li>
* <li>restrict output of queries, see {@link determineRestrictFields} </li>
* </ul>
*
* @param entityClass
* @return
*/
public static List<String> getFilterableOrRestrictableFieldNames(Class<?> entityClass) {
List<Field> allFields = FieldUtils.getAllFieldsList(entityClass);
List<String> restrictableFields = new ArrayList<String>();
for (Field field : allFields) {
final Class<?> fieldType = field.getType();
final String fieldName = field.getName();
final int fieldModifiers = field.getModifiers();
final boolean isPrimitiveOrWrapper = ClassUtils.isPrimitiveOrWrapper(fieldType);
final boolean isString = fieldType.equals(String.class);
final boolean isStatic = Modifier.isStatic(fieldModifiers);
final boolean isPrivate = Modifier.isPrivate(fieldModifiers);
// extract only non-static private fields that are primitive or
// primitive wrapper types or String
if((isPrimitiveOrWrapper || isString) && isPrivate && !isStatic) {
restrictableFields.add(fieldName);
}
}
return restrictableFields;
}
示例5: printAllFields
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static String printAllFields() throws Exception {
List<Field> fields = FieldUtils.getAllFieldsList(FeedAppConfig.class);
StringBuilder sb = new StringBuilder();
for (Field f : fields) {
sb.append(f.getName()).append("=[").append(FieldUtils.readStaticField(f)).append("] ");
}
return sb.toString();
}
示例6: initEntityNameMap
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
protected static synchronized void initEntityNameMap(Class<?> entityClass) {
if (entityTableMap.get(entityClass) != null) {
return;
}
EntityTable entityTable = new EntityTable();
entityTable.setName(getTableName(entityClass));
List<Field> fieldList = FieldUtils.getAllFieldsList(entityClass);
Set<EntityColumn> columnSet = new LinkedHashSet<>();
Set<EntityColumn> pkColumnSet = new LinkedHashSet<>();
Map<String, Reference> referenceMap = new HashMap<>();
List<String> innerJoins = new ArrayList<>();
List<String> orderBys = new ArrayList<>();
for (Field field : fieldList) {
if (field.isAnnotationPresent(Transient.class)) {
continue;
}
if (field.isAnnotationPresent(Reference.class)) {
referenceMap.put(field.getName(), field.getAnnotation(Reference.class));
continue;
}
EntityColumn entityColumn = getColumnFromField(field);
columnSet.add(entityColumn);
if (entityColumn.isId()) {
pkColumnSet.add(entityColumn);
}
}
entityTable.setEntityClassColumns(columnSet);
if (pkColumnSet.isEmpty()) {
fieldList.stream()
.filter(field -> !field.isAnnotationPresent(Transient.class)
&& !field.isAnnotationPresent(Reference.class)
&& field.getName().equalsIgnoreCase("id"))
.forEach(field -> pkColumnSet.add(getColumnFromField(field)));
}
entityTable.setEntityClassPKColumns(pkColumnSet);
StringJoiner stringJoiner = new StringJoiner(", ");
columnSet.forEach(column -> stringJoiner.add(entityTable.getName() + "." + column.getColumn()));
referenceMap.entrySet().forEach(entry -> {
String foreignTableName = getTableName(entry.getValue().referenceEntity());
stringJoiner.add(foreignTableName + "." +
CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getValue().referenceField()) +
" as " +
CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getKey()));
innerJoins.add(foreignTableName + " on " + entityTable.getName() + "." +
CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getValue().localOn()) +
" = " + foreignTableName + "." +
CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getValue().referenceOn()));
});
entityTable.setSelectColumns(stringJoiner.toString());
entityTable.setInnerJoins(innerJoins);
columnSet.stream()
.filter(column -> column.getOrderBy() != null)
.forEach(column -> orderBys.add(column.getColumn() + " " + column.getOrderBy()));
entityTable.setOrderBys(orderBys);
entityTableMap.put(entityClass, entityTable);
}