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 import java.util.Set; 020 021 import org.springframework.rules.closure.Closure; 022 import org.springframework.rules.constraint.Constraint; 023 import org.springframework.rules.closure.support.AlgorithmsAccessor; 024 import org.springframework.rules.closure.BinaryConstraint; 025 import org.springframework.rules.constraint.Like.LikeType; 026 import org.springframework.rules.constraint.property.PropertyConstraint; 027 import org.springframework.rules.factory.Constraints; 028 029 /** 030 * A convenience constraints factory accessor for easy subclassing. 031 * 032 * @author Keith Donald 033 */ 034 public class ConstraintsAccessor extends AlgorithmsAccessor { 035 036 protected Constraints getConstraints() { 037 return Constraints.instance(); 038 } 039 040 public Constraint bind(BinaryConstraint constraint, Object parameter) { 041 return getConstraints().bind(constraint, parameter); 042 } 043 044 public Constraint bind(BinaryConstraint constraint, int parameter) { 045 return getConstraints().bind(constraint, parameter); 046 } 047 048 public Constraint bind(BinaryConstraint constraint, float parameter) { 049 return getConstraints().bind(constraint, parameter); 050 } 051 052 public Constraint bind(BinaryConstraint constraint, double parameter) { 053 return getConstraints().bind(constraint, parameter); 054 } 055 056 public Constraint bind(BinaryConstraint constraint, boolean parameter) { 057 return getConstraints().bind(constraint, parameter); 058 } 059 060 public Constraint testResultOf(Closure closure, Constraint constraint) { 061 return getConstraints().testResultOf(closure, constraint); 062 } 063 064 public Constraint eq(Object value) { 065 return getConstraints().eq(value); 066 } 067 068 public Constraint eq(int value) { 069 return getConstraints().eq(value); 070 } 071 072 public Constraint eq(Object value, Comparator comparator) { 073 return getConstraints().eq(value, comparator); 074 } 075 076 public Constraint gt(Comparable value) { 077 return getConstraints().gt(value); 078 } 079 080 public Constraint gt(Object value, Comparator comparator) { 081 return getConstraints().gt(value, comparator); 082 } 083 084 public Constraint gt(int value) { 085 return getConstraints().gt(value); 086 } 087 088 public Constraint gt(long value) { 089 return getConstraints().gt(value); 090 } 091 092 public Constraint gt(float value) { 093 return getConstraints().gt(value); 094 } 095 096 public Constraint gt(double value) { 097 return getConstraints().gt(value); 098 } 099 100 public Constraint gte(Comparable value) { 101 return getConstraints().gte(value); 102 } 103 104 public Constraint gte(Object value, Comparator comparator) { 105 return getConstraints().gte(value, comparator); 106 } 107 108 public Constraint gte(int value) { 109 return getConstraints().gte(value); 110 } 111 112 public Constraint gte(long value) { 113 return getConstraints().gte(value); 114 } 115 116 public Constraint gte(float value) { 117 return getConstraints().gte(value); 118 } 119 120 public Constraint gte(double value) { 121 return getConstraints().gte(value); 122 } 123 124 public Constraint lt(Comparable value) { 125 return getConstraints().lt(value); 126 } 127 128 public Constraint lt(Comparable value, Comparator comparator) { 129 return getConstraints().lt(value, comparator); 130 } 131 132 public Constraint lt(int value) { 133 return getConstraints().lt(value); 134 } 135 136 public Constraint lt(long value) { 137 return getConstraints().lt(value); 138 } 139 140 public Constraint lt(float value) { 141 return getConstraints().lt(value); 142 } 143 144 public Constraint lt(double value) { 145 return getConstraints().lt(value); 146 } 147 148 public Constraint lte(Comparable value) { 149 return getConstraints().lte(value); 150 } 151 152 public Constraint lte(Object value, Comparator comparator) { 153 return getConstraints().lte(value, comparator); 154 } 155 156 public Constraint lte(int value) { 157 return getConstraints().lte(value); 158 } 159 160 public Constraint lte(long value) { 161 return getConstraints().lte(value); 162 } 163 164 public Constraint lte(float value) { 165 return getConstraints().lte(value); 166 } 167 168 public Constraint lte(double value) { 169 return getConstraints().lte(value); 170 } 171 172 public Constraint range(Comparable min, Comparable max) { 173 return getConstraints().range(min, max); 174 } 175 176 public Constraint range(Comparable min, Comparable max, boolean inclusive) { 177 return getConstraints().range(min, max, inclusive); 178 } 179 180 public Constraint range(Object min, Object max, Comparator comparator) { 181 return getConstraints().range(min, max, comparator); 182 } 183 184 public Constraint range(Object min, Object max, Comparator comparator, boolean inclusive) { 185 return getConstraints().range(min, max, comparator, inclusive); 186 } 187 188 public Constraint range(int min, int max) { 189 return getConstraints().range(min, max); 190 } 191 192 public Constraint range(long min, long max) { 193 return getConstraints().range(min, max); 194 } 195 196 public Constraint range(float min, float max) { 197 return getConstraints().range(min, max); 198 } 199 200 public Constraint present() { 201 return getConstraints().present(); 202 } 203 204 public PropertyConstraint present(String property) { 205 return getConstraints().present(property); 206 } 207 208 public Constraint ifTrue(Constraint constraint, Constraint mustAlsoBeTrue) { 209 return getConstraints().ifTrue(constraint, mustAlsoBeTrue); 210 } 211 212 public Constraint ifTrueElse(Constraint constraint, Constraint mustAlsoBeTrue, Constraint elseMustAlsoBeTrue) { 213 return getConstraints().ifTrue(constraint, mustAlsoBeTrue, elseMustAlsoBeTrue); 214 } 215 216 public Constraint and(Constraint constraint1, Constraint constraint2) { 217 return getConstraints().and(constraint1, constraint2); 218 } 219 220 public Constraint all(Constraint[] predicates) { 221 return getConstraints().all(predicates); 222 } 223 224 public And conjunction() { 225 return getConstraints().conjunction(); 226 } 227 228 public Constraint or(Constraint constraint1, Constraint constraint2) { 229 return getConstraints().or(constraint1, constraint2); 230 } 231 232 public Constraint any(Constraint[] constraints) { 233 return getConstraints().any(constraints); 234 } 235 236 public Constraint not(Constraint constraint) { 237 return getConstraints().not(constraint); 238 } 239 240 public Or disjunction() { 241 return getConstraints().disjunction(); 242 } 243 244 public Constraint inGroup(Set group) { 245 return getConstraints().inGroup(group); 246 } 247 248 public Constraint inGroup(Object[] group) { 249 return getConstraints().inGroup(group); 250 } 251 252 public PropertyConstraint inGroup(String propertyName, Object[] group) { 253 return getConstraints().inGroup(propertyName, group); 254 } 255 256 public Constraint like(String encodedLikeString) { 257 return getConstraints().like(encodedLikeString); 258 } 259 260 public PropertyConstraint like(String property, LikeType likeType, String value) { 261 return getConstraints().like(property, likeType, value); 262 } 263 264 public Constraint required() { 265 return getConstraints().required(); 266 } 267 268 public PropertyConstraint required(String property) { 269 return getConstraints().required(property); 270 } 271 272 public Constraint maxLength(int maxLength) { 273 return getConstraints().maxLength(maxLength); 274 } 275 276 public Constraint minLength(int minLength) { 277 return getConstraints().minLength(minLength); 278 } 279 280 public Constraint regexp(String regexp) { 281 return getConstraints().regexp(regexp); 282 } 283 284 public Constraint regexp(String regexp, String constraintType) { 285 return getConstraints().regexp(regexp, constraintType); 286 } 287 288 public Constraint method(Object target, String methodName, String constraintType) { 289 return getConstraints().method(target, methodName, constraintType); 290 } 291 292 public PropertyConstraint value(String propertyName, Constraint valueConstraint) { 293 return getConstraints().value(propertyName, valueConstraint); 294 } 295 296 public PropertyConstraint all(String propertyName, Constraint[] constraints) { 297 return getConstraints().all(propertyName, constraints); 298 } 299 300 public PropertyConstraint any(String propertyName, Constraint[] constraints) { 301 return getConstraints().any(propertyName, constraints); 302 } 303 304 public PropertyConstraint not(PropertyConstraint constraint) { 305 return getConstraints().not(constraint); 306 } 307 308 public PropertyConstraint eq(String propertyName, Object propertyValue) { 309 return getConstraints().eq(propertyName, propertyValue); 310 } 311 312 /** 313 * @since 0.3.0 314 */ 315 public PropertyConstraint eq(String propertyName, Object propertyValue, Comparator comparator) { 316 return getConstraints().eq(propertyName, propertyValue, comparator); 317 } 318 319 public PropertyConstraint gt(String propertyName, Comparable propertyValue) { 320 return getConstraints().gt(propertyName, propertyValue); 321 } 322 323 public PropertyConstraint gte(String propertyName, Comparable propertyValue) { 324 return getConstraints().gte(propertyName, propertyValue); 325 } 326 327 public PropertyConstraint lt(String propertyName, Comparable propertyValue) { 328 return getConstraints().lt(propertyName, propertyValue); 329 } 330 331 public PropertyConstraint lte(String propertyName, Comparable propertyValue) { 332 return getConstraints().lte(propertyName, propertyValue); 333 } 334 335 /** 336 * @since 0.3.0 337 */ 338 public PropertyConstraint eqProperty(String propertyName, String otherPropertyName, Comparator comparator) { 339 return getConstraints().eqProperty(propertyName, otherPropertyName, comparator); 340 } 341 342 /** 343 * @since 0.3.0 344 */ 345 public PropertyConstraint gtProperty(String propertyName, String otherPropertyName, Comparator comparator) { 346 return getConstraints().gtProperty(propertyName, otherPropertyName, comparator); 347 } 348 349 /** 350 * @since 0.3.0 351 */ 352 public PropertyConstraint gteProperty(String propertyName, String otherPropertyName, Comparator comparator) { 353 return getConstraints().gteProperty(propertyName, otherPropertyName, comparator); 354 } 355 356 /** 357 * @since 0.3.0 358 */ 359 public PropertyConstraint ltProperty(String propertyName, String otherPropertyName, Comparator comparator) { 360 return getConstraints().ltProperty(propertyName, otherPropertyName, comparator); 361 } 362 363 /** 364 * @since 0.3.0 365 */ 366 public PropertyConstraint lteProperty(String propertyName, String otherPropertyName, Comparator comparator) { 367 return getConstraints().lteProperty(propertyName, otherPropertyName, comparator); 368 } 369 370 /** 371 * @since 0.3.0 372 */ 373 public PropertyConstraint inRange(String propertyName, Comparable min, Comparable max, Comparator comparator) { 374 return getConstraints().inRange(propertyName, min, max, comparator); 375 } 376 377 /** 378 * @since 0.3.0 379 */ 380 public PropertyConstraint inRangeProperties(String propertyName, String minPropertyName, String maxPropertyName, Comparator comparator) { 381 return getConstraints().inRangeProperties(propertyName, minPropertyName, maxPropertyName, comparator); 382 } 383 384 public PropertyConstraint eqProperty(String propertyName, String otherPropertyName) { 385 return getConstraints().eqProperty(propertyName, otherPropertyName); 386 } 387 388 public PropertyConstraint gtProperty(String propertyName, String otherPropertyName) { 389 return getConstraints().gtProperty(propertyName, otherPropertyName); 390 } 391 392 public PropertyConstraint gteProperty(String propertyName, String otherPropertyName) { 393 return getConstraints().gteProperty(propertyName, otherPropertyName); 394 } 395 396 public PropertyConstraint ltProperty(String propertyName, String otherPropertyName) { 397 return getConstraints().ltProperty(propertyName, otherPropertyName); 398 } 399 400 public PropertyConstraint lteProperty(String propertyName, String otherPropertyName) { 401 return getConstraints().lteProperty(propertyName, otherPropertyName); 402 } 403 404 public PropertyConstraint inRange(String propertyName, Comparable min, Comparable max) { 405 return getConstraints().inRange(propertyName, min, max); 406 } 407 408 public PropertyConstraint inRangeProperties(String propertyName, String minPropertyName, String maxPropertyName) { 409 return getConstraints().inRangeProperties(propertyName, minPropertyName, maxPropertyName); 410 } 411 412 public PropertyConstraint unique(String propertyName) { 413 return getConstraints().unique(propertyName); 414 } 415 416 }