Revision: 1596 http://svn.sourceforge.net/spring-rich-c/?rev=1596&view=rev Author: mathiasbr Date: 2006-12-12 07:37:56 -0800 (Tue, 12 Dec 2006)
Log Message: ----------- methods added for property constraint to allow using a comparator Modified Paths: -------------- trunk/spring-richclient/support/src/main/java/org/springframework/rules/constraint/ConstraintsAccessor.java trunk/spring-richclient/support/src/main/java/org/springframework/rules/factory/Constraints.java Modified: trunk/spring-richclient/support/src/main/java/org/springframework/rules/constraint/ConstraintsAccessor.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/rules/constraint/ConstraintsAccessor.java 2006-12-12 09:42:38 UTC (rev 1595) +++ trunk/spring-richclient/support/src/main/java/org/springframework/rules/constraint/ConstraintsAccessor.java 2006-12-12 15:37:56 UTC (rev 1596) @@ -305,6 +305,13 @@ return getConstraints().eq(propertyName, propertyValue); } + /** + * @since 0.3.0 + */ + public PropertyConstraint eq(String propertyName, Object propertyValue, Comparator comparator) { + return getConstraints().eq(propertyName, propertyValue, comparator); + } + public PropertyConstraint gt(String propertyName, Comparable propertyValue) { return getConstraints().gt(propertyName, propertyValue); } @@ -321,6 +328,55 @@ return getConstraints().lte(propertyName, propertyValue); } + /** + * @since 0.3.0 + */ + public PropertyConstraint eqProperty(String propertyName, String otherPropertyName, Comparator comparator) { + return getConstraints().eqProperty(propertyName, otherPropertyName, comparator); + } + + /** + * @since 0.3.0 + */ + public PropertyConstraint gtProperty(String propertyName, String otherPropertyName, Comparator comparator) { + return getConstraints().gtProperty(propertyName, otherPropertyName, comparator); + } + + /** + * @since 0.3.0 + */ + public PropertyConstraint gteProperty(String propertyName, String otherPropertyName, Comparator comparator) { + return getConstraints().gteProperty(propertyName, otherPropertyName, comparator); + } + + /** + * @since 0.3.0 + */ + public PropertyConstraint ltProperty(String propertyName, String otherPropertyName, Comparator comparator) { + return getConstraints().ltProperty(propertyName, otherPropertyName, comparator); + } + + /** + * @since 0.3.0 + */ + public PropertyConstraint lteProperty(String propertyName, String otherPropertyName, Comparator comparator) { + return getConstraints().lteProperty(propertyName, otherPropertyName, comparator); + } + + /** + * @since 0.3.0 + */ + public PropertyConstraint inRange(String propertyName, Comparable min, Comparable max, Comparator comparator) { + return getConstraints().inRange(propertyName, min, max, comparator); + } + + /** + * @since 0.3.0 + */ + public PropertyConstraint inRangeProperties(String propertyName, String minPropertyName, String maxPropertyName, Comparator comparator) { + return getConstraints().inRangeProperties(propertyName, minPropertyName, maxPropertyName, comparator); + } + public PropertyConstraint eqProperty(String propertyName, String otherPropertyName) { return getConstraints().eqProperty(propertyName, otherPropertyName); } Modified: trunk/spring-richclient/support/src/main/java/org/springframework/rules/factory/Constraints.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/rules/factory/Constraints.java 2006-12-12 09:42:38 UTC (rev 1595) +++ trunk/spring-richclient/support/src/main/java/org/springframework/rules/factory/Constraints.java 2006-12-12 15:37:56 UTC (rev 1596) @@ -592,6 +592,20 @@ } /** + * Apply a "equal to" constraint to a bean property. + * + * @param propertyName The first property + * @param propertyValue The constraint value + * @param comparator the comparator to use while comparing the values + * @return The constraint + * + * @since 0.3.0 + */ + public PropertyConstraint eq(String propertyName, Object propertyValue, Comparator comparator) { + return new ParameterizedPropertyConstraint(propertyName, eq(propertyValue, comparator)); + } + + /** * Apply a "greater than" constraint to a bean property. * * @param propertyName The first property @@ -644,8 +658,111 @@ * * @param propertyName The first property * @param otherPropertyName The other property + * @param comparator the comparator to use while comparing the values * @return The constraint + * + * @since 0.3.0 */ + public PropertyConstraint eqProperty(String propertyName, String otherPropertyName, Comparator comparator) { + return valueProperties(propertyName, EqualTo.instance(comparator), otherPropertyName); + } + + /** + * Apply a "greater than" constraint to two properties + * + * @param propertyName The first property + * @param otherPropertyName The other property + * @param comparator the comparator to use while comparing the values + * @return The constraint + * + * @since 0.3.0 + */ + public PropertyConstraint gtProperty(String propertyName, String otherPropertyName, Comparator comparator) { + return valueProperties(propertyName, GreaterThan.instance(comparator), otherPropertyName); + } + + /** + * Apply a "greater than or equal to" constraint to two properties. + * + * @param propertyName The first property + * @param otherPropertyName The other property + * @param comparator the comparator to use while comparing the values + * @return The constraint + * + * @since 0.3.0 + */ + public PropertyConstraint gteProperty(String propertyName, String otherPropertyName, Comparator comparator) { + return valueProperties(propertyName, GreaterThanEqualTo.instance(comparator), otherPropertyName); + } + + /** + * Apply a "less than" constraint to two properties. + * + * @param propertyName The first property + * @param otherPropertyName The other property + * @param comparator the comparator to use while comparing the values + * @return The constraint + * + * @since 0.3.0 + */ + public PropertyConstraint ltProperty(String propertyName, String otherPropertyName, Comparator comparator) { + return valueProperties(propertyName, LessThan.instance(comparator), otherPropertyName); + } + + /** + * Apply a "less than or equal to" constraint to two properties. + * + * @param propertyName The first property + * @param otherPropertyName The other property + * @param comparator the comparator to use while comparing the values + * @return The constraint + * + * @since 0.3.0 + */ + public PropertyConstraint lteProperty(String propertyName, String otherPropertyName, Comparator comparator) { + return valueProperties(propertyName, LessThanEqualTo.instance(comparator), otherPropertyName); + } + + /** + * Apply a inclusive "range" constraint to a bean property. + * + * @param propertyName the property with the range constraint. + * @param min the low edge of the range + * @param max the high edge of the range + * @param comparator the comparator to use while comparing the values + * @return The range constraint constraint + * + * @since 0.3.0 + */ + public PropertyConstraint inRange(String propertyName, Object min, Object max, Comparator comparator) { + return value(propertyName, range(min, max, comparator)); + } + + /** + * Apply a inclusive "range" constraint between two other properties to a + * bean property. + * + * @param propertyName the property with the range constraint. + * @param minPropertyName the low edge of the range + * @param maxPropertyName the high edge of the range + * @param comparator the comparator to use while comparing the values + * @return The range constraint constraint + * + * @since 0.3.0 + */ + public PropertyConstraint inRangeProperties(String propertyName, String minPropertyName, String maxPropertyName, Comparator comparator) { + Constraint min = gteProperty(propertyName, minPropertyName, comparator); + Constraint max = lteProperty(propertyName, maxPropertyName, comparator); + return new CompoundPropertyConstraint(new And(min, max)); + } + + /** + * Apply a "equal to" constraint to two bean properties. + * + * @param propertyName The first property + * @param otherPropertyName The other property + * @return The constraint + */ public PropertyConstraint eqProperty(String propertyName, String otherPropertyName) { return valueProperties(propertyName, EqualTo.instance(), otherPropertyName); } @@ -716,9 +833,8 @@ * @return The range constraint constraint */ public PropertyConstraint inRangeProperties(String propertyName, String minPropertyName, String maxPropertyName) { - PropertiesConstraint min = new PropertiesConstraint(propertyName, GreaterThanEqualTo.instance(), - minPropertyName); - PropertiesConstraint max = new PropertiesConstraint(propertyName, LessThanEqualTo.instance(), maxPropertyName); + Constraint min = gteProperty(propertyName, minPropertyName); + Constraint max = lteProperty(propertyName, maxPropertyName); return new CompoundPropertyConstraint(new And(min, max)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ spring-rich-c-cvs mailing list spring-rich-c-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs