KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > headercache > MemoryHeaderList


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.folder.headercache;
19
20 import java.util.Hashtable JavaDoc;
21 import java.util.Set JavaDoc;
22
23 import org.columba.mail.message.ICloseableIterator;
24 import org.columba.mail.message.IColumbaHeader;
25 import org.columba.mail.message.IHeaderList;
26
27 public class MemoryHeaderList implements IHeaderList {
28     protected Hashtable JavaDoc map;
29
30     public MemoryHeaderList() {
31         map = new Hashtable JavaDoc();
32     }
33     
34     public void add(IColumbaHeader header, Object JavaDoc uid) {
35         if( header.get("columba.uid") == null) {
36             header.set("columba.uid", uid);
37         }
38         
39         map.put(uid, header);
40     }
41
42     public int count() {
43         return map.size();
44     }
45
46     public boolean exists(Object JavaDoc uid) {
47         return map.containsKey(uid);
48     }
49
50     public Set JavaDoc keySet() {
51         return map.keySet();
52     }
53     
54
55     public void clear() {
56         map.clear();
57     }
58
59     public IColumbaHeader get(Object JavaDoc uid) {
60         return (IColumbaHeader) map.get(uid);
61     }
62
63     public Object JavaDoc[] getUids() {
64         return map.keySet().toArray();
65     }
66
67     public IColumbaHeader remove(Object JavaDoc uid) {
68         return (IColumbaHeader)map.remove(uid);
69     }
70
71     public ICloseableIterator headerIterator() {
72         return new DefaultCloseableIterator( map.values().iterator() );
73     }
74
75     public void update(Object JavaDoc uid, IColumbaHeader header) {
76         //Update is unnecessary
77
}
78
79     public ICloseableIterator keyIterator() {
80         return new DefaultCloseableIterator(map.keySet().iterator());
81     }
82 }
83
Popular Tags