001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.el;
018    
019    import java.math.BigDecimal;
020    import java.math.BigInteger;
021    
022    import javax.servlet.jsp.el.ELException;
023    
024    /**
025     *
026     * <p>This is the superclass for all relational operators (except ==
027     * or !=)
028     * 
029     * @author Nathan Abramson - Art Technology Group
030     * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: bayard $
031     **/
032    
033    public abstract class RelationalOperator
034      extends BinaryOperator
035    {
036    
037      //-------------------------------------
038      /**
039       *
040       * Applies the operator to the given value
041       **/
042      public Object apply (Object pLeft, Object pRight)
043        throws ELException
044      {
045        return Coercions.applyRelationalOperator (pLeft, pRight, this);
046      }
047    
048      //-------------------------------------
049      /**
050       *
051       * Applies the operator to the given double values
052       **/
053      public abstract boolean apply (double pLeft,
054                                     double pRight
055                                     );
056      
057      //-------------------------------------
058      /**
059       *
060       * Applies the operator to the given long values
061       **/
062      public abstract boolean apply (long pLeft,
063                                     long pRight
064                                     );
065      
066      //-------------------------------------
067      /**
068       *
069       * Applies the operator to the given String values
070       **/
071      public abstract boolean apply (String pLeft,
072                                     String pRight
073                                     );
074    
075      //-------------------------------------
076    
077    
078        /**
079         * Applies the operator to the given BigDecimal values, returning a BigDecimal
080         **/
081        public abstract boolean apply(BigDecimal pLeft, BigDecimal pRight);
082    
083        //-------------------------------------
084    
085        /**
086         * Applies the operator to the given BigDecimal values, returning a BigDecimal
087         **/
088        public abstract boolean apply(BigInteger pLeft, BigInteger pRight);
089    
090        //-------------------------------------
091    
092    
093        /**
094         * Test return value of BigInteger/BigDecimal A.compareTo(B).
095         * @param val - result of BigInteger/BigDecimal compareTo() call
096         * @return - true if result is less than 0, otherwise false
097         */
098        protected boolean isLess(int val) {
099            if (val < 0)
100                return true;
101            else
102                return false;
103        }
104    
105        /**
106         * Test return value of BigInteger/BigDecimal A.compareTo(B).
107         * @param val - result of BigInteger/BigDecimal compareTo() call
108         * @return - true if result is equal to 0, otherwise false
109         */
110        protected boolean isEqual(int val) {
111            if (val == 0)
112                return true;
113            else
114                return false;
115        }
116    
117        /**
118         * Test return value of BigInteger/BigDecimal A.compareTo(B).
119         * @param val - result of BigInteger/BigDecimal compareTo() call
120         * @return - true if result is greater than 0, otherwise false
121         */
122        protected boolean isGreater(int val) {
123            if (val > 0)
124                return true;
125            else
126                return false;
127        }
128    }