public enum FieldSupport extends java.lang.Enum<FieldSupport>
Enum Constant and Description |
---|
COMPARISON |
EXTRACTION |
EXTRACTION_OF_PUBLIC_FIELD_ONLY |
Modifier and Type | Field and Description |
---|---|
private boolean |
allowUsingPrivateFields |
private static java.lang.String |
SEPARATOR |
Modifier and Type | Method and Description |
---|---|
static FieldSupport |
comparison()
Returns the instance dedicated to comparison of fields.
|
static FieldSupport |
extraction()
Returns the instance dedicated to extraction of fields.
|
<T> T |
fieldValue(java.lang.String fieldName,
java.lang.Class<T> fieldClass,
java.lang.Object target)
Return the value of field from a target object.
|
<T> java.util.List<T> |
fieldValues(java.lang.String fieldName,
java.lang.Class<T> fieldClass,
java.lang.Iterable<?> target)
Returns a
containing the values of the given field name, from the elements of the given
. |
<T> java.util.List<T> |
fieldValues(java.lang.String fieldName,
java.lang.Class<T> fieldClass,
java.lang.Object[] target)
Returns a
containing the values of the given field name, from the elements of the given
. |
java.util.List<java.lang.Object> |
fieldValues(java.lang.String fieldName,
java.lang.Iterable<?> target) |
boolean |
isAllowedToRead(java.lang.reflect.Field field) |
boolean |
isAllowedToUsePrivateFields() |
private boolean |
isNestedField(java.lang.String fieldName)
isNestedField("address.street"); // true
isNestedField("address.street.name"); // true
isNestedField("person"); // false
isNestedField(".name"); // false
isNestedField("person."); // false
isNestedField("person.name."); // false
isNestedField(".person.name"); // false
isNestedField("."); // false
isNestedField(""); // false |
private java.lang.String |
nextFieldNameFrom(java.lang.String fieldNameChain) |
private java.lang.String |
popFieldNameFrom(java.lang.String fieldNameChain) |
private <T> T |
readSimpleField(java.lang.String fieldName,
java.lang.Class<T> clazz,
java.lang.Object target) |
void |
setAllowUsingPrivateFields(boolean allowUsingPrivateFields)
Sets whether the use of private fields is allowed.
|
private <T> java.util.List<T> |
simpleFieldValues(java.lang.String fieldName,
java.lang.Class<T> clazz,
java.lang.Iterable<?> target) |
static FieldSupport |
valueOf(java.lang.String name)
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.
|
public static final FieldSupport EXTRACTION
public static final FieldSupport EXTRACTION_OF_PUBLIC_FIELD_ONLY
public static final FieldSupport COMPARISON
private static final java.lang.String SEPARATOR
private boolean allowUsingPrivateFields
public static FieldSupport[] values()
for (FieldSupport c : FieldSupport.values()) System.out.println(c);
public static FieldSupport valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is nullpublic static FieldSupport extraction()
public static FieldSupport comparison()
public boolean isAllowedToUsePrivateFields()
public void setAllowUsingPrivateFields(boolean allowUsingPrivateFields)
allowUsingPrivateFields
- allow private fields extraction and comparison. Default true
.public <T> java.util.List<T> fieldValues(java.lang.String fieldName, java.lang.Class<T> fieldClass, java.lang.Iterable<?> target)
List
containing the values of the given field name, from the elements of the given
Iterable
. If the given Iterable
is empty or null
, this method will return an
empty List
. This method supports nested fields (e.g. "address.street.number").fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate for
null
or empty.fieldClass
- the expected type of the given field.target
- the given Iterable
.Iterable
containing the values of the given field name, from the elements of the given
Iterable
.IntrospectionError
- if an element in the given Iterable
does not have a field with a matching name.public java.util.List<java.lang.Object> fieldValues(java.lang.String fieldName, java.lang.Iterable<?> target)
public <T> java.util.List<T> fieldValues(java.lang.String fieldName, java.lang.Class<T> fieldClass, java.lang.Object[] target)
List
containing the values of the given field name, from the elements of the given
Iterable
. If the given Iterable
is empty or null
, this method will return an
empty List
. This method supports nested fields (e.g. "address.street.number").fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate for
null
or empty.fieldClass
- the expected type of the given field.target
- the given Iterable
.Iterable
containing the values of the given field name, from the elements of the given
Iterable
.IntrospectionError
- if an element in the given Iterable
does not have a field with a matching name.private <T> java.util.List<T> simpleFieldValues(java.lang.String fieldName, java.lang.Class<T> clazz, java.lang.Iterable<?> target)
private java.lang.String popFieldNameFrom(java.lang.String fieldNameChain)
private java.lang.String nextFieldNameFrom(java.lang.String fieldNameChain)
private boolean isNestedField(java.lang.String fieldName)
isNestedField("address.street"); // true
isNestedField("address.street.name"); // true
isNestedField("person"); // false
isNestedField(".name"); // false
isNestedField("person."); // false
isNestedField("person.name."); // false
isNestedField(".person.name"); // false
isNestedField("."); // false
isNestedField(""); // false
public <T> T fieldValue(java.lang.String fieldName, java.lang.Class<T> fieldClass, java.lang.Object target)
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
fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate for
null
or empty.target
- the given objectfieldClass
- type of fieldIntrospectionError
- if the given target does not have a field with a matching name.private <T> T readSimpleField(java.lang.String fieldName, java.lang.Class<T> clazz, java.lang.Object target)
public boolean isAllowedToRead(java.lang.reflect.Field field)