01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //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;
21: import java.util.Set;
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 map;
29:
30: public MemoryHeaderList() {
31: map = new Hashtable();
32: }
33:
34: public void add(IColumbaHeader header, Object 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 uid) {
47: return map.containsKey(uid);
48: }
49:
50: public Set keySet() {
51: return map.keySet();
52: }
53:
54: public void clear() {
55: map.clear();
56: }
57:
58: public IColumbaHeader get(Object uid) {
59: return (IColumbaHeader) map.get(uid);
60: }
61:
62: public Object[] getUids() {
63: return map.keySet().toArray();
64: }
65:
66: public IColumbaHeader remove(Object uid) {
67: return (IColumbaHeader) map.remove(uid);
68: }
69:
70: public ICloseableIterator headerIterator() {
71: return new DefaultCloseableIterator(map.values().iterator());
72: }
73:
74: public void update(Object uid, IColumbaHeader header) {
75: //Update is unnecessary
76: }
77:
78: public ICloseableIterator keyIterator() {
79: return new DefaultCloseableIterator(map.keySet().iterator());
80: }
81: }
|