1 8 package org.apache.avalon.excalibur.source.validity; 9 10 import org.apache.avalon.excalibur.source.SourceValidity; 11 12 import java.util.ArrayList ; 13 import java.util.Iterator ; 14 import java.util.List ; 15 16 22 public final class AggregatedValidity 23 implements SourceValidity { 24 25 private List a; 26 27 public AggregatedValidity() { 28 this.a = new ArrayList (); 29 } 30 31 public void add(SourceValidity validity) { 32 this.a.add(validity); 33 } 34 35 public boolean isValid() { 36 for(Iterator i = a.iterator(); i.hasNext();) { 37 if(!((SourceValidity )i.next()).isValid()) 38 return false; 39 } 40 return true; 41 } 42 43 public boolean isValid(SourceValidity validity) { 44 if (validity instanceof AggregatedValidity) { 45 List b = ((AggregatedValidity)validity).a; 46 if(a.size() != b.size()) 47 return false; 48 for(Iterator i = a.iterator(), j = b.iterator(); i.hasNext();) { 49 final SourceValidity srcA = ( SourceValidity )i.next(); 50 final SourceValidity srcB = ( SourceValidity )j.next(); 51 if (!srcA.isValid() && !srcA.isValid(srcB)) 52 return false; 53 } 54 return true; 55 } 56 return false; 57 } 58 59 public String toString() { 60 StringBuffer b = new StringBuffer ("SourceValidity "); 61 for(Iterator i = a.iterator(); i.hasNext();) { 62 b.append(i.next()); 63 if(i.hasNext()) b.append(':'); 64 } 65 return b.toString(); 66 } 67 } 68 69 | Popular Tags |