View Javadoc

1   /*
2    * Copyright 2004-2009 the original author or authors.
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.springmodules.validation.valang.predicates;
18  
19  import java.math.BigDecimal;
20  import java.util.Date;
21  
22  import org.springmodules.validation.valang.functions.Function;
23  
24  /**
25   * Tests if a value is greater than or equal to another.
26   *
27   * @author David Winterfeldt
28   */
29  public class GreaterThanOrEqualTestPredicate extends AbstractCompareTestPredicate {
30  
31      /**
32       * <p>Constructor taking two functions and an operator.
33       *
34       * @param leftFunction the left function
35       * @param operator the operator.
36       */
37      public GreaterThanOrEqualTestPredicate(Function leftFunction, Operator operator, Function rightFunction, int line, int column) {
38          super(leftFunction, operator, rightFunction, line, column, ">=");
39      }
40  
41      /**
42       * Evaluates a <code>BigDecimal</code> and is called by 
43       * <code>evaluate</code>.
44       */
45      @Override
46      protected boolean doEvaluate(BigDecimal leftValue, BigDecimal rightValue) {
47          return (leftValue.compareTo(rightValue) >= 0);
48      }
49  
50      /**
51       * Evaluates a <code>BigDecimal</code> and is called by 
52       * <code>evaluate</code>.
53       */
54      @Override
55      protected boolean doEvaluate(Date leftValue, Date rightValue) {
56          return (leftValue.getTime() >= rightValue.getTime());
57      }
58      
59  }