Class ExecutionPreconditions


  • public final class ExecutionPreconditions
    extends Object
    Utility methods that helps verifying conditions conducted in expression while transaction execution. If the condition is not met, the ExecutionPreconditions method throws ExecutionException.

    Consider the following example:

    
       void checkEnoughMoney(long balance, long amount) {
         if(balance < amount) {
           throw new ExecutionException((byte)3, "Not enough money. Operation amount is " + amount
           + ", but actual balance was " + balance);
         }
       }
     

    which can be replaced using ExecutionPreconditions:

    
       checkExecution(amount <= balance, (byte)3,
           "Not enough money. Operation amount is %s, but actual balance was %s",
           amount, balance);
     
    See Also:
    ExecutionException
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkExecution​(boolean expression, byte errorCode)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable Object errorMessage)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, int arg1)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, int arg1, int arg2)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, int arg1, long arg2)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, int arg1, @Nullable Object arg2)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, long arg1)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, long arg1, int arg2)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, long arg1, long arg2)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, long arg1, @Nullable Object arg2)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, @Nullable Object arg1)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, @Nullable Object arg1, int arg2)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, @Nullable Object arg1, long arg2)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, @Nullable Object arg1, @Nullable Object arg2)
      Verifies the truth of the given expression.
      static void checkExecution​(boolean expression, byte errorCode, @Nullable String errorMessageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3)
      Verifies the truth of the given expression.
    • Method Detail

      • checkExecution

        public static void checkExecution​(boolean expression,
                                          byte errorCode)
        Verifies the truth of the given expression.
        Parameters:
        expression - a boolean expression
        errorCode - execution error code
        Throws:
        ExecutionException - if expression is false
      • checkExecution

        public static void checkExecution​(boolean expression,
                                          byte errorCode,
                                          @Nullable Object errorMessage)
        Verifies the truth of the given expression.
        Parameters:
        expression - a boolean expression
        errorCode - execution error code
        errorMessage - execution error description to use if the check fails
        Throws:
        ExecutionException - if expression is false
      • checkExecution

        public static void checkExecution​(boolean expression,
                                          byte errorCode,
                                          @Nullable String errorMessageTemplate,
                                          @Nullable Object... errorMessageArgs)
        Verifies the truth of the given expression.
        Parameters:
        expression - a boolean expression
        errorCode - execution error code
        errorMessageTemplate - execution error description template to use if the check fails. The template could have placeholders %s which will be replaced by arguments resolved by position
        errorMessageArgs - arguments to be used in the template. Each argument will be converted to string using String.valueOf(Object)
        Throws:
        ExecutionException - if expression is false