Class ExecutionPreconditions

java.lang.Object
com.exonum.binding.core.service.ExecutionPreconditions

public final class ExecutionPreconditions
extends java.lang.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

    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 java.lang.Object errorMessage)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, int arg1)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, int arg1, int arg2)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, int arg1, long arg2)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, int arg1, @Nullable java.lang.Object arg2)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, long arg1)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, long arg1, int arg2)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, long arg1, long arg2)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, long arg1, @Nullable java.lang.Object arg2)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object arg1)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object... errorMessageArgs)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object arg1, int arg2)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object arg1, long arg2)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object arg1, @Nullable java.lang.Object arg2)
    Verifies the truth of the given expression.
    static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object arg1, @Nullable java.lang.Object arg2, @Nullable java.lang.Object arg3)
    Verifies the truth of the given expression.

    Methods inherited from class java.lang.Object

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

    • 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 java.lang.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 java.lang.String errorMessageTemplate, @Nullable java.lang.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
    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, int arg1)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, int arg1, int arg2)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, int arg1, long arg2)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, int arg1, @Nullable java.lang.Object arg2)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, long arg1)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, long arg1, int arg2)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, long arg1, long arg2)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, long arg1, @Nullable java.lang.Object arg2)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object arg1)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object arg1, int arg2)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object arg1, long arg2)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object arg1, @Nullable java.lang.Object arg2)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.

    • checkExecution

      public static void checkExecution​(boolean expression, byte errorCode, @Nullable java.lang.String errorMessageTemplate, @Nullable java.lang.Object arg1, @Nullable java.lang.Object arg2, @Nullable java.lang.Object arg3)
      Verifies the truth of the given expression.

      See checkExecution(boolean, byte, String, Object...) for details.