当前位置: 首页>>代码示例>>Java>>正文


Java FieldUtils.getAllFields方法代码示例

本文整理汇总了Java中org.apache.commons.lang3.reflect.FieldUtils.getAllFields方法的典型用法代码示例。如果您正苦于以下问题:Java FieldUtils.getAllFields方法的具体用法?Java FieldUtils.getAllFields怎么用?Java FieldUtils.getAllFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang3.reflect.FieldUtils的用法示例。


在下文中一共展示了FieldUtils.getAllFields方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeAllFieldsOfType

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static <T> void writeAllFieldsOfType(Object o, T t, Class<T> c) throws IllegalAccessException
{
	boolean wroteSomething = false;

       for (Field f : FieldUtils.getAllFields(o.getClass()))
	{
       	if (!Modifier.isStatic(f.getModifiers()) && f.getType().equals(c))
       	{
       		FieldUtils.writeField(f, o, t, true);
       		wroteSomething = true;
       	}
	}

       if (!wroteSomething)
       	throw new IllegalAccessException();
}
 
开发者ID:orbwoi,项目名称:UniversalRemote,代码行数:17,代码来源:InjectionHandler.java

示例2: validate

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
private void validate(Object object, Class<?> clazz) throws Exception {
    for (Field field : FieldUtils.getAllFields(clazz)) {
        int modifiers = field.getModifiers();

        // Ignore static fields
        if (Modifier.isStatic(modifiers)) {
            continue;
        }

        assertTrue("Field is private", Modifier.isPrivate(modifiers));
        assertTrue("Field is final", Modifier.isFinal(modifiers));

        Method getter = clazz.getMethod(getterName(field.getName()));
        assertNotNull("Getter exists", getter);
        assertTrue("Getter is public", Modifier.isPublic(getter.getModifiers()));
    }

    // Check that hashCode, toString and equals are defined
    assertNotNull(clazz.getDeclaredMethod("hashCode").invoke(object));
    assertNotNull(clazz.getDeclaredMethod("toString").invoke(object));
    assertTrue((Boolean) clazz.getDeclaredMethod("equals", Object.class).invoke(object, object));
}
 
开发者ID:carlanton,项目名称:mpd-tools,代码行数:23,代码来源:DataTypeTest.java

示例3: writeAllStaticFieldsOfType

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes" })
public static <T> void writeAllStaticFieldsOfType(Class d, T t, Class c) throws IllegalAccessException
{
	boolean wroteSomething = false;

       for (Field f : FieldUtils.getAllFields(d))
	{
       	if (Modifier.isStatic(f.getModifiers()) && f.getType().equals(c))
       	{
       		FieldUtils.writeStaticField(f, t, true);
       		wroteSomething = true;
       	}
	}

       if (!wroteSomething)
       	throw new IllegalAccessException();
}
 
开发者ID:orbwoi,项目名称:UniversalRemote,代码行数:18,代码来源:InjectionHandler.java

示例4: buildFieldMap

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
private void buildFieldMap(Map<String, MappingBean> fieldMap, Set<String> fields, Class<?> sourceClass, Class<?> destinationClass){
    for(Field field: FieldUtils.getAllFields(sourceClass)){
        fields.add(field.getName());
        Optional<FieldMapping> optional = this.getFieldMapping(field, this.destinationClass);
        if(optional.isPresent()){
            FieldMapping fieldMapping = optional.get();
            MappingBean bean = new MappingBean();
            bean.setSourceField(field.getName());
            bean.setMappedField(Strings.isNullOrEmpty(fieldMapping.value())?field.getName():fieldMapping.value());
            bean.setMappedIn(fieldMapping.mappedIn());
            bean.setMappedOut(fieldMapping.mappedOut());
            bean.setIgnore(fieldMapping.ignore());
            fieldMap.put(field.getName(),bean);
        }
    }
}
 
开发者ID:yjy8749,项目名称:orika-mapper,代码行数:17,代码来源:MappingBuilder.java

