1
2
3
4
5
6 package gov.nist.secauto.metaschema.core.model;
7
8 import gov.nist.secauto.metaschema.core.MetaschemaConstants;
9 import gov.nist.secauto.metaschema.core.util.CollectionUtil;
10
11 import java.util.Map;
12 import java.util.Objects;
13 import java.util.Set;
14
15 import edu.umd.cs.findbugs.annotations.NonNull;
16
17
18
19
20
21 @FunctionalInterface
22 public interface IAttributable {
23
24
25
26 @NonNull
27 String DEFAULT_PROPERY_NAMESPACE = MetaschemaConstants.METASCHEMA_NAMESPACE;
28
29
30
31
32
33
34 @NonNull
35 Map<Key, Set<String>> getProperties();
36
37
38
39
40
41
42
43
44 default boolean hasProperty(@NonNull Key key) {
45 return getProperties().containsKey(key);
46 }
47
48
49
50
51
52
53
54
55 @NonNull
56 default Set<String> getPropertyValues(@NonNull Key key) {
57 Set<String> retval = getProperties().get(key);
58 if (retval == null) {
59 retval = CollectionUtil.emptySet();
60 }
61 return retval;
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75 default boolean hasPropertyValue(@NonNull Key key, @NonNull String value) {
76 Set<String> values = getProperties().get(key);
77 return values != null && values.contains(value);
78 }
79
80
81
82
83
84
85
86
87
88
89 @NonNull
90 static Key key(@NonNull String name, @NonNull String namespace) {
91 return new Key(name, namespace);
92 }
93
94
95
96
97
98
99
100
101
102 @NonNull
103 static Key key(@NonNull String name) {
104 return new Key(name);
105 }
106
107
108
109
110
111
112 final class Key {
113 @NonNull
114 private final String name;
115 @NonNull
116 private final String namespace;
117
118 private Key(@NonNull String name) {
119 this(name, DEFAULT_PROPERY_NAMESPACE);
120 }
121
122 private Key(@NonNull String name, @NonNull String namespace) {
123 this.name = name;
124 this.namespace = namespace;
125 }
126
127
128
129
130
131
132 @NonNull
133 public String getName() {
134 return name;
135 }
136
137
138
139
140
141
142 @NonNull
143 public String getNamespace() {
144 return namespace;
145 }
146
147 @Override
148 public int hashCode() {
149 return Objects.hash(name, namespace);
150 }
151
152 @Override
153 public boolean equals(Object obj) {
154 if (this == obj) {
155 return true;
156 }
157 if (!(obj instanceof Key)) {
158 return false;
159 }
160 Key other = (Key) obj;
161 return Objects.equals(name, other.name) && Objects.equals(namespace, other.namespace);
162 }
163 }
164 }