com.atlassian.jira.util.dbc
Class Assertions

java.lang.Object
  extended by com.atlassian.jira.util.dbc.Assertions

@PublicApi
public final class Assertions
extends Object

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

Since:
v3.13

Method Summary
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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

notNull

public static <T> T notNull(String name,
                            T notNull)
                 throws IllegalArgumentException
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

notNull

public static <T> T notNull(T notNull)
                 throws IllegalArgumentException
Throws:
IllegalArgumentException

notEmpty

public static <T extends Collection> T notEmpty(String name,
                                                T notEmpty)
                                     throws IllegalArgumentException
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
Since:
v4.1

containsNoNulls

public static <C extends Iterable<?>> C containsNoNulls(String name,
                                                        C containsNoNulls)
                                             throws IllegalArgumentException
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.

containsNoNulls

public static <C> C[] containsNoNulls(String name,
                                      C[] containsNoNulls)
                           throws IllegalArgumentException
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.

notBlank

public static String notBlank(String name,
                              String string)
                       throws IllegalArgumentException
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

containsNoBlanks

public 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.

Type Parameters:
C - the type of the collection of 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.

not

public static void not(String name,
                       boolean condition)
                throws IllegalArgumentException
Throw an IllegalArgumentException if the condition is true

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

is

public static void is(String name,
                      boolean condition)
               throws IllegalArgumentException
Throw an IllegalArgumentException if the condition is false

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

stateTrue

public static void stateTrue(String name,
                             boolean condition)
                      throws IllegalStateException
State check. Throw an IllegalStateException if the condition is false

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

stateFalse

public static void stateFalse(String name,
                              boolean condition)
                       throws IllegalStateException
State check. Throw an IllegalStateException if the condition is true

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

stateNotNull

public static <T> 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

equals

public static <T> T equals(String name,
                           T expected,
                           T got)
                throws IllegalArgumentException
Throws:
IllegalArgumentException


Copyright © 2002-2014 Atlassian. All Rights Reserved.