001package com.hammurapi.common.concurrent;
002
003import java.util.Set;
004import java.util.concurrent.Callable;
005import java.util.concurrent.Future;
006import java.util.concurrent.TimeUnit;
007
008import com.hammurapi.common.Context;
009
010public abstract class AbstractSubSet<KP> implements PropertySet<KP> {
011        
012        private PropertySet<KP> master;
013        
014        private KP prefix;
015        
016        protected abstract KP buildPath(KP prefix, KP key);
017        
018        protected AbstractSubSet(PropertySet<KP> master, KP prefix) {
019                super();
020                this.master = master;
021                this.prefix = prefix;
022        }
023
024        public void clear() {
025                master.subset(prefix).clear();
026        }
027        
028        public Object get(KP key) {
029                return master.get(buildPath(prefix, key));
030        }
031
032        public Object get(KP key, Object defaultValue) {
033                return master.get(buildPath(prefix, key), defaultValue);
034        }
035
036        public <T> T get(KP key, Class<T> type) {
037                return master.get(buildPath(prefix, key), type);
038        }
039
040        public <T> T get(KP key, Class<T> type, T defaultValue) {
041                return master.get(buildPath(prefix, key), type, defaultValue);
042        }
043
044        public Object get(KP key, long timeout, TimeUnit unit) {
045                return master.get(buildPath(prefix, key), timeout, unit);
046        }
047
048        public Object get(KP key, Object defaultValue, long timeout, TimeUnit unit) {
049                return master.get(buildPath(prefix, key), defaultValue, timeout, unit);
050        }
051
052        public <T> T get(KP key, Class<T> type, long timeout, TimeUnit unit) {
053                return master.get(buildPath(prefix, key), type, timeout, unit);
054        }
055
056        public <T> T get(KP key, Class<T> type, T defaultValue, long timeout, TimeUnit unit) {
057                return master.get(buildPath(prefix, key), type, defaultValue, timeout, unit);
058        }
059
060        public void cook(KP key, Callable<?> callable) {
061                master.cook(buildPath(prefix, key), callable);
062        }
063
064        public void cook(KP key, Callable<?> callable, long delay, TimeUnit timeUnit) {
065                master.cook(buildPath(prefix, key), callable, delay, timeUnit);
066        }
067
068        public void cooking(KP key, Future<?> future) {
069                master.cooking(buildPath(prefix, key), future);
070        }
071
072        public void cancel(KP key) {
073                master.cancel(buildPath(prefix, key));
074        }
075
076        public void cancelAll() {
077                master.subset(prefix).cancelAll();
078        }
079
080        public <T> T getAdapter(Class<T> targetType, Context context) {
081                return master.subset(prefix).getAdapter(targetType, context);
082        }
083
084        public Set<KP> keySet() {
085                return master.subset(prefix).keySet();
086        }
087
088        public PropertySet<KP> subset(KP prefix) {
089                return master.subset(buildPath(this.prefix, prefix));
090        }
091
092        public void remove(KP key) {
093                master.remove(buildPath(prefix, key));
094        }
095
096        public void mount(KP prefix, PropertySet<KP> source) {
097                master.mount(buildPath(this.prefix, prefix), source);
098        }
099
100        public void unmount(KP prefix) {
101                master.unmount(buildPath(this.prefix, prefix));
102        }
103
104        public void setAll(PropertySet<KP> source) {
105                master.subset(prefix).setAll(source);
106        }
107
108        public void set(KP key, Object value) {
109                master.set(buildPath(prefix, key), value);
110        }
111
112        public void setInvocable(KP key, Invocable<PropertySet<KP>, ?, KP, ?> invocable) {
113                master.setInvocable(buildPath(prefix, key), invocable);
114        }
115
116        public void lazy(KP key, Callable<?> callable) {
117                master.lazy(buildPath(prefix, key), callable);
118        }
119
120        public Object invoke(KP key, Object... args) {
121                return master.invoke(buildPath(prefix, key), args);
122        }
123
124        public Object shadowInvoke(KP key, Object... args) {
125                return master.shadowInvoke(key, args);
126        }
127
128        public Object shadowGet(KP key) {
129                return master.shadowGet(key);
130        }
131
132        public Object shadowGet(KP key, Object defaultValue) {
133                return master.shadowGet(key, defaultValue);
134        }
135
136        public <T> T shadowGet(KP key, Class<T> type) {
137                return master.shadowGet(key, type);
138        }
139
140        public <T> T shadowGet(KP key, Class<T> type, T defaultValue) {
141                return master.shadowGet(key, type, defaultValue);
142        }
143        
144
145        public Object shadowGet(KP key, long timeout, TimeUnit unit) {
146                return master.shadowGet(key, timeout, unit);
147        }
148
149        public Object shadowGet(KP key, Object defaultValue, long timeout, TimeUnit unit) {
150                return master.shadowGet(key, defaultValue, timeout, unit);
151        }
152
153        public <T> T shadowGet(KP key, Class<T> type, long timeout, TimeUnit unit) {
154                return master.shadowGet(key, type, timeout, unit);
155        }
156
157        public <T> T shadowGet(KP key, Class<T> type, T defaultValue, long timeout, TimeUnit unit) {
158                return master.shadowGet(key, type, defaultValue, timeout, unit);
159        }
160        
161        @Override
162        public PropertySet<KP> createVersion() {
163                throw new UnsupportedOperationException();
164        }
165        
166}