Package: RdfContainerAttributeImpl
RdfContainerAttributeImpl
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
RdfContainerAttributeImpl(RdfContainerAttributeImpl.RDFContainerAttributeBuilder) |
|
|
|
|
|
||||||||||||||||||||
builder(PropertyAttributes) |
|
|
|
|
|
||||||||||||||||||||
getCollectionType() |
|
|
|
|
|
||||||||||||||||||||
getContainerType() |
|
|
|
|
|
||||||||||||||||||||
resolveCollectionType(RDFContainerType) |
|
|
|
|
|
||||||||||||||||||||
toString() |
|
|
|
|
|
||||||||||||||||||||
validateCollectionType() |
|
|
|
|
|
Coverage
1: package cz.cvut.kbss.jopa.model.metamodel;
2:
3: import cz.cvut.kbss.jopa.exception.InvalidFieldMappingException;
4: import cz.cvut.kbss.jopa.model.annotations.RDFContainerType;
5: import cz.cvut.kbss.jopa.oom.converter.ConverterWrapper;
6:
7: public class RdfContainerAttributeImpl<X, C, E> extends AbstractPluralAttribute<X, C, E> implements RDFContainerAttribute<X, C, E> {
8:
9: private final RDFContainerType containerType;
10:
11: private final CollectionType collectionType;
12:
13: RdfContainerAttributeImpl(RDFContainerAttributeBuilder<X, C, E> builder) {
14: super(builder);
15: this.containerType = builder.containerType;
16: this.collectionType = resolveCollectionType(containerType);
17: validateCollectionType();
18: }
19:
20: private static CollectionType resolveCollectionType(RDFContainerType containerType) {
21:• return switch (containerType) {
22: case SEQ -> CollectionType.LIST;
23: case ALT -> CollectionType.SET;
24: case BAG -> CollectionType.COLLECTION;
25: };
26: }
27:
28: private void validateCollectionType() {
29:• if (containerType == RDFContainerType.SEQ && CollectionType.SET.getCollectionClass()
30:• .isAssignableFrom(getJavaType())
31: || containerType == RDFContainerType.ALT && CollectionType.LIST.getCollectionClass()
32:• .isAssignableFrom(getJavaType())) {
33: throw new InvalidFieldMappingException("RDF " + containerType.name() + " cannot be mapped to a field of type " + getJavaType());
34: }
35: }
36:
37: @Override
38: public RDFContainerType getContainerType() {
39: return containerType;
40: }
41:
42: @Override
43: public CollectionType getCollectionType() {
44: return collectionType;
45: }
46:
47: @Override
48: public String toString() {
49: return "RDFContainerAttribute[" + getName() + "]";
50: }
51:
52: static RDFContainerAttributeBuilder builder(PropertyAttributes config) {
53: return new RDFContainerAttributeBuilder().config(config);
54: }
55:
56: static class RDFContainerAttributeBuilder<X, C, E> extends PluralAttributeBuilder<X, C, E> {
57:
58: private RDFContainerType containerType;
59:
60: public RDFContainerAttributeBuilder<X, C, E> containerType(RDFContainerType containerType) {
61: this.containerType = containerType;
62: return this;
63: }
64:
65: @Override
66: public RDFContainerAttributeBuilder<X, C, E> elementType(Type<E> elementType) {
67: super.elementType(elementType);
68: return this;
69: }
70:
71: @Override
72: public RDFContainerAttributeBuilder<X, C, E> collectionType(Class<C> collectionType) {
73: super.collectionType(collectionType);
74: return this;
75: }
76:
77: @Override
78: public RDFContainerAttributeBuilder<X, C, E> propertyInfo(PropertyInfo propertyInfo) {
79: super.propertyInfo(propertyInfo);
80: return this;
81: }
82:
83: @Override
84: public RDFContainerAttributeBuilder<X, C, E> declaringType(ManagedType<X> declaringType) {
85: super.declaringType(declaringType);
86: return this;
87: }
88:
89: @Override
90: public RDFContainerAttributeBuilder<X, C, E> inferred(boolean inferred) {
91: super.inferred(inferred);
92: return this;
93: }
94:
95: @Override
96: public RDFContainerAttributeBuilder<X, C, E> includeExplicit(boolean includeExplicit) {
97: super.includeExplicit(includeExplicit);
98: return this;
99: }
100:
101: @Override
102: public RDFContainerAttributeBuilder<X, C, E> converter(ConverterWrapper converter) {
103: super.converter(converter);
104: return this;
105: }
106:
107: @Override
108: public RDFContainerAttributeBuilder<X, C, E> config(PropertyAttributes config) {
109: super.config(config);
110: return this;
111: }
112:
113: @Override
114: public RdfContainerAttributeImpl<X, C, E> build() {
115: return new RdfContainerAttributeImpl<>(this);
116: }
117: }
118: }