Skip to content

Package: EntityDescriptor

EntityDescriptor

nameinstructionbranchcomplexitylinemethod
EntityDescriptor()
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%
EntityDescriptor(URI)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
addAttributeContext(Field, URI)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
addAttributeDescriptor(Field, Descriptor)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createDescriptor(FieldSpecification, URI)
M: 0 C: 32
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
equals(Object)
M: 8 C: 27
77%
M: 4 C: 6
60%
M: 3 C: 3
50%
M: 0 C: 5
100%
M: 0 C: 1
100%
getAttributeDescriptor(FieldSpecification)
M: 0 C: 21
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getAttributeDescriptors()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getContextsInternal(Set, Set)
M: 44 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
getFieldDescriptor(Field)
M: 0 C: 25
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
hashCode()
M: 1 C: 17
94%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
lambda$setLanguage$0(String, Descriptor)
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%
setAttributeLanguage(Field, String)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
setLanguage(String)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.model.descriptors;
16:
17: import cz.cvut.kbss.jopa.model.metamodel.Attribute;
18: import cz.cvut.kbss.jopa.model.metamodel.Attribute.PersistentAttributeType;
19: import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
20: import cz.cvut.kbss.jopa.utils.ErrorUtils;
21:
22: import java.lang.reflect.Field;
23: import java.net.URI;
24: import java.util.*;
25: import java.util.Map.Entry;
26:
27: /**
28: * Describes an entity.
29: * <p>
30: * Each attribute has a descriptor associated with it.
31: */
32: public class EntityDescriptor extends Descriptor {
33:
34: private final Map<Field, Descriptor> fieldDescriptors;
35:
36: public EntityDescriptor() {
37: this.fieldDescriptors = new HashMap<>();
38: }
39:
40: public EntityDescriptor(URI context) {
41: super(context);
42: this.fieldDescriptors = new HashMap<>();
43: }
44:
45: @Override
46: public void addAttributeDescriptor(Field attribute, Descriptor descriptor) {
47: Objects.requireNonNull(attribute, ErrorUtils.getNPXMessageSupplier("attribute"));
48: Objects.requireNonNull(descriptor, ErrorUtils.getNPXMessageSupplier("descriptor"));
49:
50: fieldDescriptors.put(attribute, descriptor);
51: }
52:
53: @Override
54: public void addAttributeContext(Field attribute, URI context) {
55: Objects.requireNonNull(attribute, ErrorUtils.getNPXMessageSupplier("attribute"));
56:
57: fieldDescriptors.put(attribute, new FieldDescriptor(context, attribute));
58: }
59:
60: @Override
61: public void setLanguage(String languageTag) {
62: super.setLanguage(languageTag);
63: fieldDescriptors.values().forEach(d -> d.setLanguage(languageTag));
64: }
65:
66: @Override
67: public void setAttributeLanguage(Field attribute, String languageTag) {
68: Objects.requireNonNull(attribute);
69:
70: fieldDescriptors.putIfAbsent(attribute, new FieldDescriptor(null, attribute));
71: fieldDescriptors.get(attribute).setLanguage(languageTag);
72: }
73:
74: @Override
75: public Descriptor getAttributeDescriptor(FieldSpecification<?, ?> attribute) {
76: Descriptor d = getFieldDescriptor(attribute.getJavaField());
77:• if (d == null) {
78: d = createDescriptor(attribute, context);
79:• if (hasLanguage()) {
80: d.setLanguage(getLanguage());
81: }
82: }
83: return d;
84: }
85:
86: @Override
87: public Collection<Descriptor> getAttributeDescriptors() {
88: return Collections.unmodifiableCollection(fieldDescriptors.values());
89: }
90:
91: private Descriptor getFieldDescriptor(Field field) {
92:• for (Entry<Field, Descriptor> e : fieldDescriptors.entrySet()) {
93:• if (e.getKey().equals(field)) {
94: return e.getValue();
95: }
96: }
97: return null;
98: }
99:
100: private static Descriptor createDescriptor(FieldSpecification<?, ?> att, URI context) {
101:• if (att instanceof Attribute) {
102: final Attribute<?, ?> attSpec = (Attribute<?, ?>) att;
103:• if (attSpec.getPersistentAttributeType() == PersistentAttributeType.OBJECT) {
104:• if (attSpec.isCollection()) {
105: return new ObjectPropertyCollectionDescriptor(context, att.getJavaField());
106: } else {
107: return new EntityDescriptor(context);
108: }
109: }
110: }
111: return new FieldDescriptor(context, att.getJavaField());
112: }
113:
114: @Override
115: protected Set<URI> getContextsInternal(Set<URI> contexts, Set<Descriptor> visited) {
116:• if (visited.contains(this)) {
117: return contexts;
118: }
119:• if (context == null) {
120: return null;
121: }
122: contexts.add(context);
123: visited.add(this);
124:• for (Descriptor fd : fieldDescriptors.values()) {
125: contexts = fd.getContextsInternal(contexts, visited);
126:• if (contexts == null) {
127: return null;
128: }
129: }
130: return contexts;
131: }
132:
133: @Override
134: public boolean equals(Object o) {
135:• if (this == o) return true;
136:• if (!(o instanceof EntityDescriptor)) return false;
137:• if (!super.equals(o)) return false;
138:
139: EntityDescriptor that = (EntityDescriptor) o;
140:
141:• return fieldDescriptors != null ? fieldDescriptors.equals(that.fieldDescriptors) :
142: that.fieldDescriptors == null;
143: }
144:
145: @Override
146: public int hashCode() {
147: int result = super.hashCode();
148:• result = 31 * result + (fieldDescriptors != null ? fieldDescriptors.hashCode() : 0);
149: return result;
150: }
151: }