Skip to content

Package: AbstractDescriptor

AbstractDescriptor

nameinstructionbranchcomplexitylinemethod
AbstractDescriptor()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
AbstractDescriptor(URI)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
AbstractDescriptor(URI, boolean)
M: 0 C: 19
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
AbstractDescriptor(boolean)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
addContext(URI)
M: 0 C: 13
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
anyLanguage()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
areAssertionsInSubjectContext()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 6 C: 37
86%
M: 3 C: 9
75%
M: 3 C: 4
57%
M: 3 C: 7
70%
M: 0 C: 1
100%
getContexts()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getLanguage()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getSingleAttributeContext(FieldSpecification)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getSingleContext()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasLanguage()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hashCode()
M: 1 C: 40
98%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 5
100%
M: 0 C: 1
100%
retrieveSingleContext(Set)
M: 0 C: 26
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
setLanguage(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
toString()
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /**
2: * Copyright (C) 2020 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.model.descriptors;
14:
15: import cz.cvut.kbss.jopa.exceptions.AmbiguousContextException;
16: import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
17:
18: import java.net.URI;
19: import java.util.*;
20:
21: /**
22: * Defines base descriptor, which is used to specify context information for entities and their fields.
23: * <p>
24: * The descriptor hierarchy is a classical <b>Composite</b> pattern.
25: */
26: public abstract class AbstractDescriptor implements Descriptor {
27:
28: protected final Set<URI> contexts = new HashSet<>(4);
29:
30: protected final boolean assertionsInSubjectContext;
31:
32: private String language;
33: private boolean hasLanguage;
34:
35: protected AbstractDescriptor() {
36: this(true);
37: }
38:
39: protected AbstractDescriptor(boolean assertionsInSubjectContext) {
40: this.assertionsInSubjectContext = assertionsInSubjectContext;
41: }
42:
43: protected AbstractDescriptor(URI context) {
44: this(context, true);
45: }
46:
47: protected AbstractDescriptor(URI context, boolean assertionsInSubjectContext) {
48:• if (context != null) {
49: contexts.add(context);
50: }
51: this.assertionsInSubjectContext = assertionsInSubjectContext;
52: }
53:
54: @Override
55: public Set<URI> getContexts() {
56: return Collections.unmodifiableSet(contexts);
57: }
58:
59: @Override
60: public Optional<URI> getSingleContext() {
61: return retrieveSingleContext(contexts);
62: }
63:
64: private Optional<URI> retrieveSingleContext(Set<URI> col) {
65:• if (col.size() > 1) {
66: throw new AmbiguousContextException("Expected at most one context, but got " + col);
67: }
68:• return col.isEmpty() ? Optional.empty() : Optional.of(col.iterator().next());
69: }
70:
71: @Override
72: public Descriptor addContext(URI context) {
73:• if (context == null) {
74: contexts.clear();
75: } else {
76: contexts.add(context);
77: }
78: return this;
79: }
80:
81: @Override
82: public Optional<URI> getSingleAttributeContext(FieldSpecification<?, ?> attribute) {
83: return retrieveSingleContext(getAttributeContexts(attribute));
84: }
85:
86: @Override
87: public String getLanguage() {
88: return language;
89: }
90:
91: @Override
92: public boolean hasLanguage() {
93: return hasLanguage;
94: }
95:
96: @Override
97: public Descriptor setLanguage(String languageTag) {
98: this.language = languageTag;
99: this.hasLanguage = true;
100: return this;
101: }
102:
103: @Override
104: public Descriptor anyLanguage() {
105: return setLanguage(null);
106: }
107:
108: @Override
109: public boolean areAssertionsInSubjectContext() {
110: return assertionsInSubjectContext;
111: }
112:
113: @Override
114: public boolean equals(Object o) {
115:• if (this == o) {
116: return true;
117: }
118:• if (!(o instanceof AbstractDescriptor)) {
119: return false;
120: }
121:
122: AbstractDescriptor that = (AbstractDescriptor) o;
123:
124:• if (hasLanguage != that.hasLanguage) {
125: return false;
126: }
127:• if (assertionsInSubjectContext != that.assertionsInSubjectContext) {
128: return false;
129: }
130:• return Objects.equals(contexts, that.contexts) && Objects.equals(language, that.language);
131: }
132:
133: @Override
134: public int hashCode() {
135: int result = contexts.hashCode();
136:• result = 31 * result + (language != null ? language.hashCode() : 0);
137:• result = 31 * result + (hasLanguage ? 1 : 0);
138:• result = 31 * result + (assertionsInSubjectContext ? 1 : 0);
139: return result;
140: }
141:
142: @Override
143: public String toString() {
144:• return contexts.isEmpty() ? "default_context" : contexts.toString();
145: }
146: }