net.sf.eos.util
Class Conditions

java.lang.Object
  extended by net.sf.eos.util.Conditions

public final class Conditions
extends Object

Provides static methods to simpler condition handling. This implies less code.

Example

     if (reference == null) {
         throw new IllegalArgumentException("reference is null");
     }
     this.value = reference;
 

will change to a simple single line:

     this.value = checkArgumentNotNull(reference, "reference is null");
 

Author:
Sascha Kohlmann

Method Summary
static void checkArgument(boolean expr)
          Checks the expression of an argument and throws an IllegalArgumentException if the expression is false.
static void checkArgument(boolean expr, Object errorMessage)
          Checks the expression of an argument and throws an IllegalArgumentException if the expression is false.
static
<T> T
checkArgumentNotNull(T ref)
          Checks that the given reference is null and throws an IllegalArgumentException if so.
static
<T> T
checkArgumentNotNull(T ref, Object errorMessage)
          Checks that the given reference is null and throws an IllegalArgumentException if so.
static void checkState(boolean expr)
          Checks the expression of an argument and throws an IllegalStateException if the expression is false.
static void checkState(boolean expr, Object errorMessage)
          Checks the expression of an argument and throws an IllegalStateException if the expression is false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

checkArgumentNotNull

public static <T> T checkArgumentNotNull(T ref)
Checks that the given reference is null and throws an IllegalArgumentException if so.

Parameters:
ref - an object reference
Returns:
the non-null reference
Throws:
IllegalArgumentException - if ref is null

checkArgumentNotNull

public static <T> T checkArgumentNotNull(T ref,
                                         Object errorMessage)
Checks that the given reference is null and throws an IllegalArgumentException if so.

Parameters:
ref - an object reference
Returns:
the non-null reference
Throws:
IllegalArgumentException - if ref is null

checkArgument

public static void checkArgument(boolean expr)
Checks the expression of an argument and throws an IllegalArgumentException if the expression is false.

Parameters:
expr - the expression to test
Throws:
IllegalArgumentException - if expr is false

checkArgument

public static void checkArgument(boolean expr,
                                 Object errorMessage)
Checks the expression of an argument and throws an IllegalArgumentException if the expression is false.

Parameters:
expr - the expression to test
Throws:
IllegalArgumentException - if expr is false

checkState

public static void checkState(boolean expr)
Checks the expression of an argument and throws an IllegalStateException if the expression is false.

Parameters:
expr - the expression to test
Throws:
IllegalStateException - if expr is false

checkState

public static void checkState(boolean expr,
                              Object errorMessage)
Checks the expression of an argument and throws an IllegalStateException if the expression is false.

Parameters:
expr - the expression to test
Throws:
IllegalStateException - if expr is false


Copyright © 2008. All Rights Reserved.