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 greater than another. 025 * 026 * @author Keith Donald 027 */ 028 public class GreaterThan extends ComparisonBinaryPredicate implements BinaryConstraint { 029 030 public static GreaterThan INSTANCE = new GreaterThan(); 031 032 public static synchronized BinaryConstraint instance() { 033 return INSTANCE; 034 } 035 036 public static void load(GreaterThan instance) { 037 INSTANCE = instance; 038 } 039 040 public static BinaryConstraint instance(Comparator c) { 041 return new GreaterThan(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 GreaterThan() { 053 super(); 054 } 055 056 public GreaterThan(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.GREATER_THAN.toString(); 066 } 067 068 }