T
- the type of the described fieldpublic class FieldDescriptor<T> extends Object implements Serializable
A field descriptor associates a name with a given class, and provides the means to generate custom string representations of any instance of this class.
Constructor and Description |
---|
FieldDescriptor(String nameIn,
Class<T> fieldClassIn)
Creates a new field descriptor.
|
FieldDescriptor(String nameIn,
Class<T> fieldClassIn,
Function<T,String> printFunctionIn)
Creates a new field descriptor which uses the specified function to convert field values to
strings.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object object)
Indicates whether some other object is "equal to" this one.
|
Class<T> |
getFieldClass()
Gets the class of the described fields.
|
String |
getName()
Gets the name of the descriptor.
|
Function<T,String> |
getPrintFunction()
Gets the function to use when converting field values to strings.
|
int |
hashCode() |
String |
printField(Object value)
Gets a string representation of a given field value.
|
void |
setPrintFunction(Function<T,String> newPrintFunction)
Sets the function to use when converting field values to strings.
|
String |
toString() |
public FieldDescriptor(String nameIn, Class<T> fieldClassIn)
nameIn
- the name of the descriptorfieldClassIn
- the class of the described fieldsIllegalArgumentException
- if nameIn
or fieldClassIn
is null
public FieldDescriptor(String nameIn, Class<T> fieldClassIn, Function<T,String> printFunctionIn)
nameIn
- the name of the descriptorfieldClassIn
- the class of the described fieldsprintFunctionIn
- the function to use when converting field values to stringsNullArgumentException
- if nameIn
or fieldClassIn
is null
public String getName()
public Class<T> getFieldClass()
public Function<T,String> getPrintFunction()
public void setPrintFunction(Function<T,String> newPrintFunction)
newPrintFunction
- the new function to use when converting field values to stringspublic String printField(Object value)
The string representation of the field value is generated using the printer function
specified at construction. The standard toString
method is used instead if no
function was specified, or if the class of the provided object does not match the class
associated with this field descriptor.
value
- the field valuepublic boolean equals(Object object)
This method only compares the name of the descriptor and the class of the described fields when checking if two FieldDescriptor instances are equal or not. The function used to convert field values to strings is not taken into account.
Copyright © 2023 CNES. All rights reserved.