Class InitialisationUtil


  • public final class InitialisationUtil
    extends Object
    • Method Detail

      • initializeFromQualifiedName

        @NotNull
        @Contract(pure=true)
        public static <T> T initializeFromQualifiedName​(@NotNull
                                                        @NotNull String qualifiedClassName,
                                                        @NotNull
                                                        @NotNull Class<? extends T> superClass,
                                                        @NotNull
                                                        @NotNull Class<?>... furtherSuperClasses)
        Initializes a class from qualifiedClassName as type superClass. Further constrains for implemented classes and interfaces are possible via furtherSuperClasses.

        Requirements:

        qualifiedClassName:

        1. Has an accessible empty constructor.
        2. Points to a class extending/implementing superClass.
        3. Points to a class extending/implementing all furtherSuperClasses.
        4. Points to a class that is not primitive, abstract or an interface.
        5. Points to an existing class.
        6. Is not blank.

        superClass:

        1. Does not point to a primitive.
        2. Points to a class extending/implemented by the class of qualifiedClassName.

        furtherSuperClasses

        1. Points to classes extending/implemented by the class of qualifiedClassName.
        Type Parameters:
        T - the type of the returned class.
        Parameters:
        qualifiedClassName - the qualified name for the class to be initialized.
        superClass - defines the type to be instantiated
        furtherSuperClasses - further checks for specific interfaces etc.
        Returns:
        an instance of qualifiedClassName of type superClass extending/implementing all furtherSuperClasses.
        Throws:
        RuntimeException - if the superClass is not assignable to the class of clazz
        RuntimeException - if any of the furtherSuperClasses is not assignable to the class of clazz
        RuntimeException - if the superClass is a primitive
        RuntimeException - if the clazz is not pointing to a class.
        RuntimeException - if the clazz is blank.
        RuntimeException - if either the underlying constructor is inaccessbible, no empty constructor found or the underlying class is somehow abstract.
        RuntimeException - if the underlying constructor threw an exception.
        RuntimeException - if the clazz points to a interface, abstract class or primitive.
      • getClassFor

        @NotNull
        @Contract(pure=true)
        public static <T> @NotNull Class<? extends T> getClassFor​(@NotNull
                                                                  @NotNull String qualifiedClassName,
                                                                  @NotNull
                                                                  @NotNull Class<? extends T> superClass,
                                                                  @NotNull
                                                                  @NotNull Class<?>... furtherSuperClasses)
        Retrieves a class-instance for qualifiedClassName extending T. T is supplied by contraining the type of qualifiedClassName to superClass. Further constrains for implemented classes and interfaces are possible via furtherSuperClasses.

        Requirements:

        clazz:

        1. Points to a class extending/implementing superClass.
        2. Points to a class extending/implementing all furtherSuperClasses.
        3. Points to a class that is not primitive, abstract or an interface.
        4. Points to an existing class.
        5. Is not blank.

        superClass:

        1. Does not point to a primitive.
        2. Points to a class extending/implemented by the class of clazz.

        furtherSuperClasses

        1. Points to classes extending/implemented by the class of clazz.
        Type Parameters:
        T - the type extended by the returned class.
        Parameters:
        qualifiedClassName - the qualified name for the class to be retrieved.
        superClass - defines the type to be instantiated
        furtherSuperClasses - further checks for specific interfaces etc.
        Returns:
        an instance of clazz of type superClass extending/implementing all furtherSuperClasses.
        Throws:
        RuntimeException - if the superClass is not assignable to the class of clazz
        RuntimeException - if any of the furtherSuperClasses is not assignable to the class of clazz
        RuntimeException - if the superClass is a primitive
        RuntimeException - if the clazz is not pointing to a class.
        RuntimeException - if the clazz is blank.
      • initializeFromClass

        @NotNull
        @Contract(pure=true)
        public static <T> T initializeFromClass​(@NotNull
                                                @NotNull Class<?> clazz,
                                                @NotNull
                                                @NotNull Class<? extends T> superClass,
                                                @NotNull
                                                @NotNull Class<?>... furtherSuperClasses)
        Initializes a class from clazz as type superClass. Further constrains for implemented classes and interfaces are possible via furtherSuperClasses.

        Requirements:

        clazz:

        1. Has an accessible empty constructor.
        2. Points to a class extending/implementing superClass.
        3. Points to a class extending/implementing all furtherSuperClasses.
        4. Points to a class that is not primitive, abstract or an interface.
        5. Points to an existing class.
        6. Is not blank.

        superClass:

        1. Does not point to a primitive.
        2. Points to a class extending/implemented by the class of clazz.

        furtherSuperClasses

        1. Points to classes extending/implemented by the class of clazz.
        Type Parameters:
        T - the type of the returned class.
        Parameters:
        clazz - the class to be initialized.
        superClass - defines the type to be instantiated
        furtherSuperClasses - further checks for specific interfaces etc.
        Returns:
        an instance of clazz of type superClass extending/implementing all furtherSuperClasses.
        Throws:
        RuntimeException - if either the underlying constructor is inaccessbible, no empty constructor found or the underlying class is somehow abstract.
        RuntimeException - if the underlying constructor threw an exception.
        RuntimeException - if the clazz points to a interface, abstract class or primitive.
        RuntimeException - if the superClass is not assignable to the class of clazz
        RuntimeException - if any of the furtherSuperClasses is not assignable to the class of clazz
        RuntimeException - if the superClass is a primitive
      • initializeFromClass

        @NotNull
        @Contract(pure=true)
        public static <T> T initializeFromClass​(@NotNull
                                                @NotNull Class<? extends T> clazz)
        Initializes a class from clazz of type T.

        Requirements:

        clazz:

        1. Points to a class that is not primitive, abstract or an interface.
        Type Parameters:
        T - the type of the returned class.
        Parameters:
        clazz - the class to be initialized.
        Returns:
        an instance of clazz.
        Throws:
        RuntimeException - if either the underlying constructor is inaccessbible, no empty constructor found or the underlying class is somehow abstract.
        RuntimeException - if the underlying constructor threw an exception.
        RuntimeException - if the clazz points to a interface, abstract class or primitive.
      • requireSuperClass

        @Contract(pure=true)
        public static <T> Class<? extends T> requireSuperClass​(@NotNull
                                                               @NotNull Class<?> clazz,
                                                               @NotNull
                                                               @NotNull Class<? extends T> superClass,
                                                               @NotNull
                                                               @NotNull Class<?>... furtherSuperClasses)
        Asserts the following:

        clazz:

        1. Points to a class extending/implementing superClass.
        2. Points to a class extending/implementing all furtherSuperClasses.
        3. Points to a class that is not primitive, abstract or an interface.

        superClass:

        1. Does not point to a primitive.
        2. Points to a class extending/implemented by the class of clazz.

        furtherSuperClasses

        1. Points to classes extending/implemented by the class of clazz.
        Returns:
        Either fails or returns clazz cast to Class<? extends T>
        Throws:
        RuntimeException - if the clazz points to a interface, abstract class or primitive.
        RuntimeException - if the superClass is not assignable to the class of clazz
        RuntimeException - if any of the furtherSuperClasses is not assignable to the class of clazz
        RuntimeException - if the superClass is a primitive