com.sas.iquery.util
Class Preconditions

com.sas.iquery.util.Preconditions

public final class Preconditions

Preconditions - a static class to assist with input parameter validation.

Output messages are tuned specifically for input parameters to methods or constructors.

Originally part of com.sas.iquery.metadata.impl.Utils.

Since:
9.4

Constructor Summary
Preconditions()
           
 
Method Summary
static void checkExpression(boolean expression)
          Throw an IQueryServicesIllegalArgumentException if the expression if false.
static void checkExpression(boolean expression, java.lang.String parameterName)
          Throw an IQueryServicesIllegalArgumentException with a descriptive message containing the input parameter name if the expression if false.
static
<T> T
ensureNonNull(T reference)
          Checks to see if object is null and if so, throw an IQueryServicesIllegalArgumentException with a descriptive message.
static
<T> T
ensureNonNull(T reference, org.apache.log4j.Logger logger)
           
static
<T> T
ensureNonNull(T reference, java.lang.String parameterName)
          checks to see if object is null and if so, throw an IQueryServicesIllegalArgumentException with a descriptive message containing the parameter name.
static
<T> T
ensureNonNull(T reference, java.lang.String parameterName, org.apache.log4j.Logger logger)
           
static
<T> void
ensureNonNullElements(java.util.List<? extends T> values)
          checks to see if the input list contains a null element and if so, throw an IQueryServicesIllegalArgumentException exception with a descriptive message.
static
<T> void
ensureNonNullElements(java.util.List<? extends T> values, java.lang.String listName)
          Checks to see if the input list contains a null element and if so, throw an IQueryServicesIllegalArgumentException exception with a descriptive message.
static
<T> void
ensureNonNullElements(java.util.List<? extends T> values, java.lang.String listName, org.apache.log4j.Logger logger)
          Checks to see if the input list contains a null element and if so, throw an IQueryServicesIllegalArgumentException exception with a descriptive message.
static
<T> void
ensureNonNullTypedElements(java.util.List<? extends T> values, java.lang.Class<T> type)
          Checks to see if the input list contains a null element, or an element of an invalid type and throw an IQueryServicesIllegalArgumentException.
static
<T> void
ensureNonNullTypedElements(java.util.List<? extends T> values, java.lang.Class<T> type, org.apache.log4j.Logger logger)
          Checks to see if the input list contains a null element, or an element of an invalid type and throw an IQueryServicesIllegalArgumentException.
static
<T> void
ensureNonNullTypedElements(java.util.List<? extends T> values, java.lang.Class<T> type, java.lang.String listName)
          Checks to see if the input list contains a null element, or an element of an invalid type and throw an IQueryServicesIllegalArgumentException.
static
<T> void
ensureNonNullTypedElements(java.util.List<? extends T> values, java.lang.Class<T> type, java.lang.String listName, org.apache.log4j.Logger logger)
          Checks to see if the input list contains a null element, or an element of an invalid type and throw an IQueryServicesIllegalArgumentException.
static
<T> T
ensureNonNullWithMessage(T reference, java.lang.String key, java.lang.Object... args)
           
 

Constructor Detail

Preconditions

public Preconditions()
Method Detail

ensureNonNull

public static <T> T ensureNonNull(T reference)
Checks to see if object is null and if so, throw an IQueryServicesIllegalArgumentException with a descriptive message.

IQ has historically thrown IQueryServicesIllegalArgumentException instead of NullPointerException, when client applications have passed in a null pointer.

Throws:
IQueryServicesIllegalArgumentException - if reference is null

ensureNonNull

public static <T> T ensureNonNull(T reference,
                                  org.apache.log4j.Logger logger)

ensureNonNull

public static <T> T ensureNonNull(T reference,
                                  java.lang.String parameterName)
checks to see if object is null and if so, throw an IQueryServicesIllegalArgumentException with a descriptive message containing the parameter name.

IQ has historically thrown IQueryServicesIllegalArgumentException instead of NullPointerException, when client applications have passed in a null pointer.

Throws:
IQueryServicesIllegalArgumentException - if reference is null

ensureNonNullWithMessage

