org.apache.oozie.util
Class ParamChecker

java.lang.Object
  extended by org.apache.oozie.util.ParamChecker

public class ParamChecker
extends Object

Utility class to check common parameter preconditions.


Constructor Summary
ParamChecker()
           
 
Method Summary
static Date checkDateOozieTZ(String date, String name)
          Check whether the value is Oozie processing timezone data format.
static int checkGEZero(int value, String name)
          Check whether the value is greater than or equals to 0.
static int checkGTZero(int value, String name)
          Check whether the value is greater than or equals 0.
static int checkInteger(String val, String name)
          Check whether the value is Integer.
static int checkLEZero(int value, String name)
          Check whether the value is less than or equal to 0.
static TimeZone checkTimeZone(String tzStr, String name)
          Check whether the value mention correct Timezone.
static boolean isMember(String item, String[] members, String name)
          Check whether an item is a member of an array of string
static boolean isValidIdentifier(String token)
          Return if the specified token is a valid Java identifier.
static String notEmpty(String str, String name)
          Check that a string is not null and not empty.
static String notEmpty(String str, String name, String info)
          Check that a string is not null and not empty.
static List<String> notEmptyElements(List<String> list, String name)
          Check that a list is not null and that none of its elements is null.
static
<T> T
notNull(T obj, String name)
          Check that a value is not null.
static
<T> List<T>
notNullElements(List<T> list, String name)
          Check that a list is not null and that none of its elements is null.
static String validateActionName(String actionName)
          Check that the given string is a valid action name [a-zA-Z_][0-9a-zA-Z_\-]* and not longer than 50 chars.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParamChecker

public ParamChecker()
Method Detail

notNull

public static <T> T notNull(T obj,
                            String name)
Check that a value is not null. If null throws an IllegalArgumentException.

Parameters:
obj - value.
name - parameter name for the exception message.
Returns:
the given value.

notNullElements

public static <T> List<T> notNullElements(List<T> list,
                                          String name)
Check that a list is not null and that none of its elements is null. If null or if the list has emtpy elements throws an IllegalArgumentException.

Parameters:
list - the list of strings.
name - parameter name for the exception message.
Returns:
the given list.

notEmpty

public static String notEmpty(String str,
                              String name)
Check that a string is not null and not empty. If null or emtpy throws an IllegalArgumentException.

Parameters:
str - value.
name - parameter name for the exception message.
Returns:
the given value.

notEmpty

public static String notEmpty(String str,
                              String name,
                              String info)
Check that a string is not null and not empty. If null or emtpy throws an IllegalArgumentException.

Parameters:
str - value.
name - parameter name for the exception message.
info - additional information to be printed with the exception message
Returns:
the given value.

notEmptyElements

public static List<String> notEmptyElements(List<String> list,
                                            String name)
Check that a list is not null and that none of its elements is null. If null or if the list has emtpy elements throws an IllegalArgumentException.

Parameters:
list - the list of strings.
name - parameter name for the exception message.
Returns:
the given list.

validateActionName

public static String validateActionName(String actionName)
Check that the given string is a valid action name [a-zA-Z_][0-9a-zA-Z_\-]* and not longer than 50 chars.

Parameters:
actionName - string to validate is a token.
Returns:
the given string.

isValidIdentifier

public static boolean isValidIdentifier(String token)
Return if the specified token is a valid Java identifier.

Parameters:
token - string to validate if it is a valid Java identifier.
Returns:
if the specified token is a valid Java identifier.

checkGTZero

public static int checkGTZero(int value,
                              String name)
Check whether the value is greater than or equals 0.

Parameters:
value - : value to test
name - : Name of the parameter
Returns:
If the value is > 0, return the value. Otherwise throw IllegalArgumentException

checkGEZero

public static int checkGEZero(int value,
                              String name)
Check whether the value is greater than or equals to 0.

Parameters:
value - : value to test
name - : Name of the parameter
Returns:
If the value is >= 0, return the value. Otherwise throw IllegalArgumentException

checkLEZero

public static int checkLEZero(int value,
                              String name)
Check whether the value is less than or equal to 0.

Parameters:
value - : value to test
name - : Name of the parameter
Returns:
If the value is <= 0, return the value. Otherwise throw IllegalArgumentException

checkInteger

public static int checkInteger(String val,
                               String name)
Check whether the value is Integer.

Parameters:
value - : value to test
name - : Name of the parameter
Returns:
If the value is integer, return the value. Otherwise throw IllegalArgumentException

checkDateOozieTZ

public static Date checkDateOozieTZ(String date,
                                    String name)
Check whether the value is Oozie processing timezone data format.

Parameters:
value - : value to test
name - : Name of the parameter
Returns:
If the value is in Oozie processing timezone date format, return the value. Otherwise throw IllegalArgumentException

checkTimeZone

public static TimeZone checkTimeZone(String tzStr,
                                     String name)
Check whether the value mention correct Timezone.

Parameters:
value - : value to test
name - : Name of the parameter
Returns:
If the value is correct TZ return the value. Otherwise throw IllegalArgumentException

isMember

public static boolean isMember(String item,
                               String[] members,
                               String name)
Check whether an item is a member of an array of string

Parameters:
item - : item to test
members - : List of items in string
name - : Name of the parameter
Returns:
If the item is in the member return true. Otherwise throw IllegalArgumentException


Copyright © 2013 Apache Software Foundation. All Rights Reserved.