1 | package com.hammurapi.common.concurrent; |
2 | |
3 | import java.util.Set; |
4 | import java.util.concurrent.Callable; |
5 | import java.util.concurrent.Future; |
6 | import java.util.concurrent.TimeUnit; |
7 | |
8 | import com.hammurapi.common.Context; |
9 | |
10 | public abstract class AbstractSubSet<KP> implements PropertySet<KP> { |
11 | |
12 | private PropertySet<KP> master; |
13 | |
14 | private KP prefix; |
15 | |
16 | protected abstract KP buildPath(KP prefix, KP key); |
17 | |
18 | protected AbstractSubSet(PropertySet<KP> master, KP prefix) { |
19 | super(); |
20 | this.master = master; |
21 | this.prefix = prefix; |
22 | } |
23 | |
24 | public void clear() { |
25 | master.subset(prefix).clear(); |
26 | } |
27 | |
28 | public Object get(KP key) { |
29 | return master.get(buildPath(prefix, key)); |
30 | } |
31 | |
32 | public Object get(KP key, Object defaultValue) { |
33 | return master.get(buildPath(prefix, key), defaultValue); |
34 | } |
35 | |
36 | public <T> T get(KP key, Class<T> type) { |
37 | return master.get(buildPath(prefix, key), type); |
38 | } |
39 | |
40 | public <T> T get(KP key, Class<T> type, T defaultValue) { |
41 | return master.get(buildPath(prefix, key), type, defaultValue); |
42 | } |
43 | |
44 | public void cook(KP key, Callable<?> callable) { |
45 | master.cook(buildPath(prefix, key), callable); |
46 | } |
47 | |
48 | public void cook(KP key, Callable<?> callable, long delay, TimeUnit timeUnit) { |
49 | master.cook(buildPath(prefix, key), callable, delay, timeUnit); |
50 | } |
51 | |
52 | public void cooking(KP key, Future<?> future) { |
53 | master.cooking(buildPath(prefix, key), future); |
54 | } |
55 | |
56 | public void cancel(KP key) { |
57 | master.cancel(buildPath(prefix, key)); |
58 | } |
59 | |
60 | public void cancelAll() { |
61 | master.subset(prefix).cancelAll(); |
62 | } |
63 | |
64 | public <T> T getAdapter(Class<T> targetType, Context context) { |
65 | return master.subset(prefix).getAdapter(targetType, context); |
66 | } |
67 | |
68 | public Set<KP> keySet() { |
69 | return master.subset(prefix).keySet(); |
70 | } |
71 | |
72 | public PropertySet<KP> subset(KP prefix) { |
73 | return master.subset(buildPath(this.prefix, prefix)); |
74 | } |
75 | |
76 | public void remove(KP key) { |
77 | master.remove(buildPath(prefix, key)); |
78 | } |
79 | |
80 | public void mount(KP prefix, PropertySet<KP> source) { |
81 | master.mount(buildPath(this.prefix, prefix), source); |
82 | } |
83 | |
84 | public void unmount(KP prefix) { |
85 | master.unmount(buildPath(this.prefix, prefix)); |
86 | } |
87 | |
88 | public void setAll(PropertySet<KP> source) { |
89 | master.subset(prefix).setAll(source); |
90 | } |
91 | |
92 | public void set(KP key, Object value) { |
93 | master.set(buildPath(prefix, key), value); |
94 | } |
95 | |
96 | public void setInvocable(KP key, Invocable<PropertySet<KP>, ?, KP> invocable) { |
97 | master.setInvocable(buildPath(prefix, key), invocable); |
98 | } |
99 | |
100 | public void lazy(KP key, Callable<?> callable) { |
101 | master.lazy(buildPath(prefix, key), callable); |
102 | } |
103 | |
104 | public Object invoke(KP key, Object... args) { |
105 | return master.invoke(buildPath(prefix, key), args); |
106 | } |
107 | |
108 | public Object shadowInvoke(KP key, Object... args) { |
109 | return master.shadowInvoke(key, args); |
110 | } |
111 | |
112 | public Object shadowGet(KP key) { |
113 | return master.shadowGet(key); |
114 | } |
115 | |
116 | public Object shadowGet(KP key, Object defaultValue) { |
117 | return master.shadowGet(key, defaultValue); |
118 | } |
119 | |
120 | public <T> T shadowGet(KP key, Class<T> type) { |
121 | return master.shadowGet(key, type); |
122 | } |
123 | |
124 | public <T> T shadowGet(KP key, Class<T> type, T defaultValue) { |
125 | return master.shadowGet(key, type, defaultValue); |
126 | } |
127 | |
128 | |
129 | |
130 | } |