View Javadoc

1   /*
2    * Copyright 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.osedu.org/licenses/ECL-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.kuali.student.common.object;
17  
18  /**
19   * @author Kuali Student Team 
20   *
21   */
22  public final class KSObjectUtils {
23  
24  	/**
25  	 * 
26  	 */
27  	private KSObjectUtils() {
28  		// intentionally hidden
29  	}
30  	
31  	/**
32  	 * Null-Safe comparison of two Boolean fields.
33  	 * 
34  	 * @param source Boolean to compare against the target.
35  	 * @param target Boolean to compare against the source.
36  	 * @return true if both are null or both are equal; false otherwise.
37  	 */
38  	public static boolean nullSafeBooleanEquals (Boolean source, Boolean target) {
39  		return nullSafeObjectEquals(source, target);
40  	}
41  	
42  	/**
43  	 * Null-Safe comparison of two Integer fields.
44  	 * 
45  	 * @param source Integer to compare against the target.
46  	 * @param target Integer to compare against the source.
47  	 * @return true if both are null or both are equal; false otherwise.
48  	 */
49  	public static boolean nullSafeIntegerEquals (Integer source, Integer target) {
50  		return nullSafeObjectEquals(source, target);
51  	}
52  	
53  	private static boolean nullSafeObjectEquals (Object source, Object target) {
54  		if (source == null && target == null) {
55  			// both are null
56  			return true;
57  		}
58  		else if (source != null && target != null){
59  			return source.equals(target);
60  		}
61  		else {
62  			// one is null
63  			return false;
64  		}
65  	}
66  
67  }