Class Action<T>

  • Type Parameters:
    T - type of value returned in the result of action execution

    public class Action<T>
    extends Object
    Entity that can:
    1. execute a predefined command in a void manner (see get(...) methods of this class);
    2. execute a predefined command and return the result of that execution (see execute(...) methods of this class).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void execute()
      Executes this action.
      <X extends Exception>
      void
      execute​(Class<X> expectedException)
      Executes this action and sets the passed exception class as a unary element of an exception list belonging to this method declaration (throws... clause).
      <X1 extends Exception,​X2 extends Exception>
      void
      execute​(Class<X1> expectedExceptionOne, Class<X2> expectedExceptionTwo)
      Executes this action and respectively sets the passed exception classes as elements of an exception list belonging to this method declaration (throws... clause).
      <X1 extends Exception,​X2 extends Exception,​X3 extends Exception>
      void
      execute​(Class<X1> expectedExceptionOne, Class<X2> expectedExceptionTwo, Class<X3> expectedExceptionThree)
      Executes this action and respectively sets the passed exception classes as elements of an exception list belonging to this method declaration (throws... clause).
      <X1 extends Exception,​X2 extends Exception,​X3 extends Exception,​X4 extends Exception>
      void
      execute​(Class<X1> expectedExceptionOne, Class<X2> expectedExceptionTwo, Class<X3> expectedExceptionThree, Class<X4> expectedExceptionFour)
      Executes this action and respectively sets the passed exception classes as elements of an exception list belonging to this method declaration (throws... clause).
      T get()
      Executes this action and returns a return value that is produced in the result of execution of this action.
      <S> S get​(Class<S> typeToGet)
      Executes this action and returns a return value that is produced in the result of execution of this action, but cast into a specified type.
      <S,​X extends Exception>
      S
      get​(Class<S> typeToGet, Class<X> expectedException)
      Executes this action and returns a return value that is produced in the result of execution of this action, but cast into a specified type.
      <S,​X1 extends Exception,​X2 extends Exception>
      S
      get​(Class<S> typeToGet, Class<X1> expectedExceptionOne, Class<X2> expectedExceptionTwo)
      Executes this action and returns a return value that is produced in the result of execution of this action, but cast into a specified type.
      <S,​X1 extends Exception,​X2 extends Exception,​X3 extends Exception>
      S
      get​(Class<S> typeToGet, Class<X1> expectedExceptionOne, Class<X2> expectedExceptionTwo, Class<X3> expectedExceptionThree)
      Executes this action and returns a return value that is produced in the result of execution of this action, but cast into a specified type.
      <S,​X1 extends Exception,​X2 extends Exception,​X3 extends Exception,​X4 extends Exception>
      S
      get​(Class<S> typeToGet, Class<X1> expectedExceptionOne, Class<X2> expectedExceptionTwo, Class<X3> expectedExceptionThree, Class<X4> expectedExceptionFour)
      Executes this action and returns a return value that is produced in the result of execution of this action, but cast into a specified type.
    • Constructor Detail

      • Action

        public Action​(@Nonnull
                      Callable<T> engine)
        Constructs an action based on the passed Callable.

        Contrary to an action based on a passed Runnable, this constructor constructs an action which in the result of its execution returns a value computed by the call of a Callable.call() method belonging to the passed Callable. Therefore, type parameter of an action constructed with this constructor is strongly recommended to describe the type of value that is supposed to be returned, e.g. Action<String> (see examples below).

        Example:

        
         Action<String> actionOne = new Action<>(() -> "Hello, Universe!");
        
         Action<String> actionTwo = new Action<>(() -> {
           System.out.println("Hello, Universe!");
           return "How can I help you?";
         });
        
         int num = 10;
         Action<String> actionThree = new Action<>(() -> {
           if (num % 2 != 0) {
             throw new Exception("The passed number must be even");
           }
           return "The passed number is even";
         }); 
        Parameters:
        engine - entity used for method calls of a constructed action
      • Action

        public Action​(@Nonnull
                      Runnable engine)
        Constructs an action based on the passed Runnable.

        Contrary to an action based on a passed Callable, this constructor constructs an action which in the result of its execution always returns null. Therefore, type parameter of an action constructed with this constructor can be defined with a wildcard: Action<?> (see examples below).

        The passed Runnable is wrapped into a Callable. As a result, the execution of this action is performed via nested method calls. Firstly the wrapper Callable.call() method is called that subsequently:

        1. calls the wrapped Runnable.run() method;
        2. returns null.

        Example:

        
         Action<?> actionOne = new Action<>(() -> System.out.println("Hello, Universe!"));
        
         Action<?> actionTwo = new Action<>(() -> {
           System.out.println("Hello, Universe!");
           System.out.println("How can I help you?");
         });
        Parameters:
        engine - entity used for method calls of a constructed action
    • Method Detail

      • execute

        public void execute()
        Executes this action.
        1. Execution is performed via calling a Callable.call() method of the underlying Callable.
        2. If this action was constructed with the use of Runnable, then calling a Callable.call() method of the underlying Callable causes the call of a Runnable.run() method belonging to the Runnable wrapped into the underlying Callable:
          
               Action.execute()
                  └──Callable.call()
                        └──Runnable.run()
               
        3. A return value that is produced in the result of execution of this action is ignored.
        4. This method can be called multiple times. However, in case of calling it more than once side effects caused by a previous call are possible.
        Throws:
        Exception - if an Exception during execution of this action was thrown; note that the Exception isn't specified in a method declaration in a throws... clause in order to avoid enforcing that Exception handling (omitting of specifying the Exception in the method declaration is achieved via SneakyThrows)
      • execute

        public <X extends Exception> void execute​(@Nullable
                                                  Class<X> expectedException)
                                           throws X extends Exception
        Executes this action and sets the passed exception class as a unary element of an exception list belonging to this method declaration (throws... clause). If the passed exception class is null, it will be ignored.
        1. The only thing this method does internally is calling an execute() method. Therefore, for details on the execution see documentation for execute().
        2. The only relevant difference between this method and an execute() method is that this method declaration has an exception list (throws... clause) with one element inside, which is the passed exception class. The reason behind such solution is that an execute() method doesn't have a throws... clause, although it is capable of throwing an Exception (the clause is omitted via SneakyThrows), which allows to avoid enforcing of Exception handling. In cases, where enforcing of such handling is, however, required, this method can be used.
        3. Consider the following action. It always throws an IOException, which is a subclass of an Exception:
          
               Action<?> action = new Action<>(() -> {
                    throw new IOException();
               });
               
          However, the first execution method below will not enforce any Exception handling, while the second one - will:
          
               action.execute(); // Doesn't enforce exception handling
          
               try {
                   action.execute(IOException.class); // Does enforce exception handling
               } catch (IOException exception) {
                   log.error("Unable to read a file", exception);
               }
               
        Type Parameters:
        X - an exception class that will be set as a unary element of an exception list belonging to this method declaration, i.e. as a unary element of the throws... clause
        Parameters:
        expectedException - class representing an exception class that will be set as a unary element of an exception list belonging to this method declaration, i.e. as a unary element of the throws... clause
        Throws:
        X - if an Exception of X type during execution of this action was thrown
        X extends Exception
      • execute

        public <X1 extends Exception,​X2 extends Exception> void execute​(@Nullable
                                                                              Class<X1> expectedExceptionOne,
                                                                              @Nullable
                                                                              Class<X2> expectedExceptionTwo)
                                                                       throws X1 extends Exception,
                                                                              X2 extends Exception
        Executes this action and respectively sets the passed exception classes as elements of an exception list belonging to this method declaration (throws... clause). If the passed exception class is null, it will be ignored.
        1. The only thing this method does internally is calling an execute() method. Therefore, for details on the execution see documentation for execute().
        2. The only relevant difference between this method and an execute() method is that this method declaration has an exception list (throws... clause), which is respectively defined by the passed exception classes. The reason behind such solution is that an execute() method doesn't have a throws... clause, although it is capable of throwing an Exception (the clause is omitted via SneakyThrows), which allows to avoid enforcing of Exception handling. In cases, where enforcing of such handling is, however, required, this method can be used.
        3. Consider the following action. It always throws an IOException, which is a subclass of an Exception:
          
               Action<?> action = new Action<>(() -> {
                    throw new IOException();
               });
               
          However, the first execution method below will not enforce any Exception handling, while the second one - will:
          
               action.execute(); // Doesn't enforce exception handling
          
               try {
                   action.execute(IOException.class); // Does enforce exception handling
               } catch (IOException exception) {
                   log.error("Unable to read a file", exception);
               }
               
        Type Parameters:
        X1 - an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        X2 - an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        Parameters:
        expectedExceptionOne - class representing an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        expectedExceptionTwo - class representing an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        Throws:
        X1 - if an Exception of X1 type during execution of this action was thrown
        X2 - if an Exception of X2 type during execution of this action was thrown
        X1 extends Exception
      • execute

        public <X1 extends Exception,​X2 extends Exception,​X3 extends Exception> void execute​(@Nullable
                                                                                                         Class<X1> expectedExceptionOne,
                                                                                                         @Nullable
                                                                                                         Class<X2> expectedExceptionTwo,
                                                                                                         @Nullable
                                                                                                         Class<X3> expectedExceptionThree)
                                                                                                  throws X1 extends Exception,
                                                                                                         X2 extends Exception,
                                                                                                         X3 extends Exception
        Executes this action and respectively sets the passed exception classes as elements of an exception list belonging to this method declaration (throws... clause). If the passed exception class is null, it will be ignored.
        1. The only thing this method does internally is calling an execute() method. Therefore, for details on the execution see documentation for execute().
        2. The only relevant difference between this method and an execute() method is that this method declaration has an exception list (throws... clause), which is respectively defined by the passed exception classes. The reason behind such solution is that an execute() method doesn't have a throws... clause, although it is capable of throwing an Exception (the clause is omitted via SneakyThrows), which allows to avoid enforcing of Exception handling. In cases, where enforcing of such handling is, however, required, this method can be used.
        3. Consider the following action. It always throws an IOException, which is a subclass of an Exception:
          
               Action<?> action = new Action<>(() -> {
                    throw new IOException();
               });
               
          However, the first execution method below will not enforce any Exception handling, while the second one - will:
          
               action.execute(); // Doesn't enforce exception handling
          
               try {
                   action.execute(IOException.class); // Does enforce exception handling
               } catch (IOException exception) {
                   log.error("Unable to read a file", exception);
               }
               
        Type Parameters:
        X1 - an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        X2 - an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        X3 - an exception class that will be set as a third element of an exception list belonging to this method declaration, i.e. as a third element of the throws... clause
        Parameters:
        expectedExceptionOne - class representing an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        expectedExceptionTwo - class representing an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        expectedExceptionThree - class representing an exception class that will be set as a third element of an exception list belonging to this method declaration, i.e. as a third element of the throws... clause
        Throws:
        X1 - if an Exception of X1 type during execution of this action was thrown
        X2 - if an Exception of X2 type during execution of this action was thrown
        X3 - if an Exception of X3 type during execution of this action was thrown
        X1 extends Exception
      • execute

        public <X1 extends Exception,​X2 extends Exception,​X3 extends Exception,​X4 extends Exception> void execute​(@Nullable
                                                                                                                                    Class<X1> expectedExceptionOne,
                                                                                                                                    @Nullable
                                                                                                                                    Class<X2> expectedExceptionTwo,
                                                                                                                                    @Nullable
                                                                                                                                    Class<X3> expectedExceptionThree,
                                                                                                                                    @Nullable
                                                                                                                                    Class<X4> expectedExceptionFour)
                                                                                                                             throws X1 extends Exception,
                                                                                                                                    X2 extends Exception,
                                                                                                                                    X3 extends Exception,
                                                                                                                                    X4 extends Exception
        Executes this action and respectively sets the passed exception classes as elements of an exception list belonging to this method declaration (throws... clause). If the passed exception class is null, it will be ignored.
        1. The only thing this method does internally is calling an execute() method. Therefore, for details on the execution see documentation for execute().
        2. The only relevant difference between this method and an execute() method is that this method declaration has an exception list (throws... clause), which is respectively defined by the passed exception classes. The reason behind such solution is that an execute() method doesn't have a throws... clause, although it is capable of throwing an Exception (the clause is omitted via SneakyThrows), which allows to avoid enforcing of Exception handling. In cases, where enforcing of such handling is, however, required, this method can be used.
        3. Consider the following action. It always throws an IOException, which is a subclass of an Exception:
          
               Action<?> action = new Action<>(() -> {
                    throw new IOException();
               });
               
          However, the first execution method below will not enforce any Exception handling, while the second one - will:
          
               action.execute(); // Doesn't enforce exception handling
          
               try {
                   action.execute(IOException.class); // Does enforce exception handling
               } catch (IOException exception) {
                   log.error("Unable to read a file", exception);
               }
               
        Type Parameters:
        X1 - an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        X2 - an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        X3 - an exception class that will be set as a third element of an exception list belonging to this method declaration, i.e. as a third element of the throws... clause
        X4 - an exception class that will be set as a fourth element of an exception list belonging to this method declaration, i.e. as a fourth element of the throws... clause
        Parameters:
        expectedExceptionOne - class representing an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        expectedExceptionTwo - class representing an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        expectedExceptionThree - class representing an exception class that will be set as a third element of an exception list belonging to this method declaration, i.e. as a third element of the throws... clause
        expectedExceptionFour - class representing an exception class that will be set as a fourth element of an exception list belonging to this method declaration, i.e. as a fourth element of the throws... clause
        Throws:
        X1 - if an Exception of X1 type during execution of this action was thrown
        X2 - if an Exception of X2 type during execution of this action was thrown
        X3 - if an Exception of X3 type during execution of this action was thrown
        X4 - if an Exception of X4 type during execution of this action was thrown
        X1 extends Exception
      • get

        @Nullable
        public T get()
        Executes this action and returns a return value that is produced in the result of execution of this action.
        1. This method can be called multiple times. However, in case of calling it more than once side effects caused by a previous call are possible.
        2. For details on the execution see documentation for execute().
        Returns:
        return value that is produced in the result of execution of this action; if null is produced, then null is returned; if this action was constructed with the use of Runnable, then null is always returned
        Throws:
        Exception - if an Exception during execution of this action was thrown; note that the Exception isn't specified in a method declaration in a throws... clause in order to avoid enforcing that Exception handling (omitting of specifying the Exception in the method declaration is achieved via SneakyThrows)
      • get

        @Nullable
        public <S> S get​(@Nonnull
                         Class<S> typeToGet)
        Executes this action and returns a return value that is produced in the result of execution of this action, but cast into a specified type.
        1. This method can be called multiple times. However, in case of calling it more than once side effects caused by a previous call are possible.
        2. For details on the execution see documentation for execute().
        3. Example with String:
          
           Callable<String> callableWithString = () -> "Hello, Universe!";
           Action<String> actionWithString = new Action<>(callableWithString);
           String returnedValue = actionWithString.get(String.class);
           // result: "Hello, Universe!"
               
        4. Example with null:
           
           Callable<?> callableWithNull = () -> null;
           Action<?> actionWithNull = new Action<>(callableWithNull);
           String returnedValue = actionWithNull.get(String.class);
           // result: null
               
        5. Example with List:
          
           List<String> listToReturn = new ArrayList<>(List.of("Hello, Universe!"));
           Callable<List<String>> callableWithList = () -> listToReturn;
           Action<List<String>> actionWithList = new Action<>(callableWithList);
           List<String> returnedValue = actionWithList.get(List.class);
           // result: listToReturn == returnedValue
               
        Type Parameters:
        S - type to which the return value will be cast into
        Parameters:
        typeToGet - Class representing a type (<S>) to which the return value will be cast into
        Returns:
        return value that is produced in the result of execution of this action and cast into a specified type (typeToGet); if null is produced, then null is returned regardless of the passed typeToGet; if this action was constructed with the use of Runnable, then null is always returned
        Throws:
        MismatchedReturnTypeException - if a return value cannot be cast into a specified type (typeToGet) due to ClassCastException
        Exception - if an Exception during execution of this action was thrown; note that the Exception isn't specified in a method declaration in a throws... clause in order to avoid enforcing that Exception handling (omitting of specifying the Exception in the method declaration is achieved via SneakyThrows)
      • get

        @Nullable
        public <S,​X extends Exception> S get​(@Nonnull
                                                   Class<S> typeToGet,
                                                   @Nullable
                                                   Class<X> expectedException)
                                            throws X extends Exception
        Executes this action and returns a return value that is produced in the result of execution of this action, but cast into a specified type. The passed exception class is set as a unary element of an exception list belonging to this method declaration (throws... clause). If the passed exception class is null, it will be ignored.
        1. The only thing this method does internally is calling a get(Class) method. Therefore, for details on the execution see documentation for get(Class).
        2. The only relevant difference between this method and a get(Class) method is that this method declaration has an exception list (throws... clause) with one element inside, which is the passed exception class. The reason behind such solution is that a get(Class) method doesn't have a throws... clause, although it is capable of throwing an Exception (the clause is omitted via SneakyThrows), which allows to avoid enforcing of Exception handling. In cases, where enforcing of such handling is, however, required, this method can be used.
        3. Consider the following action. It always throws an IOException, which is a subclass of an Exception:
          
               Action<?> action = new Action<>(() -> {
                   throw new IOException();
               });
               
          However, the first get method below will not enforce any Exception handling, while the second one - will:
          
               String resultOne = action.get(String.class); // Doesn't enforce exception handling
          
               try {
                   String resultTwo = action.get(String.class, IOException.class); // Does enforce exception handling
               } catch (IOException exception) {
                   log.error("Unable to read a file", exception);
               }
               
        Type Parameters:
        S - type to which the return value will be cast into
        X - an exception class that will be set as a unary element of an exception list belonging to this method declaration, i.e. as a unary element of the throws... clause
        Parameters:
        typeToGet - Class representing a type (<S>) to which the return value will be cast into
        expectedException - class representing an exception class that will be set as a unary element of an exception list belonging to this method declaration, i.e. as a unary element of the throws... clause
        Returns:
        return value that is produced in the result of execution of this action and cast into a specified type (typeToGet); if null is produced, then null is returned regardless of the passed typeToGet; if this action was constructed with the use of Runnable, then null is always returned
        Throws:
        X - if an Exception of X type during execution of this action was thrown
        X extends Exception
      • get

        @Nullable
        public <S,​X1 extends Exception,​X2 extends Exception> S get​(@Nonnull
                                                                               Class<S> typeToGet,
                                                                               @Nullable
                                                                               Class<X1> expectedExceptionOne,
                                                                               @Nullable
                                                                               Class<X2> expectedExceptionTwo)
                                                                        throws X1 extends Exception,
                                                                               X2 extends Exception
        Executes this action and returns a return value that is produced in the result of execution of this action, but cast into a specified type. The passed exception classes are set as elements of an exception list belonging to this method declaration (throws... clause). If the passed exception class is null, it will be ignored.
        1. The only thing this method does internally is calling a get(Class) method. Therefore, for details on the execution see documentation for get(Class).
        2. The only relevant difference between this method and a get(Class) method is that this method declaration has an exception list (throws... clause), which is respectively defined by the passed exception classes. The reason behind such solution is that a get(Class) method doesn't have a throws... clause, although it is capable of throwing an Exception (the clause is omitted via SneakyThrows), which allows to avoid enforcing of Exception handling. In cases, where enforcing of such handling is, however, required, this method can be used.
        3. Consider the following action. It always throws an IOException, which is a subclass of an Exception:
          
               Action<?> action = new Action<>(() -> {
                   throw new IOException();
               });
               
          However, the first get method below will not enforce any Exception handling, while the second one - will:
          
               String resultOne = action.get(String.class); // Doesn't enforce exception handling
          
               try {
                   String resultTwo = action.get(String.class, IOException.class); // Does enforce exception handling
               } catch (IOException exception) {
                   log.error("Unable to read a file", exception);
               }
               
        Type Parameters:
        S - type to which the return value will be cast into
        X1 - an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        X2 - an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        Parameters:
        typeToGet - Class representing a type (<S>) to which the return value will be cast into
        expectedExceptionOne - class representing an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        expectedExceptionTwo - class representing an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        Returns:
        return value that is produced in the result of execution of this action and cast into a specified type (typeToGet); if null is produced, then null is returned regardless of the passed typeToGet; if this action was constructed with the use of Runnable, then null is always returned
        Throws:
        X1 - if an Exception of X1 type during execution of this action was thrown
        X2 - if an Exception of X2 type during execution of this action was thrown
        X1 extends Exception
      • get

        @Nullable
        public <S,​X1 extends Exception,​X2 extends Exception,​X3 extends Exception> S get​(@Nonnull
                                                                                                          Class<S> typeToGet,
                                                                                                          @Nullable
                                                                                                          Class<X1> expectedExceptionOne,
                                                                                                          @Nullable
                                                                                                          Class<X2> expectedExceptionTwo,
                                                                                                          @Nullable
                                                                                                          Class<X3> expectedExceptionThree)
                                                                                                   throws X1 extends Exception,
                                                                                                          X2 extends Exception,
                                                                                                          X3 extends Exception
        Executes this action and returns a return value that is produced in the result of execution of this action, but cast into a specified type. The passed exception classes are set as elements of an exception list belonging to this method declaration (throws... clause). If the passed exception class is null, it will be ignored.
        1. The only thing this method does internally is calling a get(Class) method. Therefore, for details on the execution see documentation for get(Class).
        2. The only relevant difference between this method and a get(Class) method is that this method declaration has an exception list (throws... clause), which is respectively defined by the passed exception classes. The reason behind such solution is that a get(Class) method doesn't have a throws... clause, although it is capable of throwing an Exception (the clause is omitted via SneakyThrows), which allows to avoid enforcing of Exception handling. In cases, where enforcing of such handling is, however, required, this method can be used.
        3. Consider the following action. It always throws an IOException, which is a subclass of an Exception:
          
               Action<?> action = new Action<>(() -> {
                   throw new IOException();
               });
               
          However, the first get method below will not enforce any Exception handling, while the second one - will:
          
               String resultOne = action.get(String.class); // Doesn't enforce exception handling
          
               try {
                   String resultTwo = action.get(String.class, IOException.class); // Does enforce exception handling
               } catch (IOException exception) {
                   log.error("Unable to read a file", exception);
               }
               
        Type Parameters:
        S - type to which the return value will be cast into
        X1 - an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        X2 - an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        X3 - an exception class that will be set as a third element of an exception list belonging to this method declaration, i.e. as a third element of the throws... clause
        Parameters:
        typeToGet - Class representing a type (<S>) to which the return value will be cast into
        expectedExceptionOne - class representing an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        expectedExceptionTwo - class representing an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        expectedExceptionThree - class representing an exception class that will be set as a third element of an exception list belonging to this method declaration, i.e. as a third element of the throws... clause
        Returns:
        return value that is produced in the result of execution of this action and cast into a specified type (typeToGet); if null is produced, then null is returned regardless of the passed typeToGet; if this action was constructed with the use of Runnable, then null is always returned
        Throws:
        X1 - if an Exception of X1 type during execution of this action was thrown
        X2 - if an Exception of X2 type during execution of this action was thrown
        X3 - if an Exception of X3 type during execution of this action was thrown
        X1 extends Exception
      • get

        @Nullable
        public <S,​X1 extends Exception,​X2 extends Exception,​X3 extends Exception,​X4 extends Exception> S get​(@Nonnull
                                                                                                                                     Class<S> typeToGet,
                                                                                                                                     @Nullable
                                                                                                                                     Class<X1> expectedExceptionOne,
                                                                                                                                     @Nullable
                                                                                                                                     Class<X2> expectedExceptionTwo,
                                                                                                                                     @Nullable
                                                                                                                                     Class<X3> expectedExceptionThree,
                                                                                                                                     @Nullable
                                                                                                                                     Class<X4> expectedExceptionFour)
                                                                                                                              throws X1 extends Exception,
                                                                                                                                     X2 extends Exception,
                                                                                                                                     X3 extends Exception,
                                                                                                                                     X4 extends Exception
        Executes this action and returns a return value that is produced in the result of execution of this action, but cast into a specified type. The passed exception classes are set as elements of an exception list belonging to this method declaration (throws... clause). If the passed exception class is null, it will be ignored.
        1. The only thing this method does internally is calling a get(Class) method. Therefore, for details on the execution see documentation for get(Class).
        2. The only relevant difference between this method and a get(Class) method is that this method declaration has an exception list (throws... clause), which is respectively defined by the passed exception classes. The reason behind such solution is that a get(Class) method doesn't have a throws... clause, although it is capable of throwing an Exception (the clause is omitted via SneakyThrows), which allows to avoid enforcing of Exception handling. In cases, where enforcing of such handling is, however, required, this method can be used.
        3. Consider the following action. It always throws an IOException, which is a subclass of an Exception:
          
               Action<?> action = new Action<>(() -> {
                   throw new IOException();
               });
               
          However, the first get method below will not enforce any Exception handling, while the second one - will:
          
               String resultOne = action.get(String.class); // Doesn't enforce exception handling
          
               try {
                   String resultTwo = action.get(String.class, IOException.class); // Does enforce exception handling
               } catch (IOException exception) {
                   log.error("Unable to read a file", exception);
               }
               
        Type Parameters:
        S - type to which the return value will be cast into
        X1 - an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        X2 - an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        X3 - an exception class that will be set as a third element of an exception list belonging to this method declaration, i.e. as a third element of the throws... clause
        X4 - an exception class that will be set as a fourth element of an exception list belonging to this method declaration, i.e. as a fourth element of the throws... clause
        Parameters:
        typeToGet - Class representing a type (<S>) to which the return value will be cast into
        expectedExceptionOne - class representing an exception class that will be set as a first element of an exception list belonging to this method declaration, i.e. as a first element of the throws... clause
        expectedExceptionTwo - class representing an exception class that will be set as a second element of an exception list belonging to this method declaration, i.e. as a second element of the throws... clause
        expectedExceptionThree - class representing an exception class that will be set as a third element of an exception list belonging to this method declaration, i.e. as a third element of the throws... clause
        expectedExceptionFour - class representing an exception class that will be set as a fourth element of an exception list belonging to this method declaration, i.e. as a fourth element of the throws... clause
        Returns:
        return value that is produced in the result of execution of this action and cast into a specified type (typeToGet); if null is produced, then null is returned regardless of the passed typeToGet; if this action was constructed with the use of Runnable, then null is always returned
        Throws:
        X1 - if an Exception of X1 type during execution of this action was thrown
        X2 - if an Exception of X2 type during execution of this action was thrown
        X3 - if an Exception of X3 type during execution of this action was thrown
        X4 - if an Exception of X4 type during execution of this action was thrown
        X1 extends Exception