01: /*
02: * Copyright (C) 2006 Joe Walnes.
03: * Copyright (C) 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 13. June 2006 by Guilherme Silveira
11: */
12: package com.thoughtworks.xstream.persistence;
13:
14: import java.util.AbstractMap;
15: import java.util.AbstractSet;
16: import java.util.Iterator;
17: import java.util.Set;
18:
19: /**
20: * A persistent map. Its values are actually serialized as xml files. If you
21: * need an application-wide synchronized version of this map, try the respective
22: * Collections methods.
23: *
24: * @author Guilherme Silveira
25: */
26: public class XmlMap extends AbstractMap {
27:
28: private final StreamStrategy streamStrategy;
29:
30: public XmlMap(StreamStrategy streamStrategy) {
31: this .streamStrategy = streamStrategy;
32: }
33:
34: public int size() {
35: return streamStrategy.size();
36: }
37:
38: public Object get(Object key) {
39: // faster lookup
40: return streamStrategy.get(key);
41: }
42:
43: public Object put(Object key, Object value) {
44: return streamStrategy.put(key, value);
45: }
46:
47: public Object remove(Object key) {
48: return streamStrategy.remove(key);
49: }
50:
51: public Set entrySet() {
52: return new XmlMapEntries();
53: }
54:
55: class XmlMapEntries extends AbstractSet {
56:
57: public int size() {
58: return XmlMap.this .size();
59: }
60:
61: public boolean isEmpty() {
62: return XmlMap.this .isEmpty();
63: }
64:
65: public Iterator iterator() {
66: return streamStrategy.iterator();
67: }
68:
69: }
70:
71: }
|