1 8 9 package org.picocontainer.gems.constraints; 10 11 import org.picocontainer.ComponentAdapter; 12 import org.picocontainer.PicoVisitor; 13 14 21 public class Or extends AbstractConstraint { 22 private Constraint[] children; 23 24 public Or(Constraint c1, Constraint c2) { 25 children = new Constraint[2]; 26 children[0] = c1; 27 children[1] = c2; 28 } 29 30 public Or(Constraint c1, Constraint c2, Constraint c3) { 31 children = new Constraint[3]; 32 children[0] = c1; 33 children[1] = c2; 34 children[2] = c3; 35 } 36 37 public Or(Constraint[] cc) { 38 children = new Constraint[cc.length]; 39 System.arraycopy(cc, 0, children, 0, cc.length); 40 } 41 42 public boolean evaluate(ComponentAdapter adapter) { 43 for (int i = 0; i < children.length; i++) { 44 if (children[i].evaluate(adapter)) { 45 return true; 46 } 47 } 48 return false; 49 } 50 51 public void accept(PicoVisitor visitor) { 52 super.accept(visitor); 53 for (int i = 0; i < children.length; i++) { 54 children[i].accept(visitor); 55 } 56 } 57 } 58 | Popular Tags |