%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jexl.parser.ASTLTNode |
|
|
1 | /* |
|
2 | * Copyright 2002-2006 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 | ||
17 | package org.apache.commons.jexl.parser; |
|
18 | ||
19 | import org.apache.commons.jexl.JexlContext; |
|
20 | import org.apache.commons.jexl.util.Coercion; |
|
21 | ||
22 | /** |
|
23 | * LT : a < b. |
|
24 | * |
|
25 | * Follows A.3.6.1 of the JSTL 1.0 specification |
|
26 | * |
|
27 | * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a> |
|
28 | * @author <a href="mailto:proyal@apache.org">Peter Royal</a> |
|
29 | * @version $Id: ASTLTNode.java 398203 2006-04-29 16:44:55Z dion $ |
|
30 | */ |
|
31 | public class ASTLTNode extends SimpleNode { |
|
32 | /** |
|
33 | * Create the node given an id. |
|
34 | * |
|
35 | * @param id node id. |
|
36 | */ |
|
37 | public ASTLTNode(int id) { |
|
38 | 0 | super(id); |
39 | 0 | } |
40 | ||
41 | /** |
|
42 | * Create a node with the given parser and id. |
|
43 | * |
|
44 | * @param p a parser. |
|
45 | * @param id node id. |
|
46 | */ |
|
47 | public ASTLTNode(Parser p, int id) { |
|
48 | 12 | super(p, id); |
49 | 12 | } |
50 | ||
51 | /** {@inheritDoc} */ |
|
52 | public Object jjtAccept(ParserVisitor visitor, Object data) { |
|
53 | 0 | return visitor.visit(this, data); |
54 | } |
|
55 | ||
56 | /** {@inheritDoc} */ |
|
57 | public Object value(JexlContext jc) throws Exception { |
|
58 | /* |
|
59 | * now get the values |
|
60 | */ |
|
61 | ||
62 | 39 | Object left = ((SimpleNode) jjtGetChild(0)).value(jc); |
63 | 39 | Object right = ((SimpleNode) jjtGetChild(1)).value(jc); |
64 | ||
65 | 39 | if ((left == right) || (left == null) || (right == class="keyword">null)) { |
66 | 2 | return Boolean.FALSE; |
67 | 37 | } else if (Coercion.isFloatingPoint(left) |
68 | || Coercion.isFloatingPoint(right)) { |
|
69 | 1 | double leftDouble = Coercion.coerceDouble(left).class="keyword">doubleValue(); |
70 | 1 | double rightDouble = Coercion.coerceDouble(right).class="keyword">doubleValue(); |
71 | ||
72 | 1 | return leftDouble < rightDouble ? Boolean.TRUE : Boolean.FALSE; |
73 | 36 | } else if (Coercion.isNumberable(left) || Coercion.isNumberable(right)) { |
74 | 35 | long leftLong = Coercion.coerceLong(left).class="keyword">longValue(); |
75 | 35 | long rightLong = Coercion.coerceLong(right).class="keyword">longValue(); |
76 | ||
77 | 35 | return leftLong < rightLong ? Boolean.TRUE : Boolean.FALSE; |
78 | 1 | } else if (left instanceof String || right instanceof String) { |
79 | 0 | String leftString = left.toString(); |
80 | 0 | String rightString = right.toString(); |
81 | ||
82 | 0 | return leftString.compareTo(rightString) < 0 ? Boolean.TRUE |
83 | : Boolean.FALSE; |
|
84 | 1 | } else if (left instanceof Comparable) { |
85 | 1 | return ((Comparable) left).compareTo(right) < 0 ? Boolean.TRUE |
86 | : Boolean.FALSE; |
|
87 | 0 | } else if (right instanceof Comparable) { |
88 | 0 | return ((Comparable) right).compareTo(left) > 0 ? Boolean.TRUE |
89 | : Boolean.FALSE; |
|
90 | } |
|
91 | ||
92 | 0 | throw new Exception("Invalid comparison : LT "); |
93 | } |
|
94 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |