KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > caching > AggregatedCacheValidity


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.caching;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 /**
23  * A validation object aggregating several validity objects. This is similar to the
24  * {@link CompositeCacheValidity} with the difference that the amount of
25  * aggregated objects is not limited.
26  *
27  * @deprecated Use the Avalon Excalibur SourceValidity implementations instead
28  * @author <a HREF="mailto:dims@yahoo.com">Davanum Srinivas</a>
29  * @version CVS $Id: AggregatedCacheValidity.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31 public final class AggregatedCacheValidity
32 implements CacheValidity {
33
34     private List JavaDoc a;
35
36     /**
37      * Constructor
38      */

39     public AggregatedCacheValidity() {
40         this.a = new ArrayList JavaDoc();
41     }
42
43     /**
44      * Add another validity object
45      */

46     public void add(CacheValidity validity) {
47         this.a.add(validity);
48     }
49
50     public boolean isValid(CacheValidity validity) {
51         if (validity instanceof AggregatedCacheValidity) {
52             List JavaDoc b = ((AggregatedCacheValidity)validity).a;
53             if(a.size() != b.size())
54                 return false;
55             for(Iterator JavaDoc i = a.iterator(), j = b.iterator(); i.hasNext();) {
56                 if(!((CacheValidity)i.next()).isValid((CacheValidity)j.next()))
57                     return false;
58             }
59             return true;
60         }
61         return false;
62     }
63
64     public String JavaDoc toString() {
65         StringBuffer JavaDoc b = new StringBuffer JavaDoc("Aggregated Validity[");
66         for(Iterator JavaDoc i = a.iterator(); i.hasNext();) {
67             b.append(i.next());
68             if(i.hasNext()) b.append(':');
69         }
70         b.append(']');
71         return b.toString();
72     }
73 }
74
75
Popular Tags