View Javadoc

1   package ca.uhn.hl7v2.hoh.util;
2   
3   /**
4    * Utility class for parameter validation
5    * 
6    */
7   public abstract class Validate {
8   
9   	/**
10  	 * @throws IllegalArgumentException
11  	 *             If theObject is null
12  	 */
13  	public static void notNull(Object theObject, String theName) {
14  		assert theName != null;
15  
16  		if (theObject == null) {
17  			throw new IllegalArgumentException(theName + " can not be null");
18  		}
19  	}
20  
21  	/**
22  	 * @throws IllegalArgumentException
23  	 *             If theObject is null or contains no non-whitespace characters
24  	 */
25  	public static void notBlank(String theObject, String theName) {
26  		assert theName != null;
27  
28  		if (theObject == null) {
29  			throw new IllegalArgumentException(theName + " can not be null");
30  		}
31  
32  		if (theObject.trim().length() == 0) {
33  			throw new IllegalArgumentException(theName + " can not be empty");
34  		}
35  	}
36  
37  	public static void propertySet(Object theValue, String theName) {
38  		if (theValue == null) {
39  			throw new IllegalStateException("Property \"" + theName + "\" is not set");
40  		}
41  	}
42  
43  }