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