KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hsqldb > store > ObjectCacheHashMap


1 /* Copyright (c) 2001-2005, The HSQL Development Group
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of the HSQL Development Group nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31
32 package org.hsqldb.store;
33
34 import org.hsqldb.lib.Collection;
35 import org.hsqldb.lib.Iterator;
36 import org.hsqldb.lib.Set;
37
38 /**
39  * Maps integer keys to Objects. Hashes the keys.
40  *
41  * @author fredt@users
42  * @version 1.8.0
43  * @since 1.8.0
44  */

45 public class ObjectCacheHashMap extends BaseHashMap {
46
47     Set keySet;
48     Collection values;
49
50     public ObjectCacheHashMap(int initialCapacity)
51     throws IllegalArgumentException JavaDoc {
52         super(initialCapacity, 1, BaseHashMap.intKeyOrValue,
53               BaseHashMap.objectKeyOrValue, true);
54     }
55
56     public Object JavaDoc get(int key) {
57
58         if (accessCount == Integer.MAX_VALUE) {
59             resetAccessCount();
60         }
61
62         int lookup = getLookup(key);
63
64         if (lookup == -1) {
65             return null;
66         }
67
68         accessTable[lookup] = accessCount++;
69
70         return objectValueTable[lookup];
71     }
72
73     public Object JavaDoc put(int key, Object JavaDoc value) {
74
75         if (accessCount == Integer.MAX_VALUE) {
76             resetAccessCount();
77         }
78
79         return super.addOrRemove(key, value, false);
80     }
81
82     public Object JavaDoc remove(int key) {
83         return super.addOrRemove(key, null, true);
84     }
85
86     /**
87      * for count number of elements with the given margin, return the access
88      * count.
89      */

90     public int getAccessCountCeiling(int count, int margin) {
91         return super.getAccessCountCeiling(count, margin);
92     }
93
94     /**
95      * This is called after all elements below count accessCount have been
96      * removed
97      */

98     public void setAccessCountFloor(int count) {
99         super.accessMin = count;
100     }
101
102     public ObjectCacheIterator iterator() {
103         return new ObjectCacheIterator();
104     }
105
106     public class ObjectCacheIterator extends BaseHashIterator
107     implements Iterator {}
108 }
109
Popular Tags