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:
  1. 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.
  2. Parenthesis can be omitted if using the no-arg constructor.
  3. 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.
While we recommend only using primitive types for the constructor arguments, any type implementing 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

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Comparator that sorts constructors based on the number of parameters and the types of each parameter.
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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 by getDefinition().
    static String
    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

      static String createUnsupportedDefinition(Class<?> instanceType)
      Creates a string representation the displays the type but indicates it is not supported.
      Parameters:
      instanceType - the instance type
      Returns:
      the string representation
    • createUnsupportedDefinition

      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.
      Type Parameters:
      T - the type
      Parameters:
      parentType - the parent type, which if null will always produce a fully-qualified class name
      instanceType - the instance type
      Returns:
      the string representation
    • createDefinition

      static String createDefinition(Class<?> instanceType, Object... arguments)
      Creates a string representation based on the given parent and instance type along with the constructor arguments.
      Parameters:
      instanceType - the instance type
      arguments - 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 if null will always produce a fully-qualified class name
      instanceType - the instance type
      arguments - the arguments, if any, passed to the constructor
      Returns:
      the string representation
    • createInstance

      static <T> T createInstance(Class<T> returnType, String definition)
      Reconstructs the object using its string representation produced by getDefinition().
      Type Parameters:
      T - the type
      Parameters:
      returnType - the return type
      definition - the string representation of the object
      Returns:
      the reconstructed object, or null if reconstruction is not supported