Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.el.lang;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.math.BigDecimal;
import java.math.BigInteger;
import javax.el.ELException;
import org.apache.el.util.MessageFactory;
/**
* A helper class that implements the EL Specification
*
* @author Jacob Hookom [[email protected]]
* @version $Id: ELSupport.java 1050680 2010-12-18 17:26:52Z markt $
*/
public class ELSupport {
private static final Long ZERO = Long.valueOf(0L);
/**
* Compare two objects, after coercing to the same type if appropriate.
*
* If the objects are identical, or they are equal according to
* {@link #equals(Object, Object)} then return 0.
*
* If either object is a BigDecimal, then coerce both to BigDecimal first.
* Similarly for Double(Float), BigInteger, and Long(Integer, Char, Short, Byte).
*
* Otherwise, check that the first object is an instance of Comparable, and compare
* against the second object. If that is null, return 1, otherwise
* return the result of comparing against the second object.
*
* Similarly, if the second object is Comparable, if the first is null, return -1,
* else return the result of comparing against the first object.
*
* A null object is considered as:
*
*
ZERO when compared with Numbers
*
the empty string for String compares
*
Otherwise null is considered to be lower than anything else.
*
*
* @param obj0 first object
* @param obj1 second object
* @return -1, 0, or 1 if this object is less than, equal to, or greater than val.
* @throws ELException if neither object is Comparable
* @throws ClassCastException if the objects are not mutually comparable
*/
public static final int compare(final Object obj0, final Object obj1)
throws ELException {
if (obj0 == obj1 || equals(obj0, obj1)) {
return 0;
}
if (isBigDecimalOp(obj0, obj1)) {
BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class);
BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class);
return bd0.compareTo(bd1);
}
if (isDoubleOp(obj0, obj1)) {
Double d0 = (Double) coerceToNumber(obj0, Double.class);
Double d1 = (Double) coerceToNumber(obj1, Double.class);
return d0.compareTo(d1);
}
if (isBigIntegerOp(obj0, obj1)) {
BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class);
BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class);
return bi0.compareTo(bi1);
}
if (isLongOp(obj0, obj1)) {
Long l0 = (Long) coerceToNumber(obj0, Long.class);
Long l1 = (Long) coerceToNumber(obj1, Long.class);
return l0.compareTo(l1);
}
if (obj0 instanceof String || obj1 instanceof String) {
return coerceToString(obj0).compareTo(coerceToString(obj1));
}
if (obj0 instanceof Comparable>) {
@SuppressWarnings("unchecked") // checked above
final Comparable