1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springmodules.validation.util.condition.adapter;
18
19 import org.apache.commons.collections.Predicate;
20 import org.springframework.util.Assert;
21 import org.springmodules.validation.util.condition.AbstractCondition;
22
23 /**
24 * A Jakarta Commmons Predicate condition adapter. This condition deligates the call to an associated {@link Predicate).
25 *
26 * @author Uri Boness
27 */
28 public class CommonsPredicateCondition extends AbstractCondition {
29
30 private Predicate predicate;
31
32 /**
33 * Constructs a new CommonsPredicateCondition with a given predicate.
34 *
35 * @param predicate The given predicate.
36 */
37 public CommonsPredicateCondition(Predicate predicate) {
38 Assert.notNull(predicate, "Predicate cannot be null");
39 this.predicate = predicate;
40 }
41
42 /**
43 * Checks the given object against the predicate associated with this condition.
44 *
45 * @param object The object to be checked.
46 * @return The result returned by the associated predicate when evaluting the given object.
47 * See {@link Predicate#evaluate(Object)}.
48 */
49 public boolean doCheck(Object object) {
50 return predicate.evaluate(object);
51 }
52
53
54
55 /**
56 * Returns the predicate associated with this condition.
57 *
58 * @return The predicate associated with this condition.
59 */
60 public Predicate getPredicate() {
61 return predicate;
62 }
63
64 }