net.rim.pushsdk.commons
Class Validator

java.lang.Object
  extended by net.rim.pushsdk.commons.Validator

public class Validator
extends Object

Provides a collection of validation methods.

Author:
mdandrea

Constructor Summary
Validator()
           
 
Method Summary
static void assertContains(String part, String str, String errorMessage)
          Verifies that the given string contains the specified substring.
static void assertDate1BeforeDate2(Date date1, Date date2, String errorMessage)
          Verifies that date1 is before date2 in time.
static void assertDateInFuture(Date date, String errorMessage)
          Verifies that the given date is in the future.
static void assertDateInPast(Date date, String errorMessage)
          Verifies that the given date is in the past.
static void assertEndsWith(String suffix, String str, String errorMessage)
          Verifies that the given string ends with the specified suffix.
static void assertEqual(boolean b1, boolean b2, String errorMessage)
          Verifies that two booleans are equal.
static void assertEqual(String str1, String str2, String errorMessage)
          Verifies that the given strings are equal.
static void assertFalse(boolean b, String errorMessage)
          Verifies that the given boolean is set to false.
static void assertFromAndToDatesConsistent(Date fromDate, Date toDate)
          Verifies that the from date and to dates are both not null and that the from date comes before the to date.
static void assertGreaterThan(int value1, int value2, String errorMessage)
          Verifies that the first value is greater than the second value.
