Class DynMethods.Builder

  • Enclosing class:
    DynMethods

    public static class DynMethods.Builder
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Builder​(java.lang.String methodName)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DynMethods.UnboundMethod build()
      Returns the first valid implementation as a UnboundMethod or throws a RuntimeError if there is none.
      DynMethods.BoundMethod build​(java.lang.Object receiver)
      Returns the first valid implementation as a BoundMethod or throws a RuntimeError if there is none.
      DynMethods.UnboundMethod buildChecked()
      Returns the first valid implementation as a UnboundMethod or throws a NoSuchMethodException if there is none.
      DynMethods.BoundMethod buildChecked​(java.lang.Object receiver)
      Returns the first valid implementation as a BoundMethod or throws a NoSuchMethodException if there is none.
      DynMethods.StaticMethod buildStatic()
      Returns the first valid implementation as a StaticMethod or throws a RuntimeException if there is none.
      DynMethods.StaticMethod buildStaticChecked()
      Returns the first valid implementation as a StaticMethod or throws a NoSuchMethodException if there is none.
      DynMethods.Builder ctorImpl​(java.lang.Class<?> targetClass, java.lang.Class<?>... argClasses)  
      DynMethods.Builder ctorImpl​(java.lang.String className, java.lang.Class<?>... argClasses)  
      DynMethods.Builder hiddenImpl​(java.lang.Class<?> targetClass, java.lang.Class<?>... argClasses)
      Checks for a method implementation.
      DynMethods.Builder hiddenImpl​(java.lang.Class<?> targetClass, java.lang.String methodName, java.lang.Class<?>... argClasses)
      Checks for a method implementation.
      DynMethods.Builder hiddenImpl​(java.lang.String className, java.lang.Class<?>... argClasses)
      Checks for an implementation, first finding the given class by name.
      DynMethods.Builder hiddenImpl​(java.lang.String className, java.lang.String methodName, java.lang.Class<?>... argClasses)
      Checks for an implementation, first finding the given class by name.
      DynMethods.Builder impl​(java.lang.Class<?> targetClass, java.lang.Class<?>... argClasses)
      Checks for a method implementation.
      DynMethods.Builder impl​(java.lang.Class<?> targetClass, java.lang.String methodName, java.lang.Class<?>... argClasses)
      Checks for a method implementation.
      DynMethods.Builder impl​(java.lang.String className, java.lang.Class<?>... argClasses)
      Checks for an implementation, first finding the given class by name.
      DynMethods.Builder impl​(java.lang.String className, java.lang.String methodName, java.lang.Class<?>... argClasses)
      Checks for an implementation, first finding the given class by name.
      DynMethods.Builder loader​(java.lang.ClassLoader newLoader)
      Set the ClassLoader used to lookup classes by name.
      DynMethods.Builder orNoop()
      If no implementation has been found, adds a NOOP method.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Builder

        public Builder​(java.lang.String methodName)
    • Method Detail

      • loader

        public DynMethods.Builder loader​(java.lang.ClassLoader newLoader)
        Set the ClassLoader used to lookup classes by name.

        If not set, the current thread's ClassLoader is used.

        Parameters:
        newLoader - a ClassLoader
        Returns:
        this Builder for method chaining
      • orNoop

        public DynMethods.Builder orNoop()
        If no implementation has been found, adds a NOOP method. Note: calls to impl will not match after this method is called!
        Returns:
        this Builder for method chaining
      • impl

        public DynMethods.Builder impl​(java.lang.String className,
                                       java.lang.String methodName,
                                       java.lang.Class<?>... argClasses)
        Checks for an implementation, first finding the given class by name.
        Parameters:
        className - name of a class
        methodName - name of a method (different from constructor)
        argClasses - argument classes for the method
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getMethod(String, Class[])
      • impl

        public DynMethods.Builder impl​(java.lang.String className,
                                       java.lang.Class<?>... argClasses)
        Checks for an implementation, first finding the given class by name. The name passed to the constructor is the method name used.
        Parameters:
        className - name of a class
        argClasses - argument classes for the method
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getMethod(String, Class[])
      • impl

        public DynMethods.Builder impl​(java.lang.Class<?> targetClass,
                                       java.lang.String methodName,
                                       java.lang.Class<?>... argClasses)
        Checks for a method implementation.
        Parameters:
        targetClass - a class instance
        methodName - name of a method (different from constructor)
        argClasses - argument classes for the method
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getMethod(String, Class[])
      • impl

        public DynMethods.Builder impl​(java.lang.Class<?> targetClass,
                                       java.lang.Class<?>... argClasses)
        Checks for a method implementation. The name passed to the constructor is the method name used.
        Parameters:
        targetClass - a class instance
        argClasses - argument classes for the method
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getMethod(String, Class[])
      • ctorImpl

        public DynMethods.Builder ctorImpl​(java.lang.Class<?> targetClass,
                                           java.lang.Class<?>... argClasses)
      • ctorImpl

        public DynMethods.Builder ctorImpl​(java.lang.String className,
                                           java.lang.Class<?>... argClasses)
      • hiddenImpl

        public DynMethods.Builder hiddenImpl​(java.lang.String className,
                                             java.lang.String methodName,
                                             java.lang.Class<?>... argClasses)
        Checks for an implementation, first finding the given class by name.
        Parameters:
        className - name of a class
        methodName - name of a method (different from constructor)
        argClasses - argument classes for the method
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getMethod(String, Class[])
      • hiddenImpl

        public DynMethods.Builder hiddenImpl​(java.lang.String className,
                                             java.lang.Class<?>... argClasses)
        Checks for an implementation, first finding the given class by name. The name passed to the constructor is the method name used.
        Parameters:
        className - name of a class
        argClasses - argument classes for the method
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getMethod(String, Class[])
      • hiddenImpl

        public DynMethods.Builder hiddenImpl​(java.lang.Class<?> targetClass,
                                             java.lang.String methodName,
                                             java.lang.Class<?>... argClasses)
        Checks for a method implementation.
        Parameters:
        targetClass - a class instance
        methodName - name of a method (different from constructor)
        argClasses - argument classes for the method
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getMethod(String, Class[])
      • hiddenImpl

        public DynMethods.Builder hiddenImpl​(java.lang.Class<?> targetClass,
                                             java.lang.Class<?>... argClasses)
        Checks for a method implementation. The name passed to the constructor is the method name used.
        Parameters:
        targetClass - a class instance
        argClasses - argument classes for the method
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getMethod(String, Class[])
      • build

        public DynMethods.UnboundMethod build()
        Returns the first valid implementation as a UnboundMethod or throws a RuntimeError if there is none.
        Returns:
        a DynMethods.UnboundMethod with a valid implementation
        Throws:
        java.lang.RuntimeException - if no implementation was found
      • build

        public DynMethods.BoundMethod build​(java.lang.Object receiver)
        Returns the first valid implementation as a BoundMethod or throws a RuntimeError if there is none.
        Parameters:
        receiver - an Object to receive the method invocation
        Returns:
        a DynMethods.BoundMethod with a valid implementation and receiver
        Throws:
        java.lang.IllegalStateException - if the method is static
        java.lang.IllegalArgumentException - if the receiver's class is incompatible
        java.lang.RuntimeException - if no implementation was found
      • buildChecked

        public DynMethods.UnboundMethod buildChecked()
                                              throws java.lang.NoSuchMethodException
        Returns the first valid implementation as a UnboundMethod or throws a NoSuchMethodException if there is none.
        Returns:
        a DynMethods.UnboundMethod with a valid implementation
        Throws:
        java.lang.NoSuchMethodException - if no implementation was found
      • buildChecked

        public DynMethods.BoundMethod buildChecked​(java.lang.Object receiver)
                                            throws java.lang.NoSuchMethodException
        Returns the first valid implementation as a BoundMethod or throws a NoSuchMethodException if there is none.
        Parameters:
        receiver - an Object to receive the method invocation
        Returns:
        a DynMethods.BoundMethod with a valid implementation and receiver
        Throws:
        java.lang.IllegalStateException - if the method is static
        java.lang.IllegalArgumentException - if the receiver's class is incompatible
        java.lang.NoSuchMethodException - if no implementation was found
      • buildStaticChecked

        public DynMethods.StaticMethod buildStaticChecked()
                                                   throws java.lang.NoSuchMethodException
        Returns the first valid implementation as a StaticMethod or throws a NoSuchMethodException if there is none.
        Returns:
        a DynMethods.StaticMethod with a valid implementation
        Throws:
        java.lang.IllegalStateException - if the method is not static
        java.lang.NoSuchMethodException - if no implementation was found
      • buildStatic

        public DynMethods.StaticMethod buildStatic()
        Returns the first valid implementation as a StaticMethod or throws a RuntimeException if there is none.
        Returns:
        a DynMethods.StaticMethod with a valid implementation
        Throws:
        java.lang.IllegalStateException - if the method is not static
        java.lang.RuntimeException - if no implementation was found