1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.collections4.properties;
19
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23 import java.io.Reader;
24 import java.io.Writer;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.Enumeration;
28 import java.util.InvalidPropertiesFormatException;
29 import java.util.Map;
30 import java.util.Map.Entry;
31 import java.util.Objects;
32 import java.util.Properties;
33 import java.util.Set;
34 import java.util.function.BiConsumer;
35 import java.util.function.BiFunction;
36 import java.util.function.Function;
37
38
39
40
41
42
43
44 public class PropertiesFactory extends AbstractPropertiesFactory<Properties> {
45
46 private static final class EmptyProperties extends Properties {
47
48 private static final long serialVersionUID = 1L;
49
50 @Override
51 public synchronized void clear() {
52
53 }
54
55 @Override
56 public synchronized Object compute(final Object key,
57 final BiFunction<? super Object, ? super Object, ? extends Object> remappingFunction) {
58 Objects.requireNonNull(key);
59 throw new UnsupportedOperationException();
60 }
61
62 @Override
63 public synchronized Object computeIfAbsent(final Object key,
64 final Function<? super Object, ? extends Object> mappingFunction) {
65 Objects.requireNonNull(key);
66 throw new UnsupportedOperationException();
67 }
68
69 @Override
70 public synchronized Object computeIfPresent(final Object key,
71 final BiFunction<? super Object, ? super Object, ? extends Object> remappingFunction) {
72 Objects.requireNonNull(key);
73 throw new UnsupportedOperationException();
74 }
75
76 @Override
77 public synchronized boolean contains(final Object value) {
78 return false;
79 }
80
81 @Override
82 public synchronized boolean containsKey(final Object key) {
83 return false;
84 }
85
86 @Override
87 public boolean containsValue(final Object value) {
88 return false;
89 }
90
91 @Override
92 public synchronized Enumeration<Object> elements() {
93 return Collections.emptyEnumeration();
94 }
95
96 @Override
97 public Set<Entry<Object, Object>> entrySet() {
98 return Collections.emptySet();
99 }
100
101 @Override
102 public synchronized boolean equals(final Object o) {
103 return o instanceof Properties && ((Properties) o).isEmpty();
104 }
105
106 @Override
107 public synchronized void forEach(final BiConsumer<? super Object, ? super Object> action) {
108 Objects.requireNonNull(action);
109 }
110
111 @Override
112 public synchronized Object get(final Object key) {
113 return null;
114 }
115
116 @Override
117 public synchronized Object getOrDefault(final Object key, final Object defaultValue) {
118 return defaultValue;
119 }
120
121 @Override
122 public String getProperty(final String key) {
123 return null;
124 }
125
126 @Override
127 public String getProperty(final String key, final String defaultValue) {
128 return defaultValue;
129 }
130
131 @Override
132 public synchronized int hashCode() {
133 return 0;
134 }
135
136 @Override
137 public synchronized boolean isEmpty() {
138 return true;
139 }
140
141 @Override
142 public synchronized Enumeration<Object> keys() {
143 return Collections.emptyEnumeration();
144 }
145
146 @Override
147 public Set<Object> keySet() {
148 return Collections.emptySet();
149 }
150
151
152
153
154
155 @SuppressWarnings("resource")
156 @Override
157 public synchronized void load(final InputStream inStream) throws IOException {
158 Objects.requireNonNull(inStream);
159 throw new UnsupportedOperationException();
160 }
161
162
163
164
165
166 @SuppressWarnings("resource")
167 @Override
168 public synchronized void load(final Reader reader) throws IOException {
169 Objects.requireNonNull(reader);
170 throw new UnsupportedOperationException();
171 }
172
173
174
175
176
177 @SuppressWarnings("resource")
178 @Override
179 public synchronized void loadFromXML(final InputStream in)
180 throws IOException, InvalidPropertiesFormatException {
181 Objects.requireNonNull(in);
182 throw new UnsupportedOperationException();
183 }
184
185 @Override
186 public synchronized Object merge(final Object key, final Object value,
187 final BiFunction<? super Object, ? super Object, ? extends Object> remappingFunction) {
188 Objects.requireNonNull(key);
189 Objects.requireNonNull(value);
190 throw new UnsupportedOperationException();
191 }
192
193 @Override
194 public Enumeration<?> propertyNames() {
195 return Collections.emptyEnumeration();
196 }
197
198 @Override
199 public synchronized Object put(final Object key, final Object value) {
200 Objects.requireNonNull(key);
201 Objects.requireNonNull(value);
202 throw new UnsupportedOperationException();
203 }
204
205 @Override
206 public synchronized void putAll(final Map<? extends Object, ? extends Object> t) {
207 Objects.requireNonNull(t);
208 throw new UnsupportedOperationException();
209 }
210
211 @Override
212 public synchronized Object putIfAbsent(final Object key, final Object value) {
213 Objects.requireNonNull(key);
214 Objects.requireNonNull(value);
215 throw new UnsupportedOperationException();
216 }
217
218 @Override
219 protected void rehash() {
220
221 }
222
223 @Override
224 public synchronized Object remove(final Object key) {
225 Objects.requireNonNull(key);
226 throw new UnsupportedOperationException();
227 }
228
229 @Override
230 public synchronized boolean remove(final Object key, final Object value) {
231 Objects.requireNonNull(key);
232 Objects.requireNonNull(value);
233 throw new UnsupportedOperationException();
234 }
235
236 @Override
237 public synchronized Object replace(final Object key, final Object value) {
238 Objects.requireNonNull(key);
239 Objects.requireNonNull(value);
240 throw new UnsupportedOperationException();
241 }
242
243 @Override
244 public synchronized boolean replace(final Object key, final Object oldValue, final Object newValue) {
245 Objects.requireNonNull(key);
246 Objects.requireNonNull(oldValue);
247 Objects.requireNonNull(newValue);
248 throw new UnsupportedOperationException();
249 }
250
251 @Override
252 public synchronized void replaceAll(
253 final BiFunction<? super Object, ? super Object, ? extends Object> function) {
254 Objects.requireNonNull(function);
255 throw new UnsupportedOperationException();
256 }
257
258 @SuppressWarnings("deprecation")
259 @Override
260 public void save(final OutputStream out, final String comments) {
261
262 super.save(out, comments);
263 }
264
265 @Override
266 public synchronized Object setProperty(final String key, final String value) {
267 Objects.requireNonNull(key);
268 Objects.requireNonNull(value);
269 throw new UnsupportedOperationException();
270 }
271
272 @Override
273 public synchronized int size() {
274 return 0;
275 }
276
277 @Override
278 public void store(final OutputStream out, final String comments) throws IOException {
279
280 super.store(out, comments);
281 }
282
283 @Override
284 public void store(final Writer writer, final String comments) throws IOException {
285
286 super.store(writer, comments);
287 }
288
289 @Override
290 public void storeToXML(final OutputStream os, final String comment) throws IOException {
291
292 super.storeToXML(os, comment);
293 }
294
295 @Override
296 public void storeToXML(final OutputStream os, final String comment, final String encoding) throws IOException {
297
298 super.storeToXML(os, comment, encoding);
299 }
300
301 @Override
302 public Set<String> stringPropertyNames() {
303 return Collections.emptySet();
304 }
305
306 @Override
307 public synchronized String toString() {
308
309 return super.toString();
310 }
311
312 @Override
313 public Collection<Object> values() {
314 return Collections.emptyList();
315 }
316
317 }
318
319
320
321
322
323
324 public static final Properties EMPTY_PROPERTIES = new EmptyProperties();
325
326
327
328
329 public static final PropertiesFactory INSTANCE = new PropertiesFactory();
330
331
332
333
334 private PropertiesFactory() {
335
336 }
337
338
339
340
341
342
343 @Override
344 protected Properties createProperties() {
345 return new Properties();
346 }
347
348 }