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>The implementation of the greater than operator
027 *
028 * @author Nathan Abramson - Art Technology Group
029 * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: bayard $
030 **/
031
032 public class GreaterThanOperator
033 extends RelationalOperator
034 {
035 //-------------------------------------
036 // Singleton
037 //-------------------------------------
038
039 public static final GreaterThanOperator SINGLETON =
040 new GreaterThanOperator ();
041
042 //-------------------------------------
043 /**
044 *
045 * Constructor
046 **/
047 public GreaterThanOperator ()
048 {
049 }
050
051 //-------------------------------------
052 // Expression methods
053 //-------------------------------------
054 /**
055 *
056 * Returns the symbol representing the operator
057 **/
058 public String getOperatorSymbol ()
059 {
060 return ">";
061 }
062
063 //-------------------------------------
064 /**
065 *
066 * Applies the operator to the given value
067 **/
068 public Object apply (Object pLeft, Object pRight)
069 throws ELException
070 {
071 if (pLeft == pRight) {
072 return Boolean.FALSE;
073 }
074 else if (pLeft == null ||
075 pRight == null) {
076 return Boolean.FALSE;
077 }
078 else {
079 return super.apply (pLeft, pRight);
080 }
081 }
082
083 //-------------------------------------
084 /**
085 *
086 * Applies the operator to the given double values
087 **/
088 public boolean apply (double pLeft, double pRight) {
089 return pLeft > pRight;
090 }
091
092 //-------------------------------------
093 /**
094 *
095 * Applies the operator to the given long values
096 **/
097 public boolean apply (long pLeft, long pRight) {
098 return pLeft > pRight;
099 }
100
101 //-------------------------------------
102 /**
103 *
104 * Applies the operator to the given String values
105 **/
106 public boolean apply (String pLeft, String pRight) {
107 return pLeft.compareTo (pRight) > 0;
108 }
109
110 //-------------------------------------
111
112 /**
113 *
114 * Applies the operator to the given BigDecimal values, returning a BigDecimal
115 **/
116 public boolean apply(BigDecimal pLeft, BigDecimal pRight) {
117 return isGreater(pLeft.compareTo(pRight));
118 }
119
120 //-------------------------------------
121
122 /**
123 *
124 * Applies the operator to the given BigDecimal values, returning a BigDecimal
125 **/
126 public boolean apply(BigInteger pLeft, BigInteger pRight) {
127 return isGreater(pLeft.compareTo(pRight));
128 }
129
130 //-------------------------------------
131 }