Skip to content

Package: EntityTypeImpl

EntityTypeImpl

nameinstructionbranchcomplexitylinemethod
EntityTypeImpl(String, Class, IRI)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
addDeclaredAttribute(String, Attribute)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
addDirectTypes(TypesSpecification)
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%
addOtherProperties(PropertiesSpecification)
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%
getAttribute(String)
M: 0 C: 27
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getAttributes()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getBindableJavaType()
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%
getBindableType()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getCollection(String)
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%
getCollection(String, Class)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getDeclaredAttribute(String)
M: 0 C: 27
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getDeclaredAttributes()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDeclaredCollection(String)
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%
getDeclaredCollection(String, Class)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getDeclaredList(String)
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%
getDeclaredList(String, Class)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getDeclaredMap(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDeclaredMap(String, Class, Class)
M: 21 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getDeclaredPluralAttributes()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getDeclaredSet(String)
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%
getDeclaredSet(String, Class)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getDeclaredSingularAttribute(String)
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%
getDeclaredSingularAttribute(String, Class)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getDeclaredSingularAttributes()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getDeclaredVersion(Class)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getFieldSpecification(String)
M: 0 C: 54
100%
M: 1 C: 11
92%
M: 1 C: 6
86%
M: 0 C: 9
100%
M: 0 C: 1
100%
getFieldSpecifications()
M: 0 C: 25
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getIRI()
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%
getIdClassAttributes()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getIdentifier()
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%
getJavaType()
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%
getList(String)
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%
getList(String, Class)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getMap(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMap(String, Class, Class)
M: 21 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getName()
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%
getPersistenceType()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPluralAttributes()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getProperties()
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%
getSet(String)
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%
getSet(String, Class)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getSingularAttribute(String)
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%
getSingularAttribute(String, Class)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getSingularAttributes()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getSupertype()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getTypes()
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%
getVersion(Class)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hasSingleIdAttribute()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hasVersionAttribute()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$getDeclaredPluralAttributes$0(Attribute)
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%
lambda$getDeclaredSingularAttributes$1(Attribute)
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%
lambda$getPluralAttributes$2(Attribute)
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%
lambda$getSingularAttributes$3(Attribute)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$getSingularAttributes$4(Attribute)
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%
setIdentifier(Identifier)
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%
toString()
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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;
16:
17: import cz.cvut.kbss.jopa.model.metamodel.*;
18:
19: import java.util.HashMap;
20: import java.util.HashSet;
21: import java.util.Map;
22: import java.util.Set;
23: import java.util.stream.Collectors;
24:
25: public class EntityTypeImpl<X> implements EntityType<X> {
26:
27: private final String name;
28:
29: private Class<X> javaType;
30:
31: private final Map<String, Attribute<? super X, ?>> attributeMap = new HashMap<>();
32:
33: private final Map<String, Attribute<X, ?>> declaredAttributeMap = new HashMap<>();
34:
35: private final IRI iri;
36:
37: private Identifier identifier;
38:
39: private TypesSpecification<X, ?> directTypes;
40:
41: private PropertiesSpecification<X, ?, ?, ?> properties;
42:
43: public EntityTypeImpl(String name, Class<X> javaType, final IRI iri) {
44: this.name = name;
45: this.javaType = javaType;
46: this.iri = iri;
47: }
48:
49: // void addAttribute(final String name, final Attribute<? super X, ?> a) {
50: // attributeMap.put(name, a);
51: // }
52:
53: public void addDirectTypes(TypesSpecification<X, ?> a) {
54: this.directTypes = a;
55: }
56:
57: public void addOtherProperties(PropertiesSpecification<X, ?, ?, ?> a) {
58: this.properties = a;
59: }
60:
61: public void addDeclaredAttribute(final String name, final Attribute<X, ?> a) {
62: declaredAttributeMap.put(name, a);
63: attributeMap.put(name, a);
64: }
65:
66: public void setIdentifier(final Identifier identifier) {
67: this.identifier = identifier;
68: }
69:
70: @Override
71: public String getName() {
72: return name;
73: }
74:
75: @Override
76: public <Y> SingularAttribute<X, Y> getDeclaredVersion(Class<Y> type) {
77: // TODO
78: throw new UnsupportedOperationException();
79: }
80:
81: @Override
82: public Set<SingularAttribute<? super X, ?>> getIdClassAttributes() {
83: // TODO
84: throw new UnsupportedOperationException();
85: }
86:
87: @Override
88: public IdentifiableType<? super X> getSupertype() {
89: // TODO
90: throw new UnsupportedOperationException();
91: }
92:
93: @Override
94: public <Y> SingularAttribute<? super X, Y> getVersion(Class<Y> type) {
95: // TODO
96: throw new UnsupportedOperationException();
97: }
98:
99: @Override
100: public boolean hasSingleIdAttribute() {
101: // TODO
102: return false;
103: }
104:
105: @Override
106: public boolean hasVersionAttribute() {
107: // TODO
108: return false;
109: }
110:
111: @Override
112: public Attribute<? super X, ?> getAttribute(String name) {
113:• if (attributeMap.containsKey(name)) {
114: return attributeMap.get(name);
115: }
116: throw new IllegalArgumentException("Attribute " + name + " is not present in type " + name);
117: }
118:
119: @Override
120: public Set<Attribute<? super X, ?>> getAttributes() {
121: return new HashSet<>(attributeMap.values());
122: }
123:
124: @Override
125: public <E> CollectionAttribute<? super X, E> getCollection(String name, Class<E> elementType) {
126: final CollectionAttribute<? super X, E> a = (CollectionAttribute<? super X, E>) getAttribute(name);
127:
128:• if (!a.getBindableJavaType().isAssignableFrom(elementType)) {
129: throw new IllegalArgumentException();
130: }
131:
132: return a;
133: }
134:
135: @Override
136: public CollectionAttribute<? super X, ?> getCollection(String name) {
137: return getCollection(name, Object.class);
138: }
139:
140: @Override
141: public Attribute<X, ?> getDeclaredAttribute(String name) {
142:• if (declaredAttributeMap.containsKey(name)) {
143: return declaredAttributeMap.get(name);
144: }
145: throw new IllegalArgumentException("Attribute " + name + " is not declared in type " + name);
146: }
147:
148: @Override
149: public Set<Attribute<X, ?>> getDeclaredAttributes() {
150: return new HashSet<>(declaredAttributeMap.values());
151: }
152:
153: @Override
154: public <E> CollectionAttribute<X, E> getDeclaredCollection(String name, Class<E> elementType) {
155: final CollectionAttribute<X, E> a = (CollectionAttribute<X, E>) getDeclaredAttribute(name);
156:
157:• if (!a.getBindableJavaType().isAssignableFrom(elementType)) {
158: throw new IllegalArgumentException();
159: }
160:
161: return a;
162: }
163:
164: @Override
165: public CollectionAttribute<X, ?> getDeclaredCollection(String name) {
166: return getDeclaredCollection(name, Object.class);
167: }
168:
169: @Override
170: public <E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType) {
171: final ListAttribute<X, E> a = (ListAttribute<X, E>) getDeclaredAttribute(name);
172:
173:• if (!a.getBindableJavaType().isAssignableFrom(elementType)) {
174: throw new IllegalArgumentException();
175: }
176:
177: return a;
178: }
179:
180: @Override
181: public ListAttribute<X, ?> getDeclaredList(String name) {
182: return getDeclaredList(name, Object.class);
183: }
184:
185: @Override
186: public <K, V> MapAttribute<X, K, V> getDeclaredMap(String name, Class<K> keyType,
187: Class<V> valueType) {
188: final MapAttribute<X, K, V> a = (MapAttribute<X, K, V>) getDeclaredAttribute(name);
189:
190:• if (!a.getKeyJavaType().isAssignableFrom(keyType)
191:• || !a.getBindableJavaType().isAssignableFrom(valueType)) {
192: throw new IllegalArgumentException();
193: }
194:
195: return a;
196: }
197:
198: @Override
199: public MapAttribute<X, ?, ?> getDeclaredMap(String name) {
200: return getDeclaredMap(name, Object.class, Object.class);
201: }
202:
203: @Override
204: public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
205: return declaredAttributeMap.values().stream().filter(Attribute::isCollection)
206: .map(a -> (PluralAttribute<X, ?, ?>) a)
207: .collect(Collectors.toSet());
208: }
209:
210: @Override
211: public <E> SetAttribute<X, E> getDeclaredSet(String name, Class<E> elementType) {
212: final SetAttribute<X, E> a = (SetAttribute<X, E>) getDeclaredAttribute(name);
213:
214:• if (!a.getBindableJavaType().isAssignableFrom(elementType)) {
215: throw new IllegalArgumentException();
216: }
217:
218: return a;
219: }
220:
221: @Override
222: public SetAttribute<X, ?> getDeclaredSet(String name) {
223: return getDeclaredSet(name, Object.class);
224: }
225:
226: @Override
227: public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(String name, Class<Y> type) {
228: final SingularAttribute<X, Y> a = (SingularAttribute<X, Y>) getDeclaredAttribute(name);
229:
230:• if (!a.getJavaType().isAssignableFrom(type)) {
231: throw new IllegalArgumentException();
232: }
233:
234: return a;
235: }
236:
237: @Override
238: public SingularAttribute<X, ?> getDeclaredSingularAttribute(String name) {
239: return getDeclaredSingularAttribute(name, Object.class);
240: }
241:
242: @Override
243: public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
244: return declaredAttributeMap.values().stream().filter(Attribute::isCollection).map(
245: a -> (SingularAttribute<X, ?>) a)
246: .collect(Collectors.toSet());
247: }
248:
249: @Override
250: public <E> ListAttribute<? super X, E> getList(String name, Class<E> elementType) {
251: final ListAttribute<? super X, E> a = (ListAttribute<? super X, E>) getAttribute(name);
252:
253:• if (!a.getBindableJavaType().isAssignableFrom(elementType)) {
254: throw new IllegalArgumentException();
255: }
256:
257: return a;
258: }
259:
260: @Override
261: public ListAttribute<? super X, ?> getList(String name) {
262: return getList(name, Object.class);
263: }
264:
265: @Override
266: public <K, V> MapAttribute<? super X, K, V> getMap(String name, Class<K> keyType,
267: Class<V> valueType) {
268: final MapAttribute<? super X, K, V> a = (MapAttribute<? super X, K, V>) getAttribute(name);
269:
270:• if (!a.getKeyJavaType().isAssignableFrom(keyType)
271:• || !a.getBindableJavaType().isAssignableFrom(valueType)) {
272: throw new IllegalArgumentException();
273: }
274:
275: return a;
276: }
277:
278: @Override
279: public MapAttribute<? super X, ?, ?> getMap(String name) {
280: return getMap(name, Object.class, Object.class);
281: }
282:
283: @Override
284: public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
285: return attributeMap.values().stream().filter(Attribute::isCollection).map(
286: a -> (PluralAttribute<? super X, ?, ?>) a)
287: .collect(Collectors.toSet());
288: }
289:
290: @Override
291: public <E> SetAttribute<? super X, E> getSet(String name, Class<E> elementType) {
292: final SetAttribute<? super X, E> a = (SetAttribute<? super X, E>) getAttribute(name);
293:
294:• if (!a.getBindableJavaType().isAssignableFrom(elementType)) {
295: throw new IllegalArgumentException();
296: }
297:
298: return a;
299: }
300:
301: @Override
302: public SetAttribute<? super X, ?> getSet(String name) {
303: return getSet(name, Object.class);
304: }
305:
306: @Override
307: public <Y> SingularAttribute<? super X, Y> getSingularAttribute(String name, Class<Y> type) {
308: final Attribute<? super X, ?> a = getAttribute(name);
309:
310:• if (!a.getJavaType().isAssignableFrom(type)) {
311: throw new IllegalArgumentException();
312: }
313:
314: return (SingularAttribute<? super X, Y>) a;
315: }
316:
317: @Override
318: public SingularAttribute<? super X, ?> getSingularAttribute(String name) {
319: return getSingularAttribute(name, Object.class);
320: }
321:
322: @Override
323: public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
324:• return attributeMap.values().stream().filter(a -> !a.isCollection())
325: .map(a -> (SingularAttribute<? super X, ?>) a)
326: .collect(Collectors.toSet());
327: }
328:
329: @Override
330: public Class<X> getJavaType() {
331: return javaType;
332: }
333:
334: @Override
335: public cz.cvut.kbss.jopa.model.metamodel.Type.PersistenceType getPersistenceType() {
336: return PersistenceType.ENTITY;
337: }
338:
339: @Override
340: public Class<X> getBindableJavaType() {
341: return getJavaType();
342: }
343:
344: @Override
345: public cz.cvut.kbss.jopa.model.metamodel.Bindable.BindableType getBindableType() {
346: return BindableType.ENTITY_TYPE;
347: }
348:
349: @Override
350: public IRI getIRI() {
351: return iri;
352: }
353:
354: @Override
355: public Identifier getIdentifier() {
356: return identifier;
357: }
358:
359: @Override
360: public TypesSpecification<? super X, ?> getTypes() {
361: return directTypes;
362: }
363:
364: @Override
365: public PropertiesSpecification<? super X, ?, ?, ?> getProperties() {
366: return properties;
367: }
368:
369: @Override
370: public FieldSpecification<? super X, ?> getFieldSpecification(String fieldName) {
371: FieldSpecification<? super X, ?> att = attributeMap.get(fieldName);
372:• if (att == null) {
373:• if (directTypes != null && directTypes.getName().equals(fieldName)) {
374: att = directTypes;
375:• } else if (properties != null && properties.getName().equals(fieldName)) {
376: att = properties;
377: }
378: }
379:• if (att == null) {
380: throw new IllegalArgumentException("Field " + fieldName + " is not declared in type " + name);
381: }
382: return att;
383: }
384:
385: @Override
386: public Set<FieldSpecification<? super X, ?>> getFieldSpecifications() {
387: final Set<FieldSpecification<? super X, ?>> specs = new HashSet<>(attributeMap.values());
388:• if (directTypes != null) {
389: specs.add(directTypes);
390: }
391:• if (properties != null) {
392: specs.add(properties);
393: }
394: return specs;
395: }
396:
397: @Override
398: public String toString() {
399: return "EntityType{" + name + "<" + iri + ">}";
400: }
401: }