Package com.opencsv.bean
Class FieldAccess<T>
- java.lang.Object
-
- com.opencsv.bean.FieldAccess<T>
-
- Type Parameters:
T
- The type of the member variable being accessed
public class FieldAccess<T> extends java.lang.Object
Encapsulates the logic for accessing member variables of classes.The logic in opencsv is always:
- Use an accessor method first, if available, and this always has the form "get"/"set" + member name with initial capital.
- If this accessor method is available but deals in
Optional
, wrap or unwrap as necessary. EmptyOptional
s lead tonull
return values, andnull
values lead to emptyOptional
s. - Use reflection bypassing all access control restrictions.
- Since:
- 5.0
- Author:
- Andrew Rucker Jones
-
-
Constructor Summary
Constructors Constructor Description FieldAccess(java.lang.reflect.Field field)
Constructs this instance by determining what mode of access will work for this field.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
Determines equality between this object and another.T
getField(java.lang.Object bean)
Returns the value of the field in the given bean.int
hashCode()
Creates a hash code for this object.void
setField(java.lang.Object bean, T value)
Sets the value of the field in the given bean.java.lang.String
toString()
Returns a string representation of this object.
-
-
-
Method Detail
-
getField
public T getField(java.lang.Object bean) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Returns the value of the field in the given bean.- Parameters:
bean
- The bean from which the value of this field should be returned- Returns:
- The value of this member variable
- Throws:
java.lang.IllegalAccessException
- If there is a problem accessing the member variablejava.lang.reflect.InvocationTargetException
- If there is a problem accessing the member variable
-
setField
public void setField(java.lang.Object bean, T value) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Sets the value of the field in the given bean.- Parameters:
bean
- The bean in which the value of the field should be setvalue
- The value to be written into the member variable of the bean- Throws:
java.lang.IllegalAccessException
- If there is a problem accessing the member variablejava.lang.reflect.InvocationTargetException
- If there is a problem accessing the member variable
-
hashCode
public int 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.- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
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.- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String 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.- Overrides:
toString
in classjava.lang.Object
-
-