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 java.util.Comparator;
019    
020    import org.springframework.rules.constraint.Constraint;
021    import org.springframework.rules.closure.BinaryConstraint;
022    
023    /**
024     * Predicate that tests if one comparable object is less than or equal to
025     * another.
026     *
027     * @author Keith Donald
028     */
029    public class LessThanEqualTo extends ComparisonBinaryPredicate implements BinaryConstraint {
030    
031            public static LessThanEqualTo INSTANCE = new LessThanEqualTo();
032    
033            public static synchronized BinaryConstraint instance() {
034                    return INSTANCE;
035            }
036    
037            public static void load(LessThanEqualTo instance) {
038                    INSTANCE = instance;
039            }
040    
041            public static BinaryConstraint instance(Comparator c) {
042                    return new LessThanEqualTo(c);
043            }
044    
045            public static Constraint value(Comparable value) {
046                    return INSTANCE.bind(instance(), value);
047            }
048    
049            public static Constraint value(Object value, Comparator comparator) {
050                    return INSTANCE.bind(instance(comparator), value);
051            }
052    
053            public LessThanEqualTo() {
054                    super();
055            }
056    
057            public LessThanEqualTo(Comparator comparator) {
058                    super(comparator);
059            }
060    
061            protected boolean testCompareResult(int result) {
062                    return result <= 0;
063            }
064    
065            public String toString() {
066                    return RelationalOperator.LESS_THAN_EQUAL_TO.toString();
067            }
068    
069    }