org.apache.tapestry5.ioc.internal.util
Class Defense

java.lang.Object
  extended by org.apache.tapestry5.ioc.internal.util.Defense

public final class Defense
extends Object

Static utility methods for defensive programming.


Method Summary
static
<T> T
cast(Object parameterValue, Class<T> type, String parameterName)
          Checks that the provided value is not null, and may be cast to the desired type.
static String notBlank(String value, String parameterName)
          Checks that a parameter value is not null and not empty.
static
<T> T
notNull(T value, String parameterName)
          Checks that a method parameter value is not null, and returns it.
 
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(T value,
                            String parameterName)
Checks that a method parameter value is not null, and returns it.

Type Parameters:
T - the value type
Parameters:
value - the value (which is checked to ensure non-nullness)
parameterName - the name of the parameter, used for exception messages
Returns:
the value
Throws:
IllegalArgumentException - if the value is null

notBlank

public static String notBlank(String value,
                              String parameterName)
Checks that a parameter value is not null and not empty.

Parameters:
value - value to check (which is returned)
parameterName - the name of the parameter, used for exception messages
Returns:
the value, trimmed, if non-blank
Throws:
IllegalArgumentException - if the value is null or empty

cast

public static <T> T cast(Object parameterValue,
                         Class<T> type,
                         String parameterName)
Checks that the provided value is not null, and may be cast to the desired type.

Type Parameters:
T -
Parameters:
parameterValue -
type -
parameterName -
Returns:
the casted value
Throws:
IllegalArgumentException - if the value is null, or is not assignable to the indicated type


Copyright © 2006-2009 Apache Software Foundation. All Rights Reserved.