com.elibom.client
Class Preconditions

java.lang.Object
  extended by com.elibom.client.Preconditions

public class Preconditions
extends Object

This class provides helper methods to check preconditions throwing an exception when not met.

Author:
German Escobar

Constructor Summary
Preconditions()
           
 
Method Summary
static void isUrl(String value, String message)
          Checks that a string is a valid URL.
static void maxLength(String value, int maxLength, String message)
          Checks that the length of a string is not greater than maxLength.
static void notEmpty(String value, String message)
          Checks that a string is not null or empty.
static void notNull(Object object, String message)
          Checks that an object is not null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Preconditions

public Preconditions()
Method Detail

notNull

public static void notNull(Object object,
                           String message)
                    throws IllegalArgumentException
Checks that an object is not null.

Parameters:
object - the object to be tested
message - the message for the exception in case the object is null.
Throws:
IllegalArgumentException - if the object is null.

notEmpty

public static void notEmpty(String value,
                            String message)
                     throws IllegalArgumentException
Checks that a string is not null or empty.

Parameters:
value - the string to be tested.
message - the message for the exception in case the string is empty.
Throws:
IllegalArgumentException - if the string is empty.

maxLength

public static void maxLength(String value,
                             int maxLength,
                             String message)
                      throws IllegalArgumentException
Checks that the length of a string is not greater than maxLength.

Parameters:
value - the string to be tested
maxLength - the max lenght of the string.
message - the message for the exception in case the length of the string is greater than maxLength.
Throws:
IllegalArgumentException - if the length of the string is greater that maxLength.

isUrl

public static void isUrl(String value,
                         String message)
                  throws IllegalArgumentException
Checks that a string is a valid URL.

Parameters:
value - the string to be tested.
message - the message for the exception in case the string is not a valid URL.
Throws:
IllegalArgumentException - if the string is not a valid URL.


Copyright © 2013. All Rights Reserved.