/
CapReq.java
79 lines (66 loc) · 2.15 KB
/
CapReq.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package aQute.bnd.osgi.resource;
import static java.util.Objects.requireNonNull;
import java.util.Map;
import java.util.Objects;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import org.osgi.resource.Resource;
import aQute.bnd.unmodifiable.Maps;
abstract class CapReq {
private final String namespace;
private final Resource resource;
private final Map<String, String> directives;
private final Map<String, Object> attributes;
private transient int hashCode = 0;
CapReq(String namespace, Resource resource, Map<String, String> directives, Map<String, Object> attributes) {
this.namespace = requireNonNull(namespace);
this.resource = resource;
this.directives = Maps.copyOf(directives);
this.attributes = new DeferredValueMap<>(Maps.copyOf(attributes));
}
public String getNamespace() {
return namespace;
}
public Map<String, String> getDirectives() {
return directives;
}
public Map<String, Object> getAttributes() {
return attributes;
}
public Resource getResource() {
return resource;
}
@Override
public int hashCode() {
if (hashCode != 0) {
return hashCode;
}
return hashCode = Objects.hash(attributes, directives, Boolean.valueOf(this instanceof Capability), namespace,
resource);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (this instanceof Capability) {
if (!(obj instanceof Capability))
return false;
Capability other = (Capability) obj;
return Objects.equals(namespace, other.getNamespace()) && Objects.equals(attributes, other.getAttributes())
&& Objects.equals(directives, other.getDirectives()) && Objects.equals(resource, other.getResource());
} else {
if (!(obj instanceof Requirement))
return false;
Requirement other = (Requirement) obj;
return Objects.equals(namespace, other.getNamespace()) && Objects.equals(attributes, other.getAttributes())
&& Objects.equals(directives, other.getDirectives()) && Objects.equals(resource, other.getResource());
}
}
protected void toString(StringBuilder sb) {
sb.append('[')
.append(namespace)
.append(']')
.append(attributes)
.append(directives);
}
}