01: /*****************************************************************************
02: * Copyright (C) PicoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: *****************************************************************************/package org.picocontainer.gems.constraints;
08:
09: import org.picocontainer.ComponentAdapter;
10: import org.picocontainer.PicoVisitor;
11:
12: /**
13: * Aggregates multiple constraints together using boolean AND logic.
14: * Constraints are short-circuited as in java.
15: *
16: * @author Nick Sieger
17: */
18: public final class And extends AbstractConstraint {
19: private final Constraint[] children;
20:
21: public And(Constraint c1, Constraint c2) {
22: children = new Constraint[2];
23: children[0] = c1;
24: children[1] = c2;
25: }
26:
27: public And(Constraint c1, Constraint c2, Constraint c3) {
28: children = new Constraint[3];
29: children[0] = c1;
30: children[1] = c2;
31: children[2] = c3;
32: }
33:
34: public And(Constraint[] cc) {
35: children = new Constraint[cc.length];
36: System.arraycopy(cc, 0, children, 0, cc.length);
37: }
38:
39: public boolean evaluate(ComponentAdapter adapter) {
40: for (Constraint aChildren : children) {
41: if (!aChildren.evaluate(adapter)) {
42: return false;
43: }
44: }
45: return true;
46: }
47:
48: public void accept(PicoVisitor visitor) {
49: super .accept(visitor);
50: for (Constraint aChildren : children) {
51: aChildren.accept(visitor);
52: }
53: }
54: }
|