當前位置: 首頁>>代碼示例>>Java>>正文


Java FieldUtils.getAllFieldsList方法代碼示例

本文整理匯總了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;
}
 
開發者ID:darkevilmac,項目名稱:CreeperKiller,代碼行數:25,代碼來源:HammerKiller.java

示例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;
}
 
開發者ID:jonfryd,項目名稱:tifoon,代碼行數:18,代碼來源:ReflectionObjectTreeAware.java

示例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));
}
 
開發者ID:venusdrogon,項目名稱:feilong-core,代碼行數:48,代碼來源:FieldUtil.java

示例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;
}
 
開發者ID:terrestris,項目名稱:shogun2,代碼行數:33,代碼來源:EntityUtil.java

示例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();
}
 
開發者ID:sliechti,項目名稱:feedrdr,代碼行數:9,代碼來源:FeedAppConfig.java

示例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);
}
 
開發者ID:tangr1,項目名稱:mybatis-easy-mapper,代碼行數:62,代碼來源:SQLProvider.java


注:本文中的org.apache.commons.lang3.reflect.FieldUtils.getAllFieldsList方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。