Class ComponentRegistry

java.lang.Object
org.kink_lang.kink.ComponentRegistry

public class ComponentRegistry extends Object
The component registry of the VM.

Components are any objects which are registered to the VM. A component is registered with its class. For a class, only one component can be registered. The second or later attempts of registration do not succeed.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    get(Class<T> klass)
    Returns a component registered with the class.
    <T> T
    getOrRegister(Class<T> klass, Function<Vm,T> makeComponent)
    Returns a component registered with the class; if it is not registered yet, makes one via makeComponent, then registers and returns it.
    <T> void
    register(Class<T> klass, T component)
    Registers the component with the class, only if no component is registered with the class.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • get

      public <T> T get(Class<T> klass)
      Returns a component registered with the class.
      Type Parameters:
      T - the type of the class of the component.
      Parameters:
      klass - the class of the component.
      Returns:
      the component.
      Throws:
      IllegalStateException - if it is not registered yet.
    • register

      public <T> void register(Class<T> klass, T component)
      Registers the component with the class, only if no component is registered with the class.
      Type Parameters:
      T - the type of the class of the component.
      Parameters:
      klass - the class of the component.
      component - the component.
    • getOrRegister

      public <T> T getOrRegister(Class<T> klass, Function<Vm,T> makeComponent)
      Returns a component registered with the class; if it is not registered yet, makes one via makeComponent, then registers and returns it.

      Example:

       class X {
         X(Vm vm) {}
       }
      
       X x = vm.component.getOrRegister(X.class, X::new);
       
      Type Parameters:
      T - the type of the class of the component.
      Parameters:
      klass - the class of the component.
      makeComponent - a function to make a component.
      Returns:
      the component.