Package: AxiomDescriptor
AxiomDescriptor
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AxiomDescriptor(NamedResource) |
|
|
|
|
|
||||||||||||||||||||
addAssertion(Assertion) |
|
|
|
|
|
||||||||||||||||||||
addAssertionContext(Assertion, URI) |
|
|
|
|
|
||||||||||||||||||||
addSubjectContext(URI) |
|
|
|
|
|
||||||||||||||||||||
containsAssertion(Assertion) |
|
|
|
|
|
||||||||||||||||||||
equals(Object) |
|
|
|
|
|
||||||||||||||||||||
getAssertionContexts(Assertion) |
|
|
|
|
|
||||||||||||||||||||
getAssertions() |
|
|
|
|
|
||||||||||||||||||||
getSubjectContexts() |
|
|
|
|
|
||||||||||||||||||||
hashCode() |
|
|
|
|
|
||||||||||||||||||||
lambda$addAssertionContext$0(Assertion) |
|
|
|
|
|
||||||||||||||||||||
toString() |
|
|
|
|
|
Coverage
1: /*
2: * JOPA
3: * Copyright (C) 2023 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.descriptor;
19:
20: import cz.cvut.kbss.ontodriver.model.Assertion;
21: import cz.cvut.kbss.ontodriver.model.NamedResource;
22:
23: import java.net.URI;
24: import java.util.*;
25:
26: /**
27: * This descriptor specifies subject and properties of axioms to search for in the ontology.
28: * <p>
29: * Additionally, it can specify context URIs for both the descriptor and individual properties so that the underlying
30: * driver knows where to look for the corresponding axioms.
31: */
32: public class AxiomDescriptor extends AbstractAxiomDescriptor {
33:
34: private final Set<URI> subjectContexts = new HashSet<>(4);
35: private final Map<Assertion, Set<URI>> assertionContexts;
36:
37: public AxiomDescriptor(NamedResource subject) {
38: super(subject);
39: this.assertionContexts = new HashMap<>();
40: }
41:
42: /**
43: * Adds subject context.
44: * <p>
45: * The context can be {@code null}, indicating the default context.
46: *
47: * @param context The context to use for subject
48: * @return This instance
49: */
50: public AxiomDescriptor addSubjectContext(URI context) {
51:• if (context == null) {
52: subjectContexts.clear();
53: } else {
54: subjectContexts.add(context);
55: }
56: return this;
57: }
58:
59: /**
60: * Adds the specified assertion to this descriptor.
61: *
62: * @param assertion The assertion to add
63: * @throws NullPointerException When {@code assertion} is {@code null}
64: */
65: public void addAssertion(Assertion assertion) {
66: Objects.requireNonNull(assertion);
67: assertionContexts.put(assertion, null);
68: }
69:
70: /**
71: * Sets context for the specified assertion.
72: * <p>
73: * Note that the assertion has to be already present in this descriptor.
74: *
75: * @param assertion The property to set context for
76: * @param context Context URI. Use {@code null} to indicate the default context
77: * @return This instance
78: * @throws IllegalArgumentException If there is no such assertion in this descriptor
79: * @throws NullPointerException When {@code assertion} is {@code null}
80: */
81: public AxiomDescriptor addAssertionContext(Assertion assertion, URI context) {
82: Objects.requireNonNull(assertion);
83:• if (!assertionContexts.containsKey(assertion)) {
84: throw new IllegalArgumentException("Assertion " + assertion + " is not present in this descriptor.");
85: }
86: final Set<URI> contexts = assertionContexts.computeIfAbsent(assertion, a -> new HashSet<>());
87:• if (context == null) {
88: contexts.clear();
89: } else {
90: contexts.add(context);
91: }
92: return this;
93: }
94:
95: /**
96: * Gets unmodifiable view of the properties in this descriptor.
97: *
98: * @return Set of assertions in this descriptor
99: */
100: public Set<Assertion> getAssertions() {
101: return Collections.unmodifiableSet(assertionContexts.keySet());
102: }
103:
104: /**
105: * Checks whether this descriptor contains the specified assertion.
106: *
107: * @param assertion The assertion to check
108: * @return True if the assertion is already present in this descriptor, false otherwise
109: */
110: public boolean containsAssertion(Assertion assertion) {
111: return assertionContexts.containsKey(assertion);
112: }
113:
114: @Override
115: public Set<URI> getSubjectContexts() {
116: return Collections.unmodifiableSet(subjectContexts);
117: }
118:
119: @Override
120: public Set<URI> getAssertionContexts(Assertion assertion) {
121: Objects.requireNonNull(assertion);
122:• if (!assertionContexts.containsKey(assertion) || assertionContexts.get(assertion) == null) {
123: return getSubjectContexts();
124: }
125: return Collections.unmodifiableSet(assertionContexts.get(assertion));
126: }
127:
128: @Override
129: public boolean equals(Object o) {
130:• if (this == o) {
131: return true;
132: }
133:• if (!(o instanceof AxiomDescriptor)) {
134: return false;
135: }
136:• if (!super.equals(o)) {
137: return false;
138: }
139: AxiomDescriptor that = (AxiomDescriptor) o;
140:• return subjectContexts.equals(that.subjectContexts) && assertionContexts.equals(that.assertionContexts);
141: }
142:
143: @Override
144: public int hashCode() {
145: return Objects.hash(super.hashCode(), subjectContexts, assertionContexts);
146: }
147:
148: @Override
149: public String toString() {
150: final StringBuilder sb = new StringBuilder();
151: sb.append("[").append(getSubject());
152: sb.append(" - ").append(subjectContexts);
153:• if (!assertionContexts.isEmpty()) {
154: sb.append(", properties: ").append(assertionContexts);
155: }
156: sb.append("]");
157: return sb.toString();
158: }
159: }