Interface Type<T>

Type Parameters:
T - Java type associated with this type
All Superinterfaces:
Copyable<Type<T>>, Named
All Known Implementing Classes:
TypeWrapper

public interface Type<T>
extends Named, Copyable<Type<T>>

An engine's internal type which is assigned to every fact before it gets into the session's working memory. It allows for dynamic, real-time field declarations either as functional interfaces or via reflection mechanisms.

  • Method Details

    • getId

      int getId()

      Each type is assigned a unique auto-increment int identifier which developers can use in SPI implementations, for example in sharding/partitioning data collections.

      Returns:
      unique type identifier.
    • getJavaType

      Class<T> getJavaType()

      There can be only one Type with the given name, but there could be many types associated with a specific Java Class. This method returns the associated Java type.

      Returns:
      Java Class associated with the type.
    • getDeclaredFields

      Collection<TypeField> getDeclaredFields()

      Method returns ALL known fields, both explicitly declared and resolved.

      Returns:
      Collection of declared fields
      See Also:
      TypeField
    • getField

      TypeField getField​(String name)

      Returns a declared field with the given name, or null if no such field is found or resolved

      Parameters:
      name - field name
      Returns:
      a declared field or null
    • getField

      TypeField getField​(int id)

      Returns a declared field with the given name, or null if no such field is found or resolved

      Parameters:
      id - field name
      Returns:
      a declared field or null
    • declareField

      <V> TypeField declareField​(String name, Class<V> type, Function<T,​V> function)

      Field declaration with a Function as value reader.

      Type Parameters:
      V - field value generic type
      Parameters:
      name - field name
      type - field value class
      function - the function that will be used to read field's value
      Returns:
      a newly created field or an existing one if already declared/resolved
    • declareIntField

      default TypeField declareIntField​(String name, ToIntFunction<T> function)

      Method declares a primitive int field.

      Parameters:
      name - field name
      function - field functional interface
      Returns:
      a newly created field or an existing one if already declared/resolved
    • declareLongField

      default TypeField declareLongField​(String name, ToLongFunction<T> function)

      Method declares a primitive long field.

      Parameters:
      name - field name
      function - field functional interface
      Returns:
      a newly created field or an existing one if already declared/resolved
    • declareDoubleField

      default TypeField declareDoubleField​(String name, ToDoubleFunction<T> function)

      Method declares a primitive double field.

      Parameters:
      name - field name
      function - field functional interface
      Returns:
      a newly created field or an existing one if already declared/resolved
    • declareBooleanField

      default TypeField declareBooleanField​(String name, Predicate<T> function)

      Method declares a primitive boolean field.

      Parameters:
      name - field name
      function - field functional interface
      Returns:
      a newly created field or an existing one if already declared/resolved