%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jexl.parser.ASTGENode |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0 |
|
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.apache.commons.jexl.parser; |
|
17 | ||
18 | import org.apache.commons.jexl.JexlContext; |
|
19 | import org.apache.commons.jexl.util.Coercion; |
|
20 | ||
21 | /** |
|
22 | * GE : a >= b |
|
23 | * |
|
24 | * Follows A.3.6.1 of the JSTL 1.0 specification |
|
25 | * |
|
26 | * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a> |
|
27 | * @author <a href="mailto:proyal@apache.org">Peter Royal</a> |
|
28 | * @version $Id: ASTGENode.java,v 1.4 2004/02/28 13:45:20 yoavs Exp $ |
|
29 | */ |
|
30 | public class ASTGENode extends SimpleNode |
|
31 | { |
|
32 | public ASTGENode(int id) |
|
33 | { |
|
34 | 0 | super(id); |
35 | 0 | } |
36 | ||
37 | public ASTGENode(Parser p, int id) |
|
38 | { |
|
39 | 90 | super(p, id); |
40 | 90 | } |
41 | ||
42 | ||
43 | /** Accept the visitor. **/ |
|
44 | public Object jjtAccept(ParserVisitor visitor, Object data) |
|
45 | { |
|
46 | 0 | return visitor.visit(this, data); |
47 | } |
|
48 | ||
49 | public Object value(JexlContext jc) |
|
50 | throws Exception |
|
51 | { |
|
52 | /* |
|
53 | * now get the values |
|
54 | */ |
|
55 | ||
56 | 90 | Object left = ( (SimpleNode) jjtGetChild(0)).value(jc); |
57 | 90 | Object right = ( (SimpleNode) jjtGetChild(1)).value(jc); |
58 | ||
59 | 90 | if( left == right ) |
60 | { |
|
61 | 0 | return Boolean.TRUE; |
62 | } |
|
63 | 90 | else if ( ( left == null ) || ( right == class="keyword">null ) ) |
64 | { |
|
65 | 0 | return Boolean.FALSE; |
66 | } |
|
67 | 90 | else if( Coercion.isFloatingPoint( left ) || Coercion.isFloatingPoint( right ) ) |
68 | { |
|
69 | 0 | double leftDouble = Coercion.coerceDouble( left ).class="keyword">doubleValue(); |
70 | 0 | double rightDouble = Coercion.coerceDouble( right ).class="keyword">doubleValue(); |
71 | ||
72 | 0 | return leftDouble >= rightDouble |
73 | ? Boolean.TRUE |
|
74 | : Boolean.FALSE; |
|
75 | } |
|
76 | 90 | else if( Coercion.isNumberable( left ) || Coercion.isNumberable( right ) ) |
77 | { |
|
78 | 90 | long leftLong = Coercion.coerceLong( left ).class="keyword">longValue(); |
79 | 90 | long rightLong = Coercion.coerceLong( right ).class="keyword">longValue(); |
80 | ||
81 | 96 | return leftLong >= rightLong |
82 | 5 | ? Boolean.TRUE |
83 | 1 | : Boolean.FALSE; |
84 | } |
|
85 | 0 | else if( left instanceof String || right instanceof String ) |
86 | { |
|
87 | 0 | String leftString = left.toString(); |
88 | 0 | String rightString = right.toString(); |
89 | ||
90 | 0 | return leftString.compareTo( rightString ) >= 0 |
91 | ? Boolean.TRUE |
|
92 | : Boolean.FALSE; |
|
93 | } |
|
94 | 0 | else if( left instanceof Comparable ) |
95 | { |
|
96 | 0 | return ( (Comparable)left ).compareTo( right ) >= 0 |
97 | ? Boolean.TRUE |
|
98 | : Boolean.FALSE; |
|
99 | } |
|
100 | 0 | else if( right instanceof Comparable ) |
101 | { |
|
102 | 0 | return ( (Comparable)right ).compareTo( left ) <= 0 |
103 | ? Boolean.TRUE |
|
104 | : Boolean.FALSE; |
|
105 | } |
|
106 | ||
107 | 0 | throw new Exception("Invalid comparison : GE "); |
108 | } |
|
109 | ||
110 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |