01: // Copyright (c) 2004 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.mapping;
05:
06: /** A Location suitable when Environment or Location can be access by
07: * multiple threads. Accesses are synchronized. */
08:
09: public class SharedLocation extends NamedLocation {
10: int timestamp;
11:
12: public SharedLocation(Symbol symbol, Object property, int timestamp) {
13: super (symbol, property);
14: this .timestamp = timestamp;
15: }
16:
17: public synchronized final Object get(Object defaultValue) {
18: return base != null ? base.get(defaultValue)
19: : value == Location.UNBOUND ? defaultValue : value;
20: }
21:
22: public synchronized boolean isBound() {
23: return base != null ? base.isBound()
24: : value != Location.UNBOUND;
25: }
26:
27: public synchronized final void set(Object newValue) {
28: if (base == null)
29: value = newValue;
30: else if (value == DIRECT_ON_SET) {
31: base = null;
32: value = newValue;
33: } else if (base.isConstant())
34: getEnvironment().put(getKeySymbol(), getKeyProperty(),
35: newValue);
36: else
37: base.set(newValue);
38: }
39:
40: }
|