View Javadoc

1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH Munich, Germany (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  
23  package de.bea.domingo.cache;
24  
25  import java.io.Serializable;
26  import java.util.Collection;
27  import java.util.HashMap;
28  import java.util.Map;
29  import java.util.Set;
30  
31  
32  /***
33   * Simple cache implementation using a HashMap.
34   *
35   * <b>Note that this implementation is not synchronized.</b> If multiple
36   * threads access this cache concurrently, and at least one of the threads
37   * modifies the cache structurally, it <i>must</i> be synchronized externally.
38   * (A structural modification is any operation that adds or deletes one or
39   * more mappings; merely changing the value associated with a key that an
40   * instance already contains is not a structural modification.)<p>
41   *
42   *
43   * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
44   */
45  public final class SimpleCache extends AbstractBaseCache implements Serializable {
46  
47      /*** serial version ID for serialization. */
48      private static final long serialVersionUID = 4740967132553277227L;
49  
50      /***
51       * Constructor.
52       */
53      public SimpleCache() {
54          super();
55      }
56  
57      /***
58       * {@inheritDoc}
59       * @see de.bea.domingo.cache.AbstractBaseCache#createMap()
60       */
61      protected Map createMap() {
62          return new HashMap();
63      }
64  
65      /***
66       * {@inheritDoc}
67       * @see de.bea.domingo.cache.Cache#get(java.lang.Object)
68       */
69      public Object get(final Object key) {
70          return getMap().get(key);
71      }
72  
73      /***
74       * {@inheritDoc}
75       * @see de.bea.domingo.cache.Cache#put(java.lang.Object, java.lang.Object)
76       */
77      public void put(final Object key, final Object value) {
78          getMap().put(key, value);
79      }
80  
81      /***
82       * {@inheritDoc}
83       * @see de.bea.domingo.cache.Cache#containsKey(java.lang.Object)
84       */
85      public boolean containsKey(final Object key) {
86          return getMap().containsKey(key);
87      }
88  
89      /***
90       * {@inheritDoc}
91       * @see de.bea.domingo.cache.Cache#remove(java.lang.Object)
92       */
93      public Object remove(final Object key) {
94          return getMap().remove(key);
95      }
96  
97      /***
98       * {@inheritDoc}
99       * @see de.bea.domingo.cache.Cache#clear()
100      */
101     public void clear() {
102         getMap().clear();
103     }
104 
105     /***
106      * {@inheritDoc}
107      * @see de.bea.domingo.cache.AbstractBaseCache#keySet()
108      */
109     public Set keySet() {
110       return getMap().keySet();
111     }
112 
113     /***
114      * {@inheritDoc}
115      * @see de.bea.domingo.cache.AbstractBaseCache#values()
116      */
117     public Collection values() {
118       return getMap().values();
119     }
120 }