Top Description Fields Constructors Methods
com.opencsv.bean

public Class FieldAccess<T>

extends Object
Class Inheritance
Type Parameters
<T>
The type of the member variable being accessed
Imports
com.opencsv.bean.function.AccessorInvoker, .AssignmentInvoker, org.apache.commons.lang3.reflect.FieldUtils, java.lang.reflect.Field, .InvocationTargetException, .Method, java.util.Optional

Encapsulates the logic for accessing member variables of classes.

The logic in opencsv is always:

  1. Use an accessor method first, if available, and this always has the form "get"/"set" + member name with initial capital.
  2. If this accessor method is available but deals in java.util.Optional, wrap or unwrap as necessary. Empty java.util.Optionals lead to null return values, and null values lead to empty java.util.Optionals.
  3. Use reflection bypassing all access control restrictions.
These are considered separately for reading and writing.

Author
Andrew Rucker Jones
Since
5.0

Field Summary

Modifier and TypeField and Description
private final AccessorInvoker<Object, T>
accessor

A functional interface to read the field.

private final AssignmentInvoker<Object, T>
assignment

A functional interface to write the field.

private final Field
field

The field being accessed.

Constructor Summary

AccessConstructor and Description
public
FieldAccess(Field
The field to be accessed.
field
)

Constructs this instance by determining what mode of access will work for this field.

Method Summary

Modifier and TypeMethod and Description
private AccessorInvoker<Object, T>
private AssignmentInvoker<Object, T>
public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Determines equality between this object and another.

public T

Returns:

The value of this member variable
getField
(Object
The bean from which the value of this field should be returned
bean
)

Returns the value of the field in the given bean.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Creates a hash code for this object.

public void
setField(Object
The bean in which the value of the field should be set
bean
,
T
The value to be written into the member variable of the bean
value
)

Sets the value of the field in the given bean.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

accessorback to summary
private final AccessorInvoker<Object, T> accessor

A functional interface to read the field.

assignmentback to summary
private final AssignmentInvoker<Object, T> assignment

A functional interface to write the field.

fieldback to summary
private final Field field

The field being accessed.

Constructor Detail

FieldAccessback to summary
public FieldAccess(Field field)

Constructs this instance by determining what mode of access will work for this field.

Parameters
field:Field

The field to be accessed.

Method Detail

determineAccessorMethodback to summary
private AccessorInvoker<Object, T> determineAccessorMethod()
Annotations
@SuppressWarnings:unchecked
determineAssignmentMethodback to summary
private AssignmentInvoker<Object, T> determineAssignmentMethod()
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Determines equality between this object and another. This override delegates equality determination to the field passed in through the constructor and does not includes any of its own state information.

Annotations
@Override
getFieldback to summary
public T getField(Object bean) throws IllegalAccessException, InvocationTargetException

Returns the value of the field in the given bean.

Parameters
bean:Object

The bean from which the value of this field should be returned

Returns:T

The value of this member variable

Exceptions
IllegalAccessException:
If there is a problem accessing the member variable
InvocationTargetException:
If there is a problem accessing the member variable
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Creates a hash code for this object. This override delegates hash code creation to the field passed in through the constructor and does not includes any of its own state information.

Annotations
@Override
setFieldback to summary
public void setField(Object bean, T value) throws IllegalAccessException, InvocationTargetException

Sets the value of the field in the given bean.

Parameters
bean:Object

The bean in which the value of the field should be set

value:T

The value to be written into the member variable of the bean

Exceptions
IllegalAccessException:
If there is a problem accessing the member variable
InvocationTargetException:
If there is a problem accessing the member variable
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this object. This override delegates the string representation to the field passed in through the constructor and does not includes any of its own state information.

Annotations
@Override