static void assertIndexesConsistent(int startIndex, int endIndex)
          Verifies that the start index and end index are both positive numbers (i.e.
static void assertInRange(int value, int lowerLimit, int upperLimit, String errorMessage)
          Verifies that the given value exists between the lower and upper limits.
static void assertLengthEquals(int length, String str, String errorMessage)
          Verifies that the given string has the specified length.
static void assertLengthGreater(int length, String str, String errorMessage)
          Verifies that the given string has a length greater than the specified length.
static void assertLengthGreaterEqual(int length, String str, String errorMessage)
          Verifies that the given string has a length greater than or equal to the specified length.
static void assertLengthLess(int length, String str, String errorMessage)
          Verifies that the given string has a length less than the specified length.
static void assertLengthLessEqual(int length, String str, String errorMessage)
          Verifies that the given string has a length less than or equal to the specified length.
static void assertLessEqual(int value1, int value2, String errorMessage)
          Verifies that the first value is less than or equal to the second value.
static void assertLessThan(int value1, int value2, String errorMessage)
          Verifies that the first value is less than the second value.
static void assertNonNegative(long value, String errorMessage)
          Verifies that the given value is non-negative (i.e.
static void assertNotContains(String part, String str, String errorMessage)
          Verifies that the given string does not contain the specified substring.
static void assertNotEmpty(Collection<?> collection, String errorMessage)
          Verifies that the given collection is not empty.
static void assertNotEmpty(Content content, String errorMessage)
          Verifies that the given content is not empty.
static void assertNotEmpty(List<?> list, String errorMessage)
          Verifies that the given list is not empty.
static void assertNotEmpty(Set<?> set, String errorMessage)
          Verifies that the given set is not empty.
static void assertNotEmpty(String str, String errorMessage)
          Verifies that the given string is not empty.
static void assertNotEqual(boolean b1, boolean b2, String errorMessage)
          Verifies that two booleans are not equal.
static void assertNotEqual(String str1, String str2, String errorMessage)
          Verifies that the given strings are not equal.
static void assertNotNull(Object object, String errorMessage)
          Verifies that the given object is not null.
static void assertNull(Object object, String errorMessage)
          Verifies that the given object is null.
static void assertNullOrEmpty(String str, String errorMessage)
          Verifies that the given string is either null or empty.
static void assertPositive(long value, String errorMessage)
          Verifies that the given value is positive (i.e.
static void assertSizeLessThanEqual(List<?> list, int maximumSize, String errorMessage)
          Verifies that the given list is less than or equal to the specified size (i.e.
static void assertTrue(boolean b, String errorMessage)
          Verifies that the given boolean is set to true.
static void assertValidURL(String str, String errorMessage)
          Verifies that a passed in string is a valid URL.
static void asssertGreaterEqual(int value1, int value2, String errorMessage)
          Verifies that the first value is greater than or equal to the second value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Validator

public Validator()
Method Detail

assertTrue

public static void assertTrue(boolean b,
                              String errorMessage)
Verifies that the given boolean is set to true.

Parameters:
b - the boolean to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertFalse

public static void assertFalse(boolean b,
                               String errorMessage)
Verifies that the given boolean is set to false.

Parameters:
b - the boolean to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNull

public static void assertNull(Object object,
                              String errorMessage)
Verifies that the given object is null.

Parameters:
object - the object to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNullOrEmpty

public static void assertNullOrEmpty(String str,
                                     String errorMessage)
Verifies that the given string is either null or empty.

Parameters:
str - the string to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNotNull

public static void assertNotNull(Object object,
                                 String errorMessage)
Verifies that the given object is not null.

Parameters:
object - the object to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNotEmpty

public static void assertNotEmpty(Content content,
                                  String errorMessage)
Verifies that the given content is not empty.

Parameters:
content - the content to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNotEmpty

public static void assertNotEmpty(String str,
                                  String errorMessage)
Verifies that the given string is not empty.

Parameters:
str - the string to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertLengthEquals

public static void assertLengthEquals(int length,
                                      String str,
                                      String errorMessage)
Verifies that the given string has the specified length.

Parameters:
length - the expected length of the string
str - the string to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertLengthGreater

public static void assertLengthGreater(int length,
                                       String str,
                                       String errorMessage)
Verifies that the given string has a length greater than the specified length.

Parameters:
length - the length to compare against
str - the string to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertLengthGreaterEqual

public static void assertLengthGreaterEqual(int length,
                                            String str,
                                            String errorMessage)
Verifies that the given string has a length greater than or equal to the specified length.

Parameters:
length - the length to compare against
str - the string to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertLengthLess

public static void assertLengthLess(int length,
                                    String str,
                                    String errorMessage)
Verifies that the given string has a length less than the specified length.

Parameters:
length - the length to compare against
str - the string to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertLengthLessEqual

public static void assertLengthLessEqual(int length,
                                         String str,
                                         String errorMessage)
Verifies that the given string has a length less than or equal to the specified length.

Parameters:
length - the length to compare against
str - the string to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertContains

public static void assertContains(String part,
                                  String str,
                                  String errorMessage)
Verifies that the given string contains the specified substring.

Parameters:
part - the substring
str - the string to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNotContains

public static void assertNotContains(String part,
                                     String str,
                                     String errorMessage)
Verifies that the given string does not contain the specified substring.

Parameters:
part - the substring
str - the string to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertEqual

public static void assertEqual(String str1,
                               String str2,
                               String errorMessage)
Verifies that the given strings are equal.

Parameters:
str1 - the first string
str2 - the second string
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNotEqual

public static void assertNotEqual(String str1,
                                  String str2,
                                  String errorMessage)
Verifies that the given strings are not equal.

Parameters:
str1 - the first string
str2 - the second string
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertEndsWith

public static void assertEndsWith(String suffix,
                                  String str,
                                  String errorMessage)
Verifies that the given string ends with the specified suffix.

Parameters:
suffix - the suffix
str - the string to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNotEmpty

public static void assertNotEmpty(List<?> list,
                                  String errorMessage)
Verifies that the given list is not empty.

Parameters:
list - the list to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertSizeLessThanEqual

public static void assertSizeLessThanEqual(List<?> list,
                                           int maximumSize,
                                           String errorMessage)
Verifies that the given list is less than or equal to the specified size (i.e. not greater than the maximum size).

Parameters:
list - the list to validate
maximumSize - the maximum size the list can be (must be a positive number)
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNotEmpty

public static void assertNotEmpty(Set<?> set,
                                  String errorMessage)
Verifies that the given set is not empty.

Parameters:
set - the set to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNotEmpty

public static void assertNotEmpty(Collection<?> collection,
                                  String errorMessage)
Verifies that the given collection is not empty.

Parameters:
collection - the collection to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertDateInPast

public static void assertDateInPast(Date date,
                                    String errorMessage)
Verifies that the given date is in the past.

Parameters:
date - the date to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertDateInFuture

public static void assertDateInFuture(Date date,
                                      String errorMessage)
Verifies that the given date is in the future.

Parameters:
date - the date to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertDate1BeforeDate2

public static void assertDate1BeforeDate2(Date date1,
                                          Date date2,
                                          String errorMessage)
Verifies that date1 is before date2 in time.

Parameters:
date1 - the first date to use in the comparison
date2 - the second date to use in the comparison
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertFromAndToDatesConsistent

public static void assertFromAndToDatesConsistent(Date fromDate,
                                                  Date toDate)
Verifies that the from date and to dates are both not null and that the from date comes before the to date.

Parameters:
fromDate - the from date
toDate - to to date
Throws:
IllegalArgumentException - if the assertion fails

assertIndexesConsistent

public static void assertIndexesConsistent(int startIndex,
                                           int endIndex)
Verifies that the start index and end index are both positive numbers (i.e. > 0) and that the end index is bigger than the start index.

Parameters:
startIndex - the start index
endIndex - the end index
Throws:
IllegalArgumentException - if the assertion fails

assertInRange

public static void assertInRange(int value,
                                 int lowerLimit,
                                 int upperLimit,
                                 String errorMessage)
Verifies that the given value exists between the lower and upper limits.

Parameters:
value - the value to validate
lowerLimit - the lower limit
upperLimit - the upper limit
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNonNegative

public static void assertNonNegative(long value,
                                     String errorMessage)
Verifies that the given value is non-negative (i.e. >= 0).

Parameters:
value - the value to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertPositive

public static void assertPositive(long value,
                                  String errorMessage)
Verifies that the given value is positive (i.e. > 0).

Parameters:
value - the value to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertGreaterThan

public static void assertGreaterThan(int value1,
                                     int value2,
                                     String errorMessage)
Verifies that the first value is greater than the second value.

Parameters:
value1 - the first value
value2 - the second value
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

asssertGreaterEqual

public static void asssertGreaterEqual(int value1,
                                       int value2,
                                       String errorMessage)
Verifies that the first value is greater than or equal to the second value.

Parameters:
value1 - the first value
value2 - the second value
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertLessThan

public static void assertLessThan(int value1,
                                  int value2,
                                  String errorMessage)
Verifies that the first value is less than the second value.

Parameters:
value1 - the first value
value2 - the second value
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertLessEqual

public static void assertLessEqual(int value1,
                                   int value2,
                                   String errorMessage)
Verifies that the first value is less than or equal to the second value.

Parameters:
value1 - the first value
value2 - the second value
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertEqual

public static void assertEqual(boolean b1,
                               boolean b2,
                               String errorMessage)
Verifies that two booleans are equal.

Parameters:
b1 - the first boolean
b2 - the second boolean
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertNotEqual

public static void assertNotEqual(boolean b1,
                                  boolean b2,
                                  String errorMessage)
Verifies that two booleans are not equal.

Parameters:
b1 - the first boolean
b2 - the second boolean
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails

assertValidURL

public static void assertValidURL(String str,
                                  String errorMessage)
Verifies that a passed in string is a valid URL.

Parameters:
str - the string to validate
errorMessage - the error message to be logged with a warning and wrapped in an IllegalArgumentException
Throws:
IllegalArgumentException - if the assertion fails


Copyright © 2011 Research In Motion. All Rights Reserved.