Class SignatureBuilder


  • class SignatureBuilder
    extends java.lang.Object
    The SignatureBuilder is used to build all permutations of signatures a constructor contains. Permutations are calculated by determining the number of annotations a parameter contains and ensuring a signature is created with one of each. This is useful when a constructor is annotated with a union annotation.
    See Also:
    Signature
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  SignatureBuilder.ParameterList
      The ParameterList object is used to represent a column of parameters within a table.
      private static class  SignatureBuilder.ParameterTable
      The ParameterTable is used to build a table of parameters to represent a constructor.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.reflect.Constructor factory
      this is the constructor that this signature builder is for.
      private SignatureBuilder.ParameterTable table
      This contains each parameter and annotation pair found.
    • Constructor Summary

      Constructors 
      Constructor Description
      SignatureBuilder​(java.lang.reflect.Constructor factory)
      Constructor for the SignatureBuilder object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<Signature> build()
      This method will build all the signatures for the constructor.
      private java.util.List<Signature> build​(SignatureBuilder.ParameterTable matrix)
      This method will build all the signatures for the constructor.
      private void build​(SignatureBuilder.ParameterTable matrix, int index)
      This is used to build all permutations of parameters that exist within the constructor.
      private void build​(SignatureBuilder.ParameterTable matrix, SignatureBuilder.ParameterList signature, int index)
      This is used to build all permutations of parameters that exist within the constructor.
      private java.util.List<Signature> create()
      This is used to create a list of signatures that represent the permutations of parameter and annotation pairs that exist for a single constructor.
      private java.util.List<Signature> create​(SignatureBuilder.ParameterTable matrix)
      This is used to create a list of signatures that represent the permutations of parameter and annotation pairs that exist.
      void insert​(Parameter value, int index)
      This will add a a parameter at the specified column in the table.
      boolean isValid()
      This validates the builder by checking that the width of the table is the same as the count of parameters in the constructor.
      private void populate​(SignatureBuilder.ParameterTable matrix, SignatureBuilder.ParameterList signature, int index)
      This is the final leg of building a permutation where a signature is given to permutate on the last column.
      • Methods inherited from class java.lang.Object

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

      • factory

        private final java.lang.reflect.Constructor factory
        this is the constructor that this signature builder is for.
    • Constructor Detail

      • SignatureBuilder

        public SignatureBuilder​(java.lang.reflect.Constructor factory)
        Constructor for the SignatureBuilder object. This requires the constructor that the signatures will be built for. If the constructor contains no annotations then no signatures will be built, unless this is the default no-arg constructor.
        Parameters:
        factory - this is the constructor to build for
    • Method Detail

      • isValid

        public boolean isValid()
        This validates the builder by checking that the width of the table is the same as the count of parameters in the constructor. If there table width and parameter count does not match then this means the constructor is not fully annotated.
        Returns:
        true if the constructor has been properly annotated
      • insert

        public void insert​(Parameter value,
                           int index)
        This will add a a parameter at the specified column in the table. The parameter is typically added to the table at an index mirroring the index it appears within the constructor.
        Parameters:
        value - this is the parameter to be added in the table
        index - this is the index to added the parameter to
      • build

        public java.util.List<Signature> build()
                                        throws java.lang.Exception
        This method will build all the signatures for the constructor. If a union annotation was used this may result in several signatures being created. Also if this builder represents the default constructor then this returns a single value.
        Returns:
        this returns the list of signatures to be built
        Throws:
        java.lang.Exception
      • build

        private java.util.List<Signature> build​(SignatureBuilder.ParameterTable matrix)
                                         throws java.lang.Exception
        This method will build all the signatures for the constructor. If a union annotation was used this may result in several signatures being created. Also if this builder represents the default constructor then this returns a single value.
        Parameters:
        matrix - this is the matrix of parameters to collect
        Returns:
        this returns the list of signatures to be built
        Throws:
        java.lang.Exception
      • create

        private java.util.List<Signature> create()
                                          throws java.lang.Exception
        This is used to create a list of signatures that represent the permutations of parameter and annotation pairs that exist for a single constructor. The list may be empty.
        Returns:
        this returns the list of signatures that exist
        Throws:
        java.lang.Exception
      • create

        private java.util.List<Signature> create​(SignatureBuilder.ParameterTable matrix)
                                          throws java.lang.Exception
        This is used to create a list of signatures that represent the permutations of parameter and annotation pairs that exist. All permutations are taken from the provided matrix. When building the list of signature the parameter paths are validated.
        Parameters:
        matrix - this contains the permutations of parameters
        Returns:
        this returns the list of signatures for a constructor
        Throws:
        java.lang.Exception
      • build

        private void build​(SignatureBuilder.ParameterTable matrix,
                           int index)
        This is used to build all permutations of parameters that exist within the constructor. By building a matrix of the permutations all possible signatures can be created allowing for a better way to perform dependency injection for the objects.
        Parameters:
        matrix - this is the matrix to hold the permutations
        index - this is the particular index to evaluate
      • build

        private void build​(SignatureBuilder.ParameterTable matrix,
                           SignatureBuilder.ParameterList signature,
                           int index)
        This is used to build all permutations of parameters that exist within the constructor. By building a matrix of the permutations all possible signatures can be created allowing for a better way to perform dependency injection for the objects.
        Parameters:
        matrix - this is the matrix to hold the permutations
        signature - the row to perform a permutation with
        index - this is the particular index to evaluate
      • populate

        private void populate​(SignatureBuilder.ParameterTable matrix,
                              SignatureBuilder.ParameterList signature,
                              int index)
        This is the final leg of building a permutation where a signature is given to permutate on the last column. Once finished the matrix will have a new row of parameters added which represents a new set of permutations to create signatures from.
        Parameters:
        matrix - this is the matrix to hold the permutations
        signature - the row to perform a permutation with
        index - this is the particular index to evaluate