示例5: prepareFields

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
private void prepareFields() {
    viewsForInjection = new ArrayList<>();
    for (Field field : FieldUtils.getAllFields(this.getClass())) {
        if (field.isAnnotationPresent(InjectView.class)) {
            viewsForInjection.add(new ViewMembersInjector(field, field.getAnnotation(InjectView.class)));
        }
    }
}
 
开发者ID:SIGLUS,项目名称:lmis-moz-mobile,代码行数:9,代码来源:BaseViewHolder.java

示例6: getBXMLFieldValues

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static Map<String, Object> getBXMLFieldValues(Bindable obj) throws IllegalAccessException {
    Map<String, Object> result = new HashMap<>();
    Class<?> type = obj.getClass();
    Field[] allFields = FieldUtils.getAllFields(type);

    if (ArrayUtils.isNotEmpty(allFields)) {
        for (Field field : allFields) {
            BXML bxmlAnnotation = field.getAnnotation(BXML.class);

            if (bxmlAnnotation != null) {
                String id = bxmlAnnotation.id();
                Object fieldValue = FieldUtils.readField(field, obj, true);

                if (StringUtils.isNotBlank(id)) {
                    result.put(id, fieldValue);
                } else {
                    result.put(field.getName(), fieldValue);
                }
            }
        }
    }

    return result;
}
 
开发者ID:moosbusch,项目名称:Lumpi,代码行数:25,代码来源:LumpiUtil.java

示例7: readFieldOfType

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T readFieldOfType(Object o, Class<T> t) throws IllegalAccessException
{

       for (Field f : FieldUtils.getAllFields(o.getClass()))
	{
       	if (!Modifier.isStatic(f.getModifiers()) && f.getType().equals(t))
       	{
       		return (T) FieldUtils.readField(f, o, true);
       	}
	}

       throw new IllegalAccessException();
}
 
开发者ID:orbwoi,项目名称:UniversalRemote,代码行数:15,代码来源:InjectionHandler.java

示例8: readParameterizedFieldOfType

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <C,T> C readParameterizedFieldOfType(Object o, Class<C> collection, Class<T> genertic) throws IllegalAccessException
{

       for (Field f : FieldUtils.getAllFields(o.getClass()))
	{
       	if (!Modifier.isStatic(f.getModifiers()) && f.getType().equals(collection) && f.getGenericType().equals(genertic))
       	{
       		return (C) FieldUtils.readField(f, o, true);
       	}
	}

       throw new IllegalAccessException();
}
 
开发者ID:orbwoi,项目名称:UniversalRemote,代码行数:15,代码来源:InjectionHandler.java

示例9: readStaticFieldOfType

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> T readStaticFieldOfType(Class c, Class<T> t) throws IllegalAccessException
{

       for (Field f : FieldUtils.getAllFields(c))
	{
       	if (Modifier.isStatic(f.getModifiers()) && f.getType().equals(t))
       	{
       		return (T) FieldUtils.readStaticField(f, true);
       	}
	}

       throw new IllegalAccessException();
}
 
开发者ID:orbwoi,项目名称:UniversalRemote,代码行数:15,代码来源:InjectionHandler.java

示例10: writeFieldOfType

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@SuppressWarnings({ })
public static <T> void writeFieldOfType(Object o, T t, Class<T> c) throws IllegalAccessException
{

       for (Field f : FieldUtils.getAllFields(o.getClass()))
	{
       	if (!Modifier.isStatic(f.getModifiers()) && f.getType().equals(c))
       	{
       		FieldUtils.writeField(f, o, t, true);
       		return;
       	}
	}

       throw new IllegalAccessException();
}
 
开发者ID:orbwoi,项目名称:UniversalRemote,代码行数:16,代码来源:InjectionHandler.java

