KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > cache > store > MemoryStore


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.cache.store;
9
10 import java.util.HashMap JavaDoc;
11
12 /**
13  * @author <a HREF="mailto:colus@apache.org">Eung-ju Park</a>
14  */

15 public class MemoryStore
16     extends AbstractCacheStore
17 {
18     private HashMap JavaDoc m_entries;
19     private int m_capacity;
20
21     public MemoryStore( final int capacity )
22     {
23         if ( capacity < 1 ) throw new IllegalArgumentException JavaDoc( "Specified capacity must be at least 1" );
24
25         m_capacity = capacity;
26         m_entries = new HashMap JavaDoc( m_capacity );
27     }
28
29     public int capacity()
30     {
31         return m_capacity;
32     }
33
34     public int size()
35     {
36         return m_entries.size();
37     }
38
39     public Object JavaDoc put( final Object JavaDoc key, final Object JavaDoc value )
40     {
41         return m_entries.put( key, value );
42     }
43
44     public Object JavaDoc get( final Object JavaDoc key )
45     {
46         return m_entries.get( key );
47     }
48
49     public Object JavaDoc remove( final Object JavaDoc key )
50     {
51         return m_entries.remove( key );
52     }
53
54     public boolean containsKey( final Object JavaDoc key )
55     {
56         return m_entries.containsKey( key );
57     }
58
59     public Object JavaDoc[] keys()
60     {
61         return m_entries.keySet().toArray();
62     }
63 }
64
Popular Tags