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: 42
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 8
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: * <p>
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: * <p>
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.model.metamodel.PropertiesSpecification;
21: import cz.cvut.kbss.jopa.model.metamodel.TypesSpecification;
22: import cz.cvut.kbss.jopa.utils.ErrorUtils;
23:
24: import java.lang.reflect.Field;
25: import java.net.URI;
26: import java.util.*;
27: import java.util.Map.Entry;
28:
29: /**
30: * Describes an entity.
31: * <p>
32: * Each attribute has a descriptor associated with it.
33: */
34: public class EntityDescriptor extends Descriptor {
35:
36: private final Map<Field, Descriptor> fieldDescriptors;
37:
38: public EntityDescriptor() {
39: this.fieldDescriptors = new HashMap<>();
40: }
41:
42: public EntityDescriptor(URI context) {
43: super(context);
44: this.fieldDescriptors = new HashMap<>();
45: }
46:
47: @Override
48: public void addAttributeDescriptor(Field attribute, Descriptor descriptor) {
49: Objects.requireNonNull(attribute, ErrorUtils.getNPXMessageSupplier("attribute"));
50: Objects.requireNonNull(descriptor, ErrorUtils.getNPXMessageSupplier("descriptor"));
51:
52: fieldDescriptors.put(attribute, descriptor);
53: }
54:
55: @Override
56: public void addAttributeContext(Field attribute, URI context) {
57: Objects.requireNonNull(attribute, ErrorUtils.getNPXMessageSupplier("attribute"));
58:
59: fieldDescriptors.put(attribute, new FieldDescriptor(context, attribute));
60: }
61:
62: @Override
63: public void setLanguage(String languageTag) {
64: super.setLanguage(languageTag);
65: fieldDescriptors.values().forEach(d -> d.setLanguage(languageTag));
66: }
67:
68: @Override
69: public void setAttributeLanguage(Field attribute, String languageTag) {
70: Objects.requireNonNull(attribute);
71:
72: fieldDescriptors.putIfAbsent(attribute, new FieldDescriptor(null, attribute));
73: fieldDescriptors.get(attribute).setLanguage(languageTag);
74: }
75:
76: @Override
77: public Descriptor getAttributeDescriptor(FieldSpecification<?, ?> attribute) {
78: Descriptor d = getFieldDescriptor(attribute.getJavaField());
79:• if (d == null) {
80: d = createDescriptor(attribute, context);
81:• if (hasLanguage()) {
82: d.setLanguage(getLanguage());
83: }
84: }
85: return d;
86: }
87:
88: @Override
89: public Collection<Descriptor> getAttributeDescriptors() {
90: return Collections.unmodifiableCollection(fieldDescriptors.values());
91: }
92:
93: private Descriptor getFieldDescriptor(Field field) {
94:• for (Entry<Field, Descriptor> e : fieldDescriptors.entrySet()) {
95:• if (e.getKey().equals(field)) {
96: return e.getValue();
97: }
98: }
99: return null;
100: }
101:
102: private static Descriptor createDescriptor(FieldSpecification<?, ?> att, URI context) {
103:• if ((att instanceof TypesSpecification) || (att instanceof PropertiesSpecification)) {
104: return new FieldDescriptor(context, att.getJavaField());
105: }
106: final Attribute<?, ?> attSpec = (Attribute<?, ?>) att;
107:• if (attSpec.getPersistentAttributeType() == PersistentAttributeType.OBJECT) {
108:• if (attSpec.isCollection()) {
109: return new ObjectPropertyCollectionDescriptor(context, att.getJavaField());
110: } else {
111: return new EntityDescriptor(context);
112: }
113: }
114: return new FieldDescriptor(context, att.getJavaField());
115: }
116:
117: @Override
118: protected Set<URI> getContextsInternal(Set<URI> contexts, Set<Descriptor> visited) {
119:• if (visited.contains(this)) {
120: return contexts;
121: }
122:• if (context == null) {
123: return null;
124: }
125: contexts.add(context);
126: visited.add(this);
127:• for (Descriptor fd : fieldDescriptors.values()) {
128: contexts = fd.getContextsInternal(contexts, visited);
129:• if (contexts == null) {
130: return null;
131: }
132: }
133: return contexts;
134: }
135:
136: @Override
137: public boolean equals(Object o) {
138:• if (this == o) return true;
139:• if (!(o instanceof EntityDescriptor)) return false;
140:• if (!super.equals(o)) return false;
141:
142: EntityDescriptor that = (EntityDescriptor) o;
143:
144:• return fieldDescriptors != null ? fieldDescriptors.equals(that.fieldDescriptors) :
145: that.fieldDescriptors == null;
146: }
147:
148: @Override
149: public int hashCode() {
150: int result = super.hashCode();
151:• result = 31 * result + (fieldDescriptors != null ? fieldDescriptors.hashCode() : 0);
152: return result;
153: }
154: }