View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.kuali.common.util;
17  
18  import java.io.File;
19  
20  import org.apache.commons.lang3.StringUtils;
21  
22  public abstract class Assert extends org.springframework.util.Assert {
23  
24  	public static void exists(String location) {
25  		exists(location, "[Assertion failed] - [" + location + "] does not exist");
26  	}
27  
28  	public static void exists(String location, String message) {
29  		isTrue(LocationUtils.exists(location), message);
30  	}
31  
32  	public static void isExistingDir(File dir) {
33  		isExistingDir(dir, "[Assertion failed] - [" + dir + "] is not an existing directory");
34  	}
35  
36  	public static void isExistingDir(File dir, String message) {
37  		exists(dir, message);
38  		isTrue(dir.isDirectory(), message);
39  	}
40  
41  	public static void exists(File file) {
42  		exists(file, "[Assertion failed] - [" + file + "] does not exist");
43  	}
44  
45  	public static void exists(File file, String message) {
46  		isTrue(file.exists(), message);
47  	}
48  
49  	public static void isOdd(int i) {
50  		isOdd(i, "[Assertion failed] - [" + i + "] is not an odd number");
51  	}
52  
53  	public static void isOdd(int i, String message) {
54  		isTrue(i % 2 != 0, message);
55  	}
56  
57  	public static void isEven(int i) {
58  		isEven(i, "[Assertion failed] - [" + i + "] is not an even number");
59  	}
60  
61  	public static void isEven(int i, String message) {
62  		isTrue(i % 2 == 0, message);
63  	}
64  
65  	public static void isFalse(boolean condition) {
66  		isTrue(!condition);
67  	}
68  
69  	public static void isFalse(boolean condition, String message) {
70  		isTrue(!condition, message);
71  	}
72  
73  	public static void notBlank(String... strings) {
74  		for (String string : strings) {
75  			isFalse(StringUtils.isBlank(string));
76  		}
77  	}
78  
79  }