示例11: writeStaticFieldOfType

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes" })
public static <T> void writeStaticFieldOfType(Class d, T t, Class<T> c) throws IllegalAccessException
{

       for (Field f : FieldUtils.getAllFields(d))
	{
       	if (Modifier.isStatic(f.getModifiers()) && f.getType().equals(c))
       	{
       		FieldUtils.writeStaticField(f, t, true);
       		return;
       	}
	}

       throw new IllegalAccessException();
}
 
开发者ID:orbwoi,项目名称:UniversalRemote,代码行数:16,代码来源:InjectionHandler.java

示例12: copyAllFieldsFrom

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static <T> void copyAllFieldsFrom(T dest, T origin, Class<T> c)
{
	for (Field f : FieldUtils.getAllFields(c))
	{
		if (!Modifier.isStatic(f.getModifiers()) && !Modifier.isFinal(f.getModifiers()))
		{
			copyField(f, dest, origin);
		}
	}
}
 
开发者ID:orbwoi,项目名称:UniversalRemote,代码行数:11,代码来源:InjectionHandler.java

示例13: copyAllPublicFieldsFrom

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static <T> void copyAllPublicFieldsFrom(T dest, T origin, Class<T> c)
{
	for (Field f : FieldUtils.getAllFields(c))
	{
		int modifiers = f.getModifiers();
		if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers))
		{
			copyField(f, dest, origin);
		}
	}
}
 
开发者ID:orbwoi,项目名称:UniversalRemote,代码行数:12,代码来源:InjectionHandler.java

示例14: copyAllFieldsFromEx

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static <T> void copyAllFieldsFromEx(T dest, T origin, Class<T> c)
{
	for (Field f : FieldUtils.getAllFields(c))
	{
		if (!Modifier.isStatic(f.getModifiers()))
		{
			copyField(f, dest, origin);
		}
	}
}
 
开发者ID:orbwoi,项目名称:UniversalRemote,代码行数:11,代码来源:InjectionHandler.java

示例15: determineRootAutoLinkingPaths

import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
 * Determines the root property paths relative to the given root object type against which to perform automatic
 * linking.
 *
 * <p>This will be determined based on the presence of {@link Link} annotations on the given root object type.
 * This method is invoked recursively as it walks the class structure looking for Link annotations. It uses the
 * path
 * and scanned arguments to keep track of how deep into the structure the scanning is and to prevent infinite
 * recursion.</p>
 *
 * @param rootObjectType the root object type from which to perform the scan for auto-linking paths
 * @param path the current property path relative to the original root object type at which the scan began, if null
 * then we are scanning from the root-most object type. Each recursive call of this method will append
 * a new property to this path
 * @param scanned used to track classes that have already been scanned and prevent infinite recursion
 * @return a set of property paths that should be auto linked
 */
protected Set<String> determineRootAutoLinkingPaths(Class<?> rootObjectType, String path, Set<Class<?>> scanned) {
    Set<String> autoLinkingPaths = new HashSet<String>();
    if (scanned.contains(rootObjectType)) {
        return autoLinkingPaths;
    } else {
        scanned.add(rootObjectType);
    }
    Link autoLink = AnnotationUtils.findAnnotation(rootObjectType, Link.class);
    if (autoLink != null && autoLink.cascade()) {
        autoLinkingPaths.addAll(assembleAutoLinkingPaths(path, autoLink));
    } else if (autoLink == null) {
        Field[] fields = FieldUtils.getAllFields(rootObjectType);
        for (Field field : fields) {
            autoLink = field.getAnnotation(Link.class);
            if (autoLink != null) {
                if (autoLink.cascade()) {
                    String fieldPath = appendToPath(path, field.getName());
                    autoLinkingPaths.addAll(assembleAutoLinkingPaths(fieldPath, autoLink));
                }
            } else {
                autoLinkingPaths.addAll(determineRootAutoLinkingPaths(field.getType(), appendToPath(path,
                        field.getName()), scanned));
            }
        }
    }
    return autoLinkingPaths;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:45,代码来源:UifServletRequestDataBinder.java


注:本文中的org.apache.commons.lang3.reflect.FieldUtils.getAllFields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。