public final class FieldUtils extends Object
Field shorthand utility class mainly used to collect fields from classes meeting certain restrictions/requirements.
With this utility class you can perform field lookups, by combining lookup restriction criteria.
Example
"find all fields on a class Apple, not looking at its super classes, which should be protected, have a getter method, but not a setter
method"
FieldUtils.collectFields(Apple.class, Apple.class, EnumSet.of(Visibility.PROTECTED),
EnumSet.of(BeanRestriction.YES_GETTER, BeanRestriction.NO_SETTER));
collectFields(Class, Class, EnumSet, EnumSet)| Modifier and Type | Class and Description |
|---|---|
static class |
FieldUtils.BeanRestriction
Indicates whether a field needs a Bean setter or getter, exactly none or any combination thereof.
|
static class |
FieldUtils.Visibility
Determines what visibility modifiers a field is allowed to have in
collectFields(Class, Class, EnumSet, EnumSet). |
| Constructor and Description |
|---|
FieldUtils() |
| Modifier and Type | Method and Description |
|---|---|
static @NotNull Map<Class<?>,List<FieldWrapper>> |
collectFields(Class<?> _class,
Class<?> boundaryMarker,
EnumSet<FieldUtils.Visibility> visibility,
EnumSet<FieldUtils.BeanRestriction> beanRestrictions)
Returns a pool of
Field wrappers including optional relevant setter/getter methods, collected from the given class tested
against the given visibility and Bean restriction requirements. |
@NotNull public static @NotNull Map<Class<?>,List<FieldWrapper>> collectFields(Class<?> _class, Class<?> boundaryMarker, EnumSet<FieldUtils.Visibility> visibility, EnumSet<FieldUtils.BeanRestriction> beanRestrictions)
Field wrappers including optional relevant setter/getter methods, collected from the given class tested
against the given visibility and Bean restriction requirements.
The returned fields are mapped against the classes they were found on, since field names can be declared multiple times with the same name.
_class - The class (and chain) to harvest fields from.boundaryMarker - The last class> or interface implementing class that fields are collected from. Can
be used to prevent finding fields on a supper class.visibility - A set of visibility requirements (ie. FieldUtils.Visibility.PROTECTED indicates a field is allowed to have
protected visibility).beanRestrictions - A set of Bean restriction requirements indicating a field should or shouldn't have a setter, getter or both.meetsVisibilityRequirements(Field, EnumSet),
resolveBeanProperty(Field, EnumSet)Copyright © 2018. All rights reserved.