001: /*
002: Copyright 2004 Philip Jacob <phil@whirlycott.com>
003: Seth Fitzsimmons <seth@note.amherst.edu>
004:
005: Licensed under the Apache License, Version 2.0 (the "License");
006: you may not use this file except in compliance with the License.
007: You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: */
017:
018: package com.whirlycott.cache.impl;
019:
020: import java.util.Collection;
021: import java.util.Map;
022: import java.util.Set;
023:
024: import com.whirlycott.cache.ManagedCache;
025:
026: /**
027: * This is an abstract class for help in developing a cache backend using an implementation of java.util.Map.
028: *
029: * @author Phil Jacob
030: */
031: public abstract class AbstractMapBackedCache<K, V> implements
032: ManagedCache<K, V> {
033:
034: /**
035: * Underlying Map to store cached objects in.
036: */
037: protected Map<K, V> c;
038:
039: public void destroy() {
040: c.clear();
041: c = null;
042: }
043:
044: public abstract void setMostlyRead(final boolean _mostlyRead);
045:
046: public int size() {
047: return c.size();
048: }
049:
050: public void clear() {
051: c.clear();
052: }
053:
054: public boolean isEmpty() {
055: return c.isEmpty();
056: }
057:
058: public boolean containsKey(final Object key) {
059: return c.containsKey(key);
060: }
061:
062: public boolean containsValue(final Object value) {
063: return c.containsValue(value);
064: }
065:
066: public Collection<V> values() {
067: return c.values();
068: }
069:
070: public void putAll(final Map<? extends K, ? extends V> t) {
071: c.putAll(t);
072: }
073:
074: public Set<Map.Entry<K, V>> entrySet() {
075: return c.entrySet();
076: }
077:
078: public Set<K> keySet() {
079: return c.keySet();
080: }
081:
082: public V get(final Object key) {
083: return c.get(key);
084: }
085:
086: public V remove(final Object key) {
087: return c.remove(key);
088: }
089:
090: public V put(final K key, final V value) {
091: return c.put(key, value);
092: }
093:
094: public void store(final K key, final V value) {
095: c.put(key, value);
096: }
097:
098: public V retrieve(final K key) {
099: return c.get(key);
100: }
101:
102: }
|