KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > source > validity > AggregatedValidity


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.source.validity;
9
10 import org.apache.avalon.excalibur.source.SourceValidity;
11
12 import java.util.ArrayList JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15
16 /**
17  * A validation object using a List.
18  *
19  * @author <a HREF="mailto:dims@yahoo.com">Davanum Srinivas</a>
20  * @version CVS $Revision: 1.1 $ $Date: 2001/12/17 13:55:03 $
21  */

22 public final class AggregatedValidity
23 implements SourceValidity {
24
25     private List JavaDoc a;
26
27     public AggregatedValidity() {
28         this.a = new ArrayList JavaDoc();
29     }
30
31     public void add(SourceValidity validity) {
32         this.a.add(validity);
33     }
34
35     public boolean isValid() {
36         for(Iterator JavaDoc 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 JavaDoc b = ((AggregatedValidity)validity).a;
46             if(a.size() != b.size())
47                 return false;
48             for(Iterator JavaDoc 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 JavaDoc toString() {
60         StringBuffer JavaDoc b = new StringBuffer JavaDoc("SourceValidity ");
61         for(Iterator JavaDoc 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