Package org.moeaframework.core
Interface Defined
- All Known Subinterfaces:
Constraint
,Objective
,Variable
- All Known Implementing Classes:
AbstractConstraint
,AbstractObjective
,AbstractVariable
,Between
,BinaryIntegerVariable
,BinaryVariable
,BoundedConstraint
,Equal
,FileMap
,Grammar
,GreaterThan
,GreaterThanOrEqual
,HashFileMap
,HierarchicalFileMap
,LessThan
,LessThanOrEqual
,Maximize
,Minimize
,NormalizedObjective
,NotEqual
,Outside
,Permutation
,Program
,RealVariable
,Subset
,ThresholdConstraint
public interface Defined
Interface for objects that can be defined and reconstructed using a string representation. The string
representation mimics a Java constructor call, such as:
"Minimize" "org.moeaframework.core.objective.Minimize" "LessThan(2.0)" "org.moeaframework.core.constraint.LessThan(2.0)"There are a few key differences, including:
- Either the class' simple name or fully-qualified name that includes the package is permitted. The class must reside in the same package as the return type in order to use the shorter simple name.
- Parenthesis can be omitted if using the no-arg constructor.
- Duck typing is used, meaning the string
"2"
could be considered a string, an integer, or a double. Therefore, avoid defining multiple constructors with indistinguishable representations.
toString()
and a static valueOf(String)
method is supported. These types should throw IllegalArgumentException
if the supplied string is not compatible with the type.-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
Comparator that sorts constructors based on the number of parameters and the types of each parameter. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
createDefinition
(Class<?> instanceType, Object... arguments) Creates a string representation based on the given parent and instance type along with the constructor arguments.static <T> String
createDefinition
(Class<T> parentType, Class<? extends T> instanceType, Object... arguments) Creates a string representation based on the given parent and instance type along with the constructor arguments.static <T> T
createInstance
(Class<T> returnType, String definition) Reconstructs the object using its string representation produced bygetDefinition()
.static String
createUnsupportedDefinition
(Class<?> instanceType) Creates a string representation the displays the type but indicates it is not supported.static <T> String
createUnsupportedDefinition
(Class<T> parentType, Class<? extends T> instanceType) Creates a string representation the displays the type but indicates it is not supported.Returns the string representation, or definition, of this object.
-
Method Details
-
getDefinition
String getDefinition()Returns the string representation, or definition, of this object.- Returns:
- the definition
-
createUnsupportedDefinition
Creates a string representation the displays the type but indicates it is not supported.- Parameters:
instanceType
- the instance type- Returns:
- the string representation
-
createUnsupportedDefinition
Creates a string representation the displays the type but indicates it is not supported.- Type Parameters:
T
- the type- Parameters:
parentType
- the parent type, which ifnull
will always produce a fully-qualified class nameinstanceType
- the instance type- Returns:
- the string representation
-
createDefinition
Creates a string representation based on the given parent and instance type along with the constructor arguments.- Parameters:
instanceType
- the instance typearguments
- the arguments, if any, passed to the constructor- Returns:
- the string representation
-
createDefinition
static <T> String createDefinition(Class<T> parentType, Class<? extends T> instanceType, Object... arguments) Creates a string representation based on the given parent and instance type along with the constructor arguments.- Type Parameters:
T
- the type- Parameters:
parentType
- the parent type, which ifnull
will always produce a fully-qualified class nameinstanceType
- the instance typearguments
- the arguments, if any, passed to the constructor- Returns:
- the string representation
-
createInstance
Reconstructs the object using its string representation produced bygetDefinition()
.- Type Parameters:
T
- the type- Parameters:
returnType
- the return typedefinition
- the string representation of the object- Returns:
- the reconstructed object, or
null
if reconstruction is not supported
-