Package microsim.statistics.reflectors
Class StringInvoker
java.lang.Object
microsim.statistics.reflectors.StringInvoker
- All Implemented Interfaces:
StringSource
Employs Java reflection to call objects' methods which return string values.
-
Field Summary
Fields inherited from interface microsim.statistics.StringSource
DEFAULT
-
Constructor Summary
ConstructorDescriptionStringInvoker
(@NonNull Class<?> target, @NonNull String fieldName, boolean isMethod) Constructor.StringInvoker
(@NonNull Object target, @NonNull String fieldName, boolean isMethod) Constructor. -
Method Summary
Modifier and TypeMethodDescription@NonNull String[]
getCollectionValue
(@NonNull Collection<?> c) Converts a collection of strings to an array.Invokes the method of the object passed to constructor and returns its double result.Invokes the method of the target object and returns its string result.@NonNull String
getStringValue
(@Nullable Enum<?> valueID) This is an implementation of theStringSource
interface.
-
Field Details
-
method
-
field
-
target
-
-
Constructor Details
-
StringInvoker
public StringInvoker(@NonNull @NonNull Object target, @NonNull @NonNull String fieldName, boolean isMethod) Constructor.- Parameters:
target
- It is the target object.fieldName
- A string representing the name of the method to invoke.isMethod
- If true the fieldName is a method, otherwise it is a property of the object.- Throws:
NullPointerException
- when any of the input parameters isnull
.
-
StringInvoker
public StringInvoker(@NonNull @NonNull Class<?> target, @NonNull @NonNull String fieldName, boolean isMethod) Constructor.- Parameters:
target
- It is the class of the target object.fieldName
- A string representing the name of the method to invoke.isMethod
- If true the fieldName is a method, otherwise it is a property of the object.- Throws:
NullPointerException
- when any of the input parameters isnull
.
-
-
Method Details
-
getString
Invokes the method of the target object and returns its string result.- Parameters:
target
- Object to be invoked.- Returns:
- The requested string value.
- Throws:
NullPointerException
- whentarget
isnull
.
-
getString
Invokes the method of the object passed to constructor and returns its double result.- Returns:
- The requested double value.
-
getStringValue
This is an implementation of theStringSource
interface. It calls thegetString(Object)
method.- Specified by:
getStringValue
in interfaceStringSource
- Parameters:
valueID
- This parameter is ignored. It is put for compatibility with theStringSource
interface.- Returns:
- The requested double value.
-
getCollectionValue
Converts a collection of strings to an array.- Parameters:
c
- ACollection
object.- Returns:
- an array.
-