01: /*
02: * Copyright 2006-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.gl.util;
17:
18: /**
19: * This class is used to compare objects with one another
20: */
21: public class ObjectHelper {
22: protected ObjectHelper() {
23: }
24:
25: /**
26: * Returns true if object on left side is equal to object on right side
27: *
28: * @param lhs object on left side of equation
29: * @param rhs object on right side of equation
30: * @return true if both lhs and rhs are null or if lhs.equals(rhs)
31: */
32: static public boolean isEqual(Object lhs, Object rhs) {
33: return (null == lhs && null == rhs)
34: || (null != lhs && lhs.equals(rhs));
35: }
36:
37: /**
38: * Return true if object on left side is one of the items in array of objects
39: *
40: * @param lhs object on left side of equation
41: * @param rhs object on right side of equation
42: * @return false if rhs is null. true if isEqual(lhs, rhs[i]) for any ith element of rhs.
43: */
44: static public boolean isOneOf(Object lhs, Object[] rhs) {
45: if (rhs == null)
46: return false;
47:
48: // simple linear search. Arrays.binarySearch isn't appropriate
49: // because the elements of rhs aren't in natural order.
50: for (int i = 0; i < rhs.length; i++) {
51: if (isEqual(lhs, rhs[i])) {
52: return true;
53: }
54: }
55:
56: return false;
57: }
58: }
|