001    /*
002     * Copyright 2002-2004 the original author or authors.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.rules.constraint;
017    
018    import org.springframework.rules.closure.BinaryConstraint;
019    
020    /**
021     * Type-safe enum class for supported binary operators.
022     *
023     * @author Keith Donald
024     */
025    public abstract class RelationalOperator extends Operator {
026    
027            /**
028             * The <code>EQUAL_TO (==)</code> operator
029             */
030            public static final RelationalOperator EQUAL_TO = new RelationalOperator(
031                            "eq", "=") {
032                    public BinaryConstraint getConstraint() {
033                            return EqualTo.instance();
034                    }
035            };
036    
037            /**
038             * The <code>LESS_THAN (<)</code> operator
039             */
040            public static final RelationalOperator LESS_THAN = new RelationalOperator(
041                            "lt", "<") {
042                    public Operator negation() {
043                            return GREATER_THAN;
044                    }
045    
046                    public BinaryConstraint getConstraint() {
047                            return LessThan.instance();
048                    }
049            };
050    
051            /**
052             * The <code>LESS_THAN_EQUAL_TO (<=)</code> operator
053             */
054            public static final RelationalOperator LESS_THAN_EQUAL_TO = new RelationalOperator(
055                            "lte", "<=") {
056                    public Operator negation() {
057                            return GREATER_THAN_EQUAL_TO;
058                    }
059    
060                    public BinaryConstraint getConstraint() {
061                            return LessThanEqualTo.instance();
062                    }
063            };
064    
065            /**
066             * The <code>GREATER_THAN (>)</code> operator
067             */
068            public static final RelationalOperator GREATER_THAN = new RelationalOperator(
069                            "gt", ">") {
070                    public Operator negation() {
071                            return LESS_THAN;
072                    }
073    
074                    public BinaryConstraint getConstraint() {
075                            return GreaterThan.instance();
076                    }
077            };
078    
079            /**
080             * The <code>GREATER_THAN_EQUAL_TO (>=)</code> operator
081             */
082            public static final RelationalOperator GREATER_THAN_EQUAL_TO = new RelationalOperator(
083                            "gte", ">=") {
084                    public Operator negation() {
085                            return LESS_THAN_EQUAL_TO;
086                    }
087    
088                    public BinaryConstraint getConstraint() {
089                            return GreaterThanEqualTo.instance();
090                    }
091            };
092    
093            private RelationalOperator(String code, String symbol) {
094                    super(code, symbol);
095            }
096    
097            /**
098             * Returns the predicate instance associated with this binary operator.
099             *
100             * @return the associated binary predicate
101             */
102            public abstract BinaryConstraint getConstraint();
103    
104    }