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