View Javadoc

1   /*
2    * Copyright 2011 Vincent Behar
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.rundeck.api.util;
17  
18  import org.apache.commons.lang.StringUtils;
19  
20  /**
21   * Utility class for assertions
22   * 
23   * @author Vincent Behar
24   */
25  public class AssertUtil {
26  
27      /**
28       * Test if the given {@link Object} is null
29       * 
30       * @param object
31       * @param errorMessage to be used if the object is null
32       * @throws IllegalArgumentException if the given object is null
33       */
34      public static void notNull(Object object, String errorMessage) throws IllegalArgumentException {
35          if (object == null) {
36              throw new IllegalArgumentException(errorMessage);
37          }
38      }
39  
40      /**
41       * Test if the given {@link String} is blank (null, empty or only whitespace)
42       * 
43       * @param input string
44       * @param errorMessage to be used if the string is blank
45       * @throws IllegalArgumentException if the given string is blank
46       */
47      public static void notBlank(String input, String errorMessage) throws IllegalArgumentException {
48          if (StringUtils.isBlank(input)) {
49              throw new IllegalArgumentException(errorMessage);
50          }
51      }
52  
53  }