Class SimpleInvokeFactory<F,T>

java.lang.Object
ru.progrm_jarvis.javacommons.invoke.SimpleInvokeFactory<F,T>
Type Parameters:
F - type of functional interface implemented
T - type of target value
All Implemented Interfaces:
InvokeFactory<F,T>

public final class SimpleInvokeFactory<F,T> extends Object implements InvokeFactory<F,T>
Simple implementation of InvokeFactory.
  • Field Details

    • lookupFactory

      protected LookupFactory lookupFactory
      Used lookup factory
    • functionalInterface

      protected MethodType functionalInterface
      Implemented functional interface
    • functionalMethodSignature

      protected MethodType functionalMethodSignature
      Signature of the functional interface's functional method
    • functionalMethodName

      protected String functionalMethodName
      Name of the functional interface's functional method
    • methodHandleCreator

      protected Function<MethodHandles.Lookup,MethodHandle> methodHandleCreator
      Factory creating implementation method handle using the given lookup
    • targetClass

      protected Class<? extends T> targetClass
      Target class containing the implementation method
    • target

      @Nullable protected @Nullable Object target
      Target
  • Method Details

    • newInstance

      @NotNull public static <F, T> @NotNull InvokeFactory<F,T> newInstance()
      Creates a new simple invoke factory.
      Type Parameters:
      F - type of functional interface implemented
      T - type of target value
      Returns:
      created invoke factory
    • using

      public InvokeFactory<F,T> using(@NonNull @NonNull LookupFactory lookupFactory)
      Description copied from interface: InvokeFactory
      Specifies the lookup factory to be used for creation of lookup
      Specified by:
      using in interface InvokeFactory<F,T>
      Parameters:
      lookupFactory - lookup factory to be used for creation of lookup
      Returns:
      this invoke factory
    • implementing

      public InvokeFactory<F,T> implementing(@NonNull @NonNull MethodType functionalInterface, @NonNull @NonNull String functionalMethodName, @NonNull @NonNull MethodType functionalMethodSignature)
      Description copied from interface: InvokeFactory
      Specifies the functional interface implemented.
      Specified by:
      implementing in interface InvokeFactory<F,T>
      Parameters:
      functionalInterface - type of the implemented functional interface (always has return type and no parameters)
      functionalMethodName - name of the implemented functional method
      functionalMethodSignature - signature of the implemented functional method
      Returns:
      this invoke factory
    • via

      public InvokeFactory<F,T> via(@NonNull @NonNull Class<? extends T> targetClass, @NonNull @NonNull Function<MethodHandles.Lookup,MethodHandle> methodHandleCreator)
      Description copied from interface: InvokeFactory
      Specifies the target class with function which will be used to create a related MethodHandle.
      Specified by:
      via in interface InvokeFactory<F,T>
      Parameters:
      targetClass - class to whom the method-handle relates
      methodHandleCreator - function creating a MethodHandle using the given lookup
      Returns:
      this invoke factory
      See Also:
    • boundTo

      public InvokeFactory<F,T> boundTo(@Nullable T target)
      Description copied from interface: InvokeFactory
      Binds the method call to the specified instance.
      Specified by:
      boundTo in interface InvokeFactory<F,T>
      Parameters:
      target - instance of the target class to use for non-static invocation or null to unbound (make the call static)
      Returns:
      this invoke factory
    • unbound

      public InvokeFactory<F,T> unbound()
      Description copied from interface: InvokeFactory
      Unbinds the method call from instance (making it static).
      Specified by:
      unbound in interface InvokeFactory<F,T>
      Returns:
      this invoke factory
    • create

      public F create() throws Throwable
      Description copied from interface: InvokeFactory
      Creates the implementation of the functional interface.
      Specified by:
      create in interface InvokeFactory<F,T>
      Returns:
      implemented functional interface
      Throws:
      IllegalStateException - if any of the required factory properties has not been set
      Throwable - if an exception occurs while creating an implementation of the functional interface
    • toString

      public String toString()
      Overrides:
      toString in class Object