• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

link-intersystems / lis-commons / #282

05 Nov 2023 05:04PM UTC coverage: 89.848% (-0.2%) from 90.032%
#282

Pull #10

renelink
Improved Readme.
Pull Request #10: feature/beans record

77 of 80 new or added lines in 11 files covered. (96.25%)

1 existing line in 1 file now uncovered.

7461 of 8304 relevant lines covered (89.85%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/lis-commons-beans/src/main/java/com/link_intersystems/beans/BeanClass.java
1
package com.link_intersystems.beans;
2

3
import java.lang.reflect.Parameter;
4
import java.util.List;
5
import java.util.function.Predicate;
6

7
import static java.util.stream.Collectors.toList;
8

9
/**
10
 * @author René Link {@literal <rene.link@link-intersystems.com>}
11
 */
12
public abstract class BeanClass<T> {
1✔
13

14
    protected static final Predicate<? super PropertyDesc> INDEXED_PROPERTY_FILTER = jpd -> jpd instanceof IndexedPropertyDesc;
1✔
15
    protected static final Predicate<? super PropertyDesc> NO_INDEXED_PROPERTY_FILTER = jpd -> !INDEXED_PROPERTY_FILTER.test(jpd);
1✔
16

17
    private transient PropertyDescList properties;
18
    private transient PropertyDescList indexedProperties;
19

20
    public abstract String getName();
21

22
    public abstract Class<T> getType();
23

24
    public boolean isInstance(Object bean) {
25
        return getType().isInstance(bean);
1✔
26
    }
27

28
    /**
29
     * Creates a new {@link Bean} of this class that has
30
     * a new bean instance that can be retrieved by {@link Bean#getBeanObject()}.
31
     */
32
    public Bean<T> newBeanInstance() throws BeanInstantiationException {
33
        BeanInstanceFactory<T> beanInstanceFactory = getBeanInstanceFactory();
1✔
34
        return beanInstanceFactory.newBeanInstance();
1✔
35
    }
36

37
    public BeanInstanceFactory<T> getBeanInstanceFactory() {
38
        return getBeanInstanceFactory(new ArgumentResolver() {
1✔
39
            @Override
40
            public boolean canResolveArgument(Parameter parameter) {
NEW
41
                return true;
×
42
            }
43

44
            @Override
45
            public Object resolveArgument(Parameter parameter) throws ArgumentResolveException {
NEW
46
                return null;
×
47
            }
48
        });
49
    }
50

51
    public abstract BeanInstanceFactory<T> getBeanInstanceFactory(ArgumentResolver argumentResolver);
52

53
    /**
54
     * Returns a {@link Bean} based on the given bean instance.
55
     */
56
    public Bean<T> getBeanFromInstance(T beanObject) {
57
        BeanInstanceFactory<T> beanInstanceFactory = getBeanInstanceFactory();
1✔
58
        return beanInstanceFactory.fromExistingInstance(beanObject);
1✔
59
    }
60

61
    public PropertyDescList getProperties() {
62
        if (this.properties == null) {
1✔
63
            List<PropertyDesc> propertyDescs = getAllProperties().stream()
1✔
64
                    .filter(NO_INDEXED_PROPERTY_FILTER)
1✔
65
                    .collect(toList());
1✔
66
            this.properties = new PropertyDescList(propertyDescs);
1✔
67
        }
68
        return properties;
1✔
69
    }
70

71
    public PropertyDescList getIndexedProperties() {
72
        if (this.indexedProperties == null) {
1✔
73
            List<PropertyDesc> propertyDescs = getAllProperties().stream()
1✔
74
                    .filter(INDEXED_PROPERTY_FILTER)
1✔
75
                    .collect(toList());
1✔
76
            this.indexedProperties = new PropertyDescList(propertyDescs);
1✔
77
        }
78
        return indexedProperties;
1✔
79
    }
80

81
    /**
82
     * @return the {@link #getProperties()} and the {@link #getIndexedProperties()}.
83
     */
84
    public abstract PropertyDescList getAllProperties();
85

86

87
    /**
88
     * @return true if either a simple property or an indexed property with the
89
     * given name exists.
90
     */
91
    public boolean hasAnyProperty(String propertyName) {
92
        return hasProperty(propertyName) || hasIndexedProperty(propertyName);
1✔
93
    }
94

95
    boolean hasProperty(String propertyName) {
96
        return getProperties().stream()
1✔
97
                .map(PropertyDesc::getName)
1✔
98
                .anyMatch(propertyName::equals);
1✔
99
    }
100

101
    boolean hasIndexedProperty(String propertyName) {
102
        return getIndexedProperties().stream()
1✔
103
                .map(PropertyDesc::getName)
1✔
104
                .anyMatch(propertyName::equals);
1✔
105
    }
106

107

108
    public BeanEventTypeList getBeanEventTypes() {
109
        return BeanEventTypeList.EMPTY;
×
110
    }
111

112
    public boolean isListenerSupported(Class<?> listenerClass) {
113
        return getBeanEventTypes()
×
114
                .stream()
×
115
                .anyMatch(be -> be.isApplicable(listenerClass));
×
116
    }
117

118
    public BeanClass<T> filter(PropertyDescFilter propertyDescFilter) {
119
        return new FilteredBeanClass<>(this, propertyDescFilter);
×
120
    }
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc