Interface TypeResolver

All Superinterfaces:
Copyable<TypeResolver>

public interface TypeResolver extends Copyable<TypeResolver>

TypeResolver provides dynamic mapping of Java types to the engine's internal Type. In the engine, all fact types are represented by a String identifier and an associated Java class. This allows instances of the same Java class to be treated as having different logical types.

This interface extends Copyable, allowing a TypeResolver to create copies of itself. The copies must inherit the original declared types but must not have a reverse effect — changes, such as new types or field declarations, in the copies must not be reflected in the original type resolver.

See Also:
  • Method Details

    • getType

      <T> Type<T> getType(String name)
      Type Parameters:
      T - type parameter
      Parameters:
      name - type's logical name
      Returns:
      existing Type or null if not found
    • getKnownTypes

      Collection<Type<?>> getKnownTypes()
      Returns a collection of all known types.
      Returns:
      a collection of Type instances representing the known types
    • getKnownTypes

      Collection<Type<?>> getKnownTypes(Class<?> javaClass)
      Returns a collection of all known types that have the same Java type as specified by the argument.
      Parameters:
      javaClass - the class of the Java type to find known types for
      Returns:
      a collection of Type instances representing the known types with the specified Java type
    • addType

      void addType(Type<?> type)
      Adds a new type to the type resolver and overrides any previous association between the type's logical name and the type itself.
      Parameters:
      type - The type to be added to the resolver.
      Since:
      4.0.0
    • declare

      default <T> Type<T> declare(Class<T> type)

      Declares and registers new Type with the given Java class name. The logical name of the resulting type will be Class.getName()

      Type Parameters:
      T - java class type parameter
      Parameters:
      type - Java class
      Returns:
      new internal type
      Throws:
      IllegalStateException - if such type name has been already declared
    • declare

      <T> Type<T> declare(String typeName, Class<T> javaType)

      Declares and registers new Type with the given type name and Java class

      Type Parameters:
      T - java class type parameter
      Parameters:
      typeName - logical type name
      javaType - Java class
      Returns:
      new internal type
      Throws:
      IllegalStateException - if such type name has been already declared
    • declare

      <T> Type<T> declare(String typeName, String javaType)

      Declares and registers new Type with the given logical type name and Java class name. The existence of the corresponding Java class will be checked lazily, when the engine requires access to the class's properties.

      Type Parameters:
      T - java class type parameter
      Parameters:
      typeName - logical type name
      javaType - Java class name
      Returns:
      new logical type
      Throws:
      IllegalStateException - if such type name has been already declared
    • getOrDeclare

      default <T> Type<T> getOrDeclare(String typeName, Class<T> javaType)
    • getOrDeclare

      default <T> Type<T> getOrDeclare(String typeName, String javaType)
    • getOrDeclare

      default <T> Type<T> getOrDeclare(String typeName)
    • getOrDeclare

      default <T> Type<T> getOrDeclare(Class<T> cl)
    • resolve

      <T> Type<T> resolve(Object o)
      Type Parameters:
      T - type parameter
      Parameters:
      o - object to resolve
      Returns:
      Type of the argument or null if object's type is unknown