01: /* -*- mode: Java; c-basic-offset: 2; -*- */
02:
03: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
04: * Copyright 2001-2005 Laszlo Systems, Inc. All Rights Reserved. *
05: * Use is subject to license terms. *
06: * J_LZ_COPYRIGHT_END *********************************************************/
07:
08: package org.openlaszlo.sc;
09:
10: import java.util.*;
11:
12: // Each entry has three parts:
13: // - a key, used to store and retrieve it
14: // - a checksum, which tells whether the value is current
15: // - a value
16: public class ScriptCompilerCache extends HashMap {
17:
18: public ScriptCompilerCache() {
19: super ();
20: }
21:
22: static class ScriptCompilerCacheEntry {
23: Object checksum;
24: Object value;
25:
26: ScriptCompilerCacheEntry(Object checksum, Object value) {
27: this .checksum = checksum;
28: this .value = value;
29: }
30: }
31:
32: public boolean containsKey(Object key, Object checksum) {
33: if (containsKey(key)) {
34: ScriptCompilerCacheEntry entry = (ScriptCompilerCacheEntry) get(key);
35: if (entry.checksum.equals(checksum)) {
36: return true;
37: }
38: }
39: return false;
40: }
41:
42: public Object get(Object key, Object checksum) {
43: ScriptCompilerCacheEntry entry = (ScriptCompilerCacheEntry) get(key);
44: if (entry != null && entry.checksum.equals(checksum)) {
45: return entry.value;
46: }
47: return null;
48: }
49:
50: public void put(Object key, Object checksum, Object value) {
51: put(key, new ScriptCompilerCacheEntry(checksum, value));
52: }
53: }
|