nl.jqno.equalsverifier.util
Class FieldAccessor

java.lang.Object
  extended by nl.jqno.equalsverifier.util.FieldAccessor

public class FieldAccessor
extends Object

Provides reflective access to one field of an object.

Author:
Jan Ouwens

Constructor Summary
FieldAccessor(Object object, Field field)
          Constructor.
 
Method Summary
 boolean canBeModifiedReflectively()
          Determines whether the field can be modified using reflection.
 void changeField(PrefabValues prefabValues)
          Changes the field's value to something else.
 void copyTo(Object to)
          Copies field's value to the corresponding field in the specified object.
 void defaultField()
          Tries to make the field null.
 boolean fieldIsFinal()
          Returns whether the field is marked with the final modifier.
 boolean fieldIsPrimitive()
          Returns whether the field is of a primitive type.
 boolean fieldIsStatic()
          Returns whether the field is marked with the static modifier.
 boolean fieldIsTransient()
          Returns whether the field is marked with the transient modifier.
 Object get()
          Tries to get the field's value.
 Field getField()
          Getter.
 String getFieldName()
          Getter for the field's name.
 Class<?> getFieldType()
          Getter for the field's type.
 Object getObject()
          Getter.
 void set(Object value)
          Tries to set the field to the specified value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FieldAccessor

public FieldAccessor(Object object,
                     Field field)
Constructor.

Parameters:
object - The object we want to access.
field - A field of object.
Method Detail

getObject

public Object getObject()
Getter.


getField

public Field getField()
Getter.


getFieldType

public Class<?> getFieldType()
Getter for the field's type.


getFieldName

public String getFieldName()
Getter for the field's name.


fieldIsPrimitive

public boolean fieldIsPrimitive()
Returns whether the field is of a primitive type.


fieldIsFinal

public boolean fieldIsFinal()
Returns whether the field is marked with the final modifier.


fieldIsStatic

public boolean fieldIsStatic()
Returns whether the field is marked with the static modifier.


fieldIsTransient

public boolean fieldIsTransient()
Returns whether the field is marked with the transient modifier.


get

public Object get()
Tries to get the field's value.

Returns:
The field's value.
Throws:
ReflectionException - If the operation fails.

set

public void set(Object value)
Tries to set the field to the specified value.

Parameters:
value - The value that the field should get.
Throws:
ReflectionException - If the operation fails.

defaultField

public void defaultField()
Tries to make the field null.

Throws:
ReflectionException - If the operation fails.

copyTo

public void copyTo(Object to)
Copies field's value to the corresponding field in the specified object.

Parameters:
to - The object into which to copy the field.
Throws:
ReflectionException - If the operation fails.

changeField

public void changeField(PrefabValues prefabValues)
Changes the field's value to something else. The new value will never be null. Other than that, the precise value is undefined.

Parameters:
prefabValues - If the field is of a type contained within prefabValues, the new value will be taken from it.
Throws:
ReflectionException - If the operation fails.

canBeModifiedReflectively

public boolean canBeModifiedReflectively()
Determines whether the field can be modified using reflection.

Returns:
Whether or not the field can be modified reflectively.


Copyright © 2015. All Rights Reserved.