Class DynFields.Builder

  • Enclosing class:
    DynFields

    public static class DynFields.Builder
    extends java.lang.Object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> DynFields.UnboundField<T> build()
      Returns the first valid implementation as a UnboundField or throws a NoSuchFieldException if there is none.
      <T> DynFields.BoundField<T> build​(java.lang.Object target)
      Returns the first valid implementation as a BoundMethod or throws a RuntimeException if there is none.
      <T> DynFields.UnboundField<T> buildChecked()
      Returns the first valid implementation as a UnboundField or throws a NoSuchFieldException if there is none.
      <T> DynFields.BoundField<T> buildChecked​(java.lang.Object target)
      Returns the first valid implementation as a BoundMethod or throws a NoSuchMethodException if there is none.
      <T> DynFields.StaticField<T> buildStatic()
      Returns the first valid implementation as a StaticField or throws a RuntimeException if there is none.
      DynFields.Builder defaultAlwaysNull()
      Instructs this builder to return AlwaysNull if no implementation is found.
      DynFields.Builder hiddenImpl​(java.lang.Class<?> targetClass, java.lang.String fieldName)
      Checks for a hidden implementation.
      DynFields.Builder hiddenImpl​(java.lang.String className, java.lang.String fieldName)
      Checks for a hidden implementation, first finding the class by name.
      DynFields.Builder impl​(java.lang.Class<?> targetClass, java.lang.String fieldName)
      Checks for an implementation.
      DynFields.Builder impl​(java.lang.String className, java.lang.String fieldName)
      Checks for an implementation, first finding the class by name.
      DynFields.Builder loader​(java.lang.ClassLoader newLoader)
      Set the ClassLoader used to lookup classes by name.
      • Methods inherited from class java.lang.Object

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

      • loader

        public DynFields.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
      • defaultAlwaysNull

        public DynFields.Builder defaultAlwaysNull()
        Instructs this builder to return AlwaysNull if no implementation is found.
        Returns:
        this Builder for method chaining
      • impl

        public DynFields.Builder impl​(java.lang.String className,
                                      java.lang.String fieldName)
        Checks for an implementation, first finding the class by name.
        Parameters:
        className - name of a class
        fieldName - name of the field
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getField(String)
      • impl

        public DynFields.Builder impl​(java.lang.Class<?> targetClass,
                                      java.lang.String fieldName)
        Checks for an implementation.
        Parameters:
        targetClass - a class instance
        fieldName - name of a field (different from constructor)
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getField(String)
      • hiddenImpl

        public DynFields.Builder hiddenImpl​(java.lang.String className,
                                            java.lang.String fieldName)
        Checks for a hidden implementation, first finding the class by name.
        Parameters:
        className - name of a class
        fieldName - name of a field (different from constructor)
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getField(String)
      • hiddenImpl

        public DynFields.Builder hiddenImpl​(java.lang.Class<?> targetClass,
                                            java.lang.String fieldName)
        Checks for a hidden implementation.
        Parameters:
        targetClass - a class instance
        fieldName - name of a field (different from constructor)
        Returns:
        this Builder for method chaining
        See Also:
        Class.forName(String), Class.getField(String)
      • buildChecked

        public <T> DynFields.UnboundField<T> buildChecked()
                                                   throws java.lang.NoSuchFieldException
        Returns the first valid implementation as a UnboundField or throws a NoSuchFieldException if there is none.
        Type Parameters:
        T - Java class stored in the field
        Returns:
        a DynFields.UnboundField with a valid implementation
        Throws:
        java.lang.NoSuchFieldException - if no implementation was found
      • buildChecked

        public <T> DynFields.BoundField<T> buildChecked​(java.lang.Object target)
                                                 throws java.lang.NoSuchFieldException
        Returns the first valid implementation as a BoundMethod or throws a NoSuchMethodException if there is none.
        Type Parameters:
        T - Java class stored in the field
        Parameters:
        target - an Object on which to get and set the field
        Returns:
        a DynFields.BoundField with a valid implementation and target
        Throws:
        java.lang.IllegalStateException - if the method is static
        java.lang.IllegalArgumentException - if the receiver's class is incompatible
        java.lang.NoSuchFieldException - if no implementation was found
      • build

        public <T> DynFields.UnboundField<T> build()
        Returns the first valid implementation as a UnboundField or throws a NoSuchFieldException if there is none.
        Type Parameters:
        T - Java class stored in the field
        Returns:
        a DynFields.UnboundField with a valid implementation
        Throws:
        java.lang.RuntimeException - if no implementation was found
      • build

        public <T> DynFields.BoundField<T> build​(java.lang.Object target)
        Returns the first valid implementation as a BoundMethod or throws a RuntimeException if there is none.
        Type Parameters:
        T - Java class stored in the field
        Parameters:
        target - an Object on which to get and set the field
        Returns:
        a DynFields.BoundField with a valid implementation and target
        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
      • buildStatic

        public <T> DynFields.StaticField<T> buildStatic()
        Returns the first valid implementation as a StaticField or throws a RuntimeException if there is none.
        Type Parameters:
        T - Java class stored in the field
        Returns:
        a DynFields.StaticField with a valid implementation
        Throws:
        java.lang.IllegalStateException - if the method is not static
        java.lang.RuntimeException - if no implementation was found