001 /*
002 * Copyright 2002-2004 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of 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,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under 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 another.
025 *
026 * @author Keith Donald
027 */
028 public class LessThan extends ComparisonBinaryPredicate implements BinaryConstraint {
029
030 public static LessThan INSTANCE = new LessThan();
031
032 public static synchronized BinaryConstraint instance() {
033 return INSTANCE;
034 }
035
036 public static void load(LessThan instance) {
037 INSTANCE = instance;
038 }
039
040 public static BinaryConstraint instance(Comparator c) {
041 return new LessThan(c);
042 }
043
044 public static Constraint value(Comparable value) {
045 return INSTANCE.bind(instance(), value);
046 }
047
048 public static Constraint value(Object value, Comparator comparator) {
049 return INSTANCE.bind(instance(comparator), value);
050 }
051
052 public LessThan() {
053 super();
054 }
055
056 public LessThan(Comparator comparator) {
057 super(comparator);
058 }
059
060 protected boolean testCompareResult(int result) {
061 return result < 0;
062 }
063
064 public String toString() {
065 return RelationalOperator.LESS_THAN.toString();
066 }
067
068 }