hasMixedProperties()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 2
c 1
b 0
f 0
cc 1
rs 10
1
package es.webbeta.serializer.metadata;
2
3
import es.webbeta.serializer.base.MetadataProperty;
4
import es.webbeta.serializer.type.FieldAccessType;
5
6
import java.util.ArrayList;
7
import java.util.List;
8
import java.util.stream.Collectors;
9
import java.util.stream.Stream;
10
11
public class Metadata {
12
13
    private String canonicalName;
14
    private FieldAccessType accessType;
15
    private List<MetadataVirtualProperty> virtualProperties = new ArrayList<>();
16
    private List<es.webbeta.serializer.metadata.MetadataProperty> properties = new ArrayList<>();
17
18
    Metadata(String canonicalName) {
19
        this.canonicalName = canonicalName;
20
    }
21
22
    public Boolean appliesTo(String canonicalName) {
23
        return this.canonicalName.equals(canonicalName);
24
    }
25
26
    public String getCanonicalName() {
27
        return canonicalName;
28
    }
29
30
    public Boolean hasAccessType() {
31
        return accessType != null;
32
    }
33
34
    public FieldAccessType getAccessType() {
35
        return accessType;
36
    }
37
38
    public void setAccessType(FieldAccessType accessType) {
39
        this.accessType = accessType;
40
    }
41
42
    public Boolean hasVirtualProperties() {
43
        return virtualProperties.size() > 0;
0 ignored issues
show
Best Practice introduced by
Use isEmpty() to check if a collection is empty instead of checking its size, since it is optimized for this task.
Loading history...
44
    }
45
46
    public List<MetadataVirtualProperty> getVirtualProperties() {
47
        return virtualProperties;
48
    }
49
50
    public Boolean hasVirtualProperty(String name) {
51
        return getVirtualProperty(name) != null;
52
    }
53
54
    public MetadataVirtualProperty getVirtualProperty(String name) {
55
        List<MetadataVirtualProperty> props = virtualProperties.stream()
56
                .filter(prop -> prop.getPropertyName().equals(name))
57
                .collect(Collectors.toList());
58
59
        if (props.size() == 0)
0 ignored issues
show
Best Practice introduced by
Use isEmpty() to check if a collection is empty instead of checking its size, since it is optimized for this task.
Loading history...
60
            return null;
61
        else
62
            return props.get(0);
63
    }
64
65
    public void setVirtualProperties(List<MetadataVirtualProperty> virtualProperties) {
66
        this.virtualProperties = virtualProperties;
67
    }
68
69
    public Boolean hasProperties() {
70
        return properties.size() > 0;
0 ignored issues
show
Best Practice introduced by
Use isEmpty() to check if a collection is empty instead of checking its size, since it is optimized for this task.
Loading history...
71
    }
72
73
    public List<es.webbeta.serializer.metadata.MetadataProperty> getProperties() {
74
        return properties;
75
    }
76
77
    public Boolean hasProperty(String name) {
78
        return getProperty(name) != null;
79
    }
80
81
    public es.webbeta.serializer.metadata.MetadataProperty getProperty(String name) {
82
        List<es.webbeta.serializer.metadata.MetadataProperty> props = properties.stream()
83
                .filter(prop -> prop.getPropertyName().equals(name))
84
                .collect(Collectors.toList());
85
86
        if (props.size() == 0)
0 ignored issues
show
Best Practice introduced by
Use isEmpty() to check if a collection is empty instead of checking its size, since it is optimized for this task.
Loading history...
87
            return null;
88
        else
89
            return props.get(0);
90
    }
91
92
    public void setProperties(List<es.webbeta.serializer.metadata.MetadataProperty> properties) {
93
        this.properties = properties;
94
    }
95
96
    public Boolean hasMixedProperties() {
97
        return hasProperties() || hasVirtualProperties();
98
    }
99
100
    public List<MetadataProperty> getMixedProperties() {
101
        return Stream.concat(properties.stream(), virtualProperties.stream()).collect(Collectors.toList());
102
    }
103
104
    public Boolean hasMixedProperty(String name) {
105
        return getMixedProperty(name) != null;
106
    }
107
108
    public MetadataProperty getMixedProperty(String name) {
109
        List<MetadataProperty> mixedProps = getMixedProperties();
110
111
        List<MetadataProperty> props = mixedProps.stream()
112
                .filter(prop -> prop.getPropertyName().equals(name))
113
                .collect(Collectors.toList());
114
115
        if (props.size() == 0)
0 ignored issues
show
Best Practice introduced by
Use isEmpty() to check if a collection is empty instead of checking its size, since it is optimized for this task.
Loading history...
116
            return null;
117
        else
118
            return props.get(0);
119
    }
120
121
}
122