1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.github.jinahya.simple.file.back;
19
20
21 import com.github.jinahya.simple.file.back.FileContext.PropertyKey;
22 import java.util.EnumMap;
23 import java.util.Map;
24 import java.util.Optional;
25
26
27
28
29
30
31
32 public abstract class AbstractFileContext implements FileContext {
33
34
35 @Override
36 public Optional<Object> property(final PropertyKey key) {
37
38 if (key == null) {
39 throw new NullPointerException("null key");
40 }
41
42 return Optional.ofNullable(properties().get(key));
43 }
44
45
46 @Override
47 public Optional<Object> property(final PropertyKey key,
48 final Object value) {
49
50 if (key == null) {
51 throw new NullPointerException("null key");
52 }
53
54 if (value == null) {
55 return Optional.ofNullable(properties().remove(key));
56 }
57
58 return Optional.ofNullable(properties().put(key, value));
59 }
60
61
62
63
64
65
66
67 protected Map<PropertyKey, Object> properties() {
68
69 if (properties == null) {
70 properties = new EnumMap<>(PropertyKey.class);
71 }
72
73 return properties;
74 }
75
76
77 private Map<PropertyKey, Object> properties;
78
79
80 }
81