1 /* 2 * Copyright 2006 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.ole.gl; 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) || (null != lhs && lhs.equals(rhs)); 34 } 35 36 /** 37 * Return true if object on left side is one of the items in array of objects 38 * 39 * @param lhs object on left side of equation 40 * @param rhs object on right side of equation 41 * @return false if rhs is null. true if isEqual(lhs, rhs[i]) for any ith element of rhs. 42 */ 43 static public boolean isOneOf(Object lhs, Object[] rhs) { 44 if (rhs == null) 45 return false; 46 47 // simple linear search. Arrays.binarySearch isn't appropriate 48 // because the elements of rhs aren't in natural order. 49 for (int i = 0; i < rhs.length; i++) { 50 if (isEqual(lhs, rhs[i])) { 51 return true; 52 } 53 } 54 55 return false; 56 } 57 }