Skip to content

Package: ReferencedListDataPropertyStrategy

ReferencedListDataPropertyStrategy

nameinstructionbranchcomplexitylinemethod
ReferencedListDataPropertyStrategy(EntityType, ListAttributeImpl, Descriptor, EntityMappingHelper)
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%
addAxiomValue(Axiom)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
buildAxiomValuesFromInstance(Object, AxiomValueGatherer)
M: 4 C: 31
89%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 9
100%
M: 0 C: 1
100%
buildAxiomsFromInstance(Object)
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%
buildInstanceFieldValue(Object)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createListDescriptor(Axiom)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createListValueDescriptor(Object)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
hasValue()
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isValidRange(Object)
M: 1 C: 13
93%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$addAxiomValue$0(Axiom)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$addAxiomValue$1(Axiom)
M: 0 C: 16
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
lambda$buildAxiomValuesFromInstance$2(ReferencedListValueDescriptor, Object)
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%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: package cz.cvut.kbss.jopa.oom;
2:
3: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
4: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
5: import cz.cvut.kbss.jopa.model.metamodel.ListAttributeImpl;
6: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
7: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
8: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListValueDescriptor;
9: import cz.cvut.kbss.ontodriver.model.Axiom;
10: import cz.cvut.kbss.ontodriver.model.NamedResource;
11:
12: import java.util.ArrayList;
13: import java.util.Collection;
14: import java.util.List;
15: import java.util.Objects;
16: import java.util.Set;
17:
18: class ReferencedListDataPropertyStrategy<X> extends DataPropertyFieldStrategy<ListAttributeImpl<? super X, ?>, X> {
19:
20: private final Class<?> elementType;
21:
22: private final List<Object> values = new ArrayList<>();
23:
24: ReferencedListDataPropertyStrategy(EntityType<X> et, ListAttributeImpl<? super X, ?> att,
25: Descriptor attributeDescriptor, EntityMappingHelper mapper) {
26: super(et, att, attributeDescriptor, mapper);
27: this.elementType = att.getElementType().getJavaType();
28: }
29:
30: @Override
31: void addAxiomValue(Axiom<?> head) {
32: final ReferencedListDescriptor listDescriptor = createListDescriptor(head);
33: final Collection<Axiom<?>> sequence = mapper.loadReferencedList(listDescriptor);
34: sequence.stream()
35: .filter(item -> item.getAssertion().getIdentifier()
36: .equals(attribute.getHasContentsPropertyIRI().toURI()))
37: .forEach(item -> {
38: final Object value = item.getValue().getValue();
39:• if (isValidRange(value)) {
40: values.add(toAttributeValue(value));
41: }
42: });
43: }
44:
45: ReferencedListDescriptor createListDescriptor(Axiom<?> ax) {
46: final NamedResource owner = ax.getSubject();
47: final ReferencedListDescriptor listDescriptor = ListDescriptorFactory.createReferencedListDescriptor(owner, attribute);
48: listDescriptor.setContext(getAttributeWriteContext());
49: return listDescriptor;
50: }
51:
52: @Override
53: boolean hasValue() {
54:• return !values.isEmpty();
55: }
56:
57: @Override
58: boolean isValidRange(Object value) {
59:• return elementType.isAssignableFrom(value.getClass()) || canBeConverted(value);
60: }
61:
62: @Override
63: void buildInstanceFieldValue(Object instance) {
64: setValueOnInstance(instance, values);
65: }
66:
67: @Override
68: void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) {
69: final Object value = extractFieldValueFromInstance(instance);
70:• assert value instanceof List || value == null;
71:
72: final ReferencedListValueDescriptor<Object> listDescriptor = createListValueDescriptor(instance);
73: final List<?> list = (List<?>) value;
74:• if (list != null) {
75: list.stream().filter(Objects::nonNull)
76: .forEach(v -> listDescriptor.addValue(converter.convertToAxiomValue(v)));
77: }
78: valueBuilder.addReferencedListValues(listDescriptor);
79: }
80:
81: private <V> ReferencedListValueDescriptor<V> createListValueDescriptor(X instance) {
82: final NamedResource owner = NamedResource.create(EntityPropertiesUtils.getIdentifier(instance, et));
83: final ReferencedListValueDescriptor<V> descriptor = ListDescriptorFactory.createReferencedListValueDescriptor(owner, attribute);
84: descriptor.setContext(getAttributeWriteContext());
85: return descriptor;
86: }
87:
88: @Override
89: Set<Axiom<?>> buildAxiomsFromInstance(X instance) {
90: throw new UnsupportedOperationException("Method not supported for referenced lists.");
91: }
92: }