KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > exp > parser > ASTLessOrEqual


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.exp.parser;
21
22 import org.apache.cayenne.exp.Expression;
23 import org.apache.cayenne.util.ConversionUtil;
24
25 /**
26  * "Less than or equal to" expression.
27  *
28  * @since 1.1
29  * @author Andrus Adamchik
30  */

31 public class ASTLessOrEqual extends ConditionNode {
32
33     /**
34      * Constructor used by expression parser. Do not invoke directly.
35      */

36     ASTLessOrEqual(int id) {
37         super(id);
38     }
39
40     public ASTLessOrEqual() {
41         super(ExpressionParserTreeConstants.JJTLESSOREQUAL);
42     }
43
44     public ASTLessOrEqual(ASTPath path, Object JavaDoc value) {
45         super(ExpressionParserTreeConstants.JJTLESSOREQUAL);
46         jjtAddChild(path, 0);
47         jjtAddChild(new ASTScalar(value), 1);
48     }
49
50     protected Object JavaDoc evaluateNode(Object JavaDoc o) throws Exception JavaDoc {
51         int len = jjtGetNumChildren();
52         if (len != 2) {
53             return Boolean.FALSE;
54         }
55
56         Comparable JavaDoc c1 = ConversionUtil.toComparable(evaluateChild(0, o));
57         if (c1 == null) {
58             return Boolean.FALSE;
59         }
60
61         Comparable JavaDoc c2 = ConversionUtil.toComparable(evaluateChild(1, o));
62         if (c2 == null) {
63             return Boolean.FALSE;
64         }
65
66         return c1.compareTo(c2) <= 0 ? Boolean.TRUE : Boolean.FALSE;
67     }
68
69     /**
70      * Creates a copy of this expression node, without copying children.
71      */

72     public Expression shallowCopy() {
73         return new ASTLessOrEqual(id);
74     }
75
76     protected String JavaDoc getExpressionOperator(int index) {
77         return "<=";
78     }
79
80     public int getType() {
81         return Expression.LESS_THAN_EQUAL_TO;
82     }
83 }
84
Popular Tags