Skip to content

Package: AbstractPluralAttribute

AbstractPluralAttribute

nameinstructionbranchcomplexitylinemethod
AbstractPluralAttribute(AbstractPluralAttribute.PluralAttributeBuilder)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getBindableJavaType()
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%
getBindableType()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getCollectionType()
M: 18 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getElementType()
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%
isCollection()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2022 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.metamodel;
16:
17: import cz.cvut.kbss.jopa.oom.converter.ConverterWrapper;
18:
19: import java.lang.reflect.Field;
20: import java.util.Collection;
21: import java.util.Map;
22:
23: public abstract class AbstractPluralAttribute<X, C, E> extends AbstractAttribute<X, C>
24: implements PluralAttribute<X, C, E> {
25:
26: private final Type<E> elementType;
27:
28: private final Class<C> collectionType;
29:
30: AbstractPluralAttribute(PluralAttributeBuilder<X, C, E> builder) {
31: super(builder);
32: this.elementType = builder.elementType;
33: this.collectionType = builder.collectionType;
34: }
35:
36: @Override
37: public boolean isCollection() {
38: return true;
39: }
40:
41: @Override
42: public Class<E> getBindableJavaType() {
43: return elementType.getJavaType();
44: }
45:
46: @Override
47: public cz.cvut.kbss.jopa.model.metamodel.Bindable.BindableType getBindableType() {
48: return BindableType.PLURAL_ATTRIBUTE;
49: }
50:
51: @Override
52: public cz.cvut.kbss.jopa.model.metamodel.CollectionType getCollectionType() {
53:• if (getJavaType().isAssignableFrom(Collection.class)) {
54: return CollectionType.COLLECTION;
55:• } else if (getJavaType().isAssignableFrom(Map.class)) {
56: return CollectionType.MAP;
57: } else {
58: throw new IllegalArgumentException();
59: }
60: }
61:
62: @Override
63: public Type<E> getElementType() {
64: return elementType;
65: }
66:
67: @Override
68: public Class<C> getJavaType() {
69: return collectionType;
70: }
71:
72: public abstract static class PluralAttributeBuilder<X, C, E> extends AbstractAttributeBuilder<X, C> {
73: private Type<E> elementType;
74: private Class<C> collectionType;
75:
76: @Override
77: public PluralAttributeBuilder<X, C, E> config(PropertyAttributes config) {
78: super.config(config);
79: elementType((Type<E>) config.getType());
80: return this;
81: }
82:
83: public PluralAttributeBuilder<X, C, E> elementType(Type<E> elementType) {
84: this.elementType = elementType;
85: return this;
86: }
87:
88: public PluralAttributeBuilder<X, C, E> collectionType(Class<C> collectionType) {
89: this.collectionType = collectionType;
90: return this;
91: }
92:
93: @Override
94: public PluralAttributeBuilder<X, C, E> field(Field field) {
95: super.field(field);
96: return this;
97: }
98:
99: @Override
100: public PluralAttributeBuilder<X, C, E> declaringType(ManagedType<X> declaringType) {
101: super.declaringType(declaringType);
102: return this;
103: }
104:
105: @Override
106: public PluralAttributeBuilder<X, C, E> inferred(boolean inferred) {
107: super.inferred(inferred);
108: return this;
109: }
110:
111: @Override
112: public PluralAttributeBuilder<X, C, E> includeExplicit(boolean includeExplicit) {
113: super.includeExplicit(includeExplicit);
114: return this;
115: }
116:
117: @Override
118: public PluralAttributeBuilder<X, C, E> converter(ConverterWrapper converter) {
119: super.converter(converter);
120: return this;
121: }
122:
123: @Override
124: public abstract AbstractPluralAttribute<X, C, E> build();
125: }
126: }