Class Validations

java.lang.Object
com.atlassian.bamboo.utils.Validations

public class Validations extends Object
Convenience methods that help a method or constructor check whether it was invoked correctly.
Since:
10.0
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    checkArgument(boolean expression)
    Ensures the truth of an expression involving one or more parameters to the calling method.
    static void
    checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs)
    Ensures the truth of an expression involving one or more parameters to the calling method.
    static <T> T
    checkNotNull(T reference)
    Ensures that an object reference is not null.
    static <T> T
    checkNotNull(T reference, @NotNull String errorMessage)
    Ensures that an object reference is not null.
    static void
    checkState(boolean expression)
    Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
    static void
    checkState(boolean expression, @NotNull String errorMessage)
    Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.

    Methods inherited from class java.lang.Object

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

    • Validations

      public Validations()
  • Method Details

    • checkArgument

      public static void checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs)
      Ensures the truth of an expression involving one or more parameters to the calling method.
      Parameters:
      expression - a boolean expression representing the condition to be checked
      errorMessageTemplate - a template for the error message in case the check fail
      errorMessageArgs - the arguments to be substituted into the message template
      Throws:
      IllegalArgumentException - if expression is false
    • checkArgument

      public static void checkArgument(boolean expression)
      Ensures the truth of an expression involving one or more parameters to the calling method.
      Parameters:
      expression - a boolean expression
      Throws:
      IllegalArgumentException - if expression is false
    • checkNotNull

      public static <T> T checkNotNull(@Nullable T reference, @NotNull @NotNull String errorMessage)
      Ensures that an object reference is not null.
      Type Parameters:
      T - the type of the reference
      Parameters:
      reference - the object reference to check for nullity
      errorMessage - the error message to be used in the exception thrown when reference is null
      Returns:
      reference if not null
      Throws:
      NullPointerException - if reference is null
    • checkNotNull

      public static <T> T checkNotNull(@Nullable T reference)
      Ensures that an object reference is not null.
      Type Parameters:
      T - the type of the reference
      Parameters:
      reference - the object reference to check for nullity
      Returns:
      reference if not null
      Throws:
      NullPointerException - if reference is null
    • checkState

      public static void checkState(boolean expression, @NotNull @NotNull String errorMessage)
      Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
      Parameters:
      expression - a boolean expression representing the state that must be satisfied
      errorMessage - the exception message to use if the check fails; will be converted to a string using String.valueOf(Object)
      Throws:
      IllegalStateException - if expression is false
    • checkState

      public static void checkState(boolean expression)
      Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
      Parameters:
      expression - a boolean expression representing the state that must be satisfied
      Throws:
      IllegalStateException - if expression is false