@PublicApi public final class

Assertions

extends Object
java.lang.Object
   ↳ com.atlassian.jira.util.dbc.Assertions

@PublicApi

This class is designed for plugins to consume (call its methods).

Clients of @PublicApi can expect that programs compiled against a given version will remain binary compatible with later versions of the @PublicApi as per each product's API policy as long as the client does not implement/extend @PublicApi interfaces or classes (refer to each product's API policy for the exact guarantee---usually binary compatibility is guaranteed at least across minor versions).

Note: since @PublicApi interfaces and classes are not designed to be implemented or extended by clients, we may perform certain types of binary-incompatible changes to these classes and interfaces, but these will not affect well-behaved clients that do not extend/implement these types (in general, only classes and interfaces annotated with @PublicSpi are safe to extend/implement).

Class Overview

Utility class with design by contract checks. Should be preferred to com.atlassian.jira.util.dbcNull.

Summary

Public Methods
static <C extends Iterable<String>> C containsNoBlanks(String name, C stringsNotBlank)
Throw and IllegalArgumentException if the passed collection is null or contains any blank Strings.
static <C extends Iterable<?>> C containsNoNulls(String name, C containsNoNulls)
Throw an IllegalArgumentException if the passed collection is null or contains any null values.
static <C> C[] containsNoNulls(String name, C[] containsNoNulls)
Throw an IllegalArgumentException if the passed array is null or contains any null values.
static <T> T equals(String name, T expected, T got)
static void is(String name, boolean condition)
Throw an IllegalArgumentException if the condition is false
static long nonNegative(String name, long nonNegative)
static void not(String name, boolean condition)
Throw an IllegalArgumentException if the condition is true
static String notBlank(String name, String string)
Throw an IllegalArgumentException if the string is null or blank (only contains whitespace)
static <T extends Collection> T notEmpty(String name, T notEmpty)
Throw an IllegalArgumentException if the argument is null or empty
static <T> T notNull(String name, T notNull)
Throw an IllegalArgumentException if the string is null
static <T> T notNull(T notNull)
static void stateFalse(String name, boolean condition)
State check.
static <T> T stateNotNull(String name, T notNull)
State check.
static void stateTrue(String name, boolean condition)
State check.
static String stripNotBlank(String name, String string)
Either returns a string with all space trimmed or throws an IllegalArgumentException if the string is null or blank (only contains whitespace).
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static C containsNoBlanks (String name, C stringsNotBlank)

Throw and IllegalArgumentException if the passed collection is null or contains any blank Strings.

Parameters
name name added to the exception
stringsNotBlank the collection of strings that should not be blank.
Returns
  • the passed argument.
Throws
IllegalArgumentException if the passed collection is null or contains any blank strings.

public static C containsNoNulls (String name, C containsNoNulls)

Throw an IllegalArgumentException if the passed collection is null or contains any null values.

Parameters
name name added to the exception.
containsNoNulls the collection to check.
Returns
  • the passed in Iterable.
Throws
IllegalArgumentException if the passed collection is null or contains any null.

public static C[] containsNoNulls (String name, C[] containsNoNulls)

Throw an IllegalArgumentException if the passed array is null or contains any null values.

Parameters
name name added to the exception.
containsNoNulls the collection to check.
Returns
  • the passed in Iterable.
Throws
IllegalArgumentException if the passed collection is null or contains any null.

public static T equals (String name, T expected, T got)

public static void is (String name, boolean condition)

Throw an IllegalArgumentException if the condition is false

Parameters
name added to the exception
condition should be false
Throws
IllegalArgumentException if true

public static long nonNegative (String name, long nonNegative)

public static void not (String name, boolean condition)

Throw an IllegalArgumentException if the condition is true

Parameters
name added to the exception
condition should be false
Throws
IllegalArgumentException if true

public static String notBlank (String name, String string)

Throw an IllegalArgumentException if the string is null or blank (only contains whitespace)

Parameters
name added to the exception
string should not be null or blank
Returns
  • argument being checked.
Throws
IllegalArgumentException if null or blank

public static T notEmpty (String name, T notEmpty)

Throw an IllegalArgumentException if the argument is null or empty

Parameters
name added to the exception
notEmpty should not be null or empty
Returns
  • argument being checked.
Throws
IllegalArgumentException if null or empty

public static T notNull (String name, T notNull)

Throw an IllegalArgumentException if the string is null

Parameters
name added to the exception
notNull should not be null
Returns
  • argument being checked.
Throws
IllegalArgumentException if null

public static T notNull (T notNull)

public static void stateFalse (String name, boolean condition)

State check. Throw an IllegalStateException if the condition is true

Parameters
name added to the exception
condition should be true
Throws
IllegalStateException if false

public static T stateNotNull (String name, T notNull)

State check. Throw an IllegalStateException if the supplied argument is null.

Parameters
name added to the exception
notNull should not be null
Returns
  • argument being checked.
Throws
IllegalStateException if false

public static void stateTrue (String name, boolean condition)

State check. Throw an IllegalStateException if the condition is false

Parameters
name added to the exception
condition should be true
Throws
IllegalStateException if false

public static String stripNotBlank (String name, String string)

Either returns a string with all space trimmed or throws an IllegalArgumentException if the string is null or blank (only contains whitespace).

Parameters
name added to the exception
string should not be null or blank
Returns
  • the trimmed argument.
Throws
IllegalArgumentException if null or blank