public class StructureModifier<TField>
extends java.lang.Object
Constructor and Description |
---|
StructureModifier(java.lang.Class targetType,
java.lang.Class superclassExclude,
boolean requireDefault)
Creates a structure modifier.
|
Modifier and Type | Method and Description |
---|---|
java.util.List<java.lang.reflect.Field> |
getFields()
Retrieves a list of the fields matching the constraints of this structure modifier.
|
java.lang.Class |
getFieldType()
Retrieves the common type of each field.
|
java.lang.Object |
getTarget()
Retrieves the object we're currently modifying.
|
java.lang.Class |
getTargetType()
Retrieves the type of the object we're modifying.
|
java.util.List<TField> |
getValues()
Retrieve every value stored in the fields of the current type.
|
StructureModifier<TField> |
modify(int fieldIndex,
com.google.common.base.Function<TField,TField> select)
Correctly modifies the value of a field.
|
TField |
read(int fieldIndex)
Reads the value of a field given its index.
|
TField |
readSafely(int fieldIndex)
Reads the value of a field if and ONLY IF it exists.
|
int |
size()
Retrieve the number of readable types.
|
StructureModifier<TField> |
withTarget(java.lang.Object target)
Retrieves a structure modifier of the same type for a different object target.
|
<T> StructureModifier<T> |
withType(java.lang.Class fieldType)
Retrieves a structure modifier that only reads and writes fields of a given type.
|
<T> StructureModifier<T> |
withType(java.lang.Class fieldType,
EquivalentConverter<T> converter)
Retrieves a structure modifier that only reads and writes fields of a given type.
|
StructureModifier<TField> |
write(int fieldIndex,
TField value)
Writes the value of a field given its index.
|
StructureModifier<TField> |
writeDefaults()
Sets all non-primitive fields to a more fitting default value.
|
StructureModifier<TField> |
writeSafely(int fieldIndex,
TField value)
Writes the value of a given field IF and ONLY if it exists.
|
public StructureModifier(java.lang.Class targetType, java.lang.Class superclassExclude, boolean requireDefault)
targetType
- - the structure to modify.superclassExclude
- - a superclass to exclude.requireDefault
- - whether or not we will be using writeDefaults().public TField read(int fieldIndex) throws FieldAccessException
fieldIndex
- - index of the field.FieldAccessException
- The field doesn't exist, or it cannot be accessed under the current security contraints.public TField readSafely(int fieldIndex) throws FieldAccessException
fieldIndex
- - index of the field.FieldAccessException
- The field cannot be accessed under the current security contraints.public StructureModifier<TField> write(int fieldIndex, TField value) throws FieldAccessException
fieldIndex
- - index of the field.value
- - new value of the field.FieldAccessException
- The field doesn't exist, or it cannot be accessed under the current security contraints.public StructureModifier<TField> writeSafely(int fieldIndex, TField value) throws FieldAccessException
fieldIndex
- - index of the potential field.value
- - new value of the field.FieldAccessException
- The field cannot be accessed under the current security contraints.public StructureModifier<TField> modify(int fieldIndex, com.google.common.base.Function<TField,TField> select) throws FieldAccessException
fieldIndex
- - index of the field to modify.select
- - the function that modifies the field value.FieldAccessException
- The field cannot be accessed under the current security contraints.public <T> StructureModifier<T> withType(java.lang.Class fieldType)
fieldType
- - the type, or supertype, of every field to modify.public StructureModifier<TField> writeDefaults() throws FieldAccessException
DefaultInstances.getDefault(Class)
.FieldAccessException
- If we're unable to write to the fields due to a security limitation.public <T> StructureModifier<T> withType(java.lang.Class fieldType, EquivalentConverter<T> converter)
fieldType
- - the type, or supertype, of every field to modify.converter
- - converts objects into the given type.public java.lang.Class getFieldType()
public java.lang.Class getTargetType()
public java.lang.Object getTarget()
public int size()
public StructureModifier<TField> withTarget(java.lang.Object target)
target
- - different target of the same type.public java.util.List<java.lang.reflect.Field> getFields()
public java.util.List<TField> getValues() throws FieldAccessException
FieldAccessException
- Unable to access one or all of the fields