public static <T> T ensureNonNullWithMessage(T reference,
                                             java.lang.String key,
                                             java.lang.Object... args)

ensureNonNull

public static <T> T ensureNonNull(T reference,
                                  java.lang.String parameterName,
                                  org.apache.log4j.Logger logger)

ensureNonNullElements

public static <T> void ensureNonNullElements(@NonNull
                                             java.util.List<? extends T> values)
checks to see if the input list contains a null element and if so, throw an IQueryServicesIllegalArgumentException exception with a descriptive message.

Parameters:
values - the input list

ensureNonNullElements

public static <T> void ensureNonNullElements(@NonNull
                                             java.util.List<? extends T> values,
                                             java.lang.String listName)
Checks to see if the input list contains a null element and if so, throw an IQueryServicesIllegalArgumentException exception with a descriptive message.

This signature allows the caller to provide a name for the input list.

Parameters:
values - the input list
listName - the name of the input list

ensureNonNullElements

public static <T> void ensureNonNullElements(@NonNull
                                             java.util.List<? extends T> values,
                                             java.lang.String listName,
                                             @NonNull
                                             org.apache.log4j.Logger logger)
Checks to see if the input list contains a null element and if so, throw an IQueryServicesIllegalArgumentException exception with a descriptive message.

This signature allows the caller to provide a name for the input list.

This signature also writes an error to the log.

Parameters:
values - the input list
listName - the name of the input list

ensureNonNullTypedElements

public static <T> void ensureNonNullTypedElements(@NonNull
                                                  java.util.List<? extends T> values,
                                                  @NonNull
                                                  java.lang.Class<T> type)
Checks to see if the input list contains a null element, or an element of an invalid type and throw an IQueryServicesIllegalArgumentException.

Use this method when callers are not likely to be using generics (i.e. legacy callers) and you need your own run time type checking.

Parameters:
values - the input list
type - the expected type of each list element

ensureNonNullTypedElements

public static <T> void ensureNonNullTypedElements(@NonNull
                                                  java.util.List<? extends T> values,
                                                  @NonNull
                                                  java.lang.Class<T> type,
                                                  @NonNull
                                                  org.apache.log4j.Logger logger)
Checks to see if the input list contains a null element, or an element of an invalid type and throw an IQueryServicesIllegalArgumentException.

Use this method when callers are not likely to be using generics (i.e. legacy callers) and you need your own run time type checking.

This signature also writes an error to the log.

Parameters:
values - the input list
type - the expected type of each list element

ensureNonNullTypedElements

public static <T> void ensureNonNullTypedElements(@NonNull
                                                  java.util.List<? extends T> values,
                                                  @NonNull
                                                  java.lang.Class<T> type,
                                                  @NonNull
                                                  java.lang.String listName)
Checks to see if the input list contains a null element, or an element of an invalid type and throw an IQueryServicesIllegalArgumentException.

Use this method when callers are not likely to be using generics (i.e. legacy callers) and you need your own run time type checking.

Parameters:
values - the input list
type - the expected type of each list element
listName - the name of the input list

ensureNonNullTypedElements

public static <T> void ensureNonNullTypedElements(@NonNull
                                                  java.util.List<? extends T> values,
                                                  @NonNull
                                                  java.lang.Class<T> type,
                                                  @NonNull
                                                  java.lang.String listName,
                                                  @NonNull
                                                  org.apache.log4j.Logger logger)
Checks to see if the input list contains a null element, or an element of an invalid type and throw an IQueryServicesIllegalArgumentException.

Use this method when callers are not likely to be using generics (i.e. legacy callers) and you need your own run time type checking.

This signature also writes an error to the log.

Parameters:
values - the input list
type - the expected type of each list element
listName - the name of the input list
logger - log an error message to this logger

checkExpression

public static void checkExpression(boolean expression)
Throw an IQueryServicesIllegalArgumentException if the expression if false.


checkExpression

public static void checkExpression(boolean expression,
                                   java.lang.String parameterName)
Throw an IQueryServicesIllegalArgumentException with a descriptive message containing the input parameter name if the expression if false.




Copyright © 2009 SAS Institute Inc. All Rights Reserved.