You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by hc...@apache.org on 2005/01/29 12:57:19 UTC
cvs commit: jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/util EqualsUtils.java
hchar 2005/01/29 03:57:19
Added: sandbox/yajcache/src/org/apache/jcs/yajcache/util
EqualsUtils.java
Log:
equals utils
Revision Changes Path
1.1 jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/util/EqualsUtils.java
Index: EqualsUtils.java
===================================================================
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jcs.yajcache.util;
import java.util.Arrays;
/**
* @author Hanson Char
*/
public enum EqualsUtils {
inst;
/**
* Returns true if the two input arguments are equal, handling cases
* when they are arrays.
* Returns false otherwise.
*/
public boolean equals(Object lhs, Object rhs) {
if (lhs == rhs)
return true;
if (lhs == null || rhs == null)
return false;
Class lClass = lhs.getClass();
Class rClass = rhs.getClass();
if (lClass.isArray()
&& rClass.isArray())
{
Class lCompType = lClass.getComponentType();
Class rCompType = rClass.getComponentType();
if (lCompType.isPrimitive()) {
if (rCompType.isPrimitive()) {
if (lCompType != rCompType)
return false;
if (lCompType == int.class)
return Arrays.equals((int[])lhs, (int[])rhs);
if (lCompType == boolean.class)
return Arrays.equals((boolean[])lhs, (boolean[])rhs);
if (lCompType == byte.class)
return Arrays.equals((byte[])lhs, (byte[])rhs);
if (lCompType == char.class)
return Arrays.equals((char[])lhs, (char[])rhs);
if (lCompType == double.class)
return Arrays.equals((double[])lhs, (double[])rhs);
if (lCompType == float.class)
return Arrays.equals((float[])lhs, (float[])rhs);
if (lCompType == long.class)
return Arrays.equals((long[])lhs, (long[])rhs);
if (lCompType == short.class)
return Arrays.equals((short[])lhs, (short[])rhs);
}
return false;
}
else {
if (rCompType.isPrimitive())
return false;
return Arrays.equals((Object[])lhs, (Object[])rhs);
}
}
return lhs.equals(rhs);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org