Enum FieldSupport
- All Implemented Interfaces:
Serializable
,Comparable<FieldSupport>
Utility methods for fields access.
- Author:
- Joel Costigliola
-
Enum Constant Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic FieldSupport
Returns the instance dedicated to comparison of fields.static FieldSupport
Returns the instance dedicated to extraction of fields.<T> T
fieldValue
(String fieldName, Class<T> fieldClass, Object target) Return the value of field from a target object.<T> List
<T> fieldValues
(String fieldName, Class<T> fieldClass, Iterable<?> target) <T> List
<T> fieldValues
(String fieldName, Class<T> fieldClass, Object[] target) fieldValues
(String fieldName, Iterable<?> target) boolean
isAllowedToRead
(Field field) boolean
void
setAllowUsingPrivateFields
(boolean allowUsingPrivateFields) Sets whether the use of private fields is allowed.static FieldSupport
Returns the enum constant of this type with the specified name.static FieldSupport[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
EXTRACTION
-
EXTRACTION_OF_PUBLIC_FIELD_ONLY
-
COMPARISON
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
extraction
Returns the instance dedicated to extraction of fields.- Returns:
- the instance dedicated to extraction of fields.
-
comparison
Returns the instance dedicated to comparison of fields.- Returns:
- the instance dedicated to comparison of fields.
-
isAllowedToUsePrivateFields
public boolean isAllowedToUsePrivateFields() -
setAllowUsingPrivateFields
public void setAllowUsingPrivateFields(boolean allowUsingPrivateFields) Sets whether the use of private fields is allowed. If a method tries to extract/compare private fields and is not allowed to, it will fail with an exception.- Parameters:
allowUsingPrivateFields
- allow private fields extraction and comparison. Defaulttrue
.
-
fieldValues
Returns a
containing the values of the given field name, from the elements of the givenList
. If the givenIterable
Iterable
is empty ornull
, this method will return an emptyList
. This method supports nested fields (e.g. "address.street.number").- Type Parameters:
T
- the type of the extracted elements.- Parameters:
fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate fornull
or empty.fieldClass
- the expected type of the given field.target
- the givenIterable
.- Returns:
- an
Iterable
containing the values of the given field name, from the elements of the givenIterable
. - Throws:
IntrospectionError
- if an element in the givenIterable
does not have a field with a matching name.
-
fieldValues
-
fieldValues
Returns a
containing the values of the given field name, from the elements of the givenList
. If the givenIterable
Iterable
is empty ornull
, this method will return an emptyList
. This method supports nested fields (e.g. "address.street.number").- Type Parameters:
T
- the type of the extracted elements.- Parameters:
fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate fornull
or empty.fieldClass
- the expected type of the given field.target
- the givenIterable
.- Returns:
- an
Iterable
containing the values of the given field name, from the elements of the givenIterable
. - Throws:
IntrospectionError
- if an element in the givenIterable
does not have a field with a matching name.
-
fieldValue
Return the value of field from a target object. The field must not be static or synthetic (since 3.19.0).Return null if field is nested and one of the nested value is null, ex :
fieldValue(race.name, String.class, frodo); // will return null if frodo.race is null
- Type Parameters:
T
- the type of the extracted value.- Parameters:
fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate fornull
or empty.fieldClass
- type of fieldtarget
- the given object- Returns:
- the value of the given field name
- Throws:
IntrospectionError
- if the given target does not have a field with a matching name.
-
isAllowedToRead
-