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

leeonky / test-charm-java / 338

05 Oct 2025 04:05PM UTC coverage: 74.667% (+0.06%) from 74.611%
338

push

circleci

leeonky
Some index mapping in list consistency

4 of 4 new or added lines in 2 files covered. (100.0%)

23 existing lines in 3 files now uncovered.

8627 of 11554 relevant lines covered (74.67%)

0.75 hits per line

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

78.33
/jfactory/src/main/java/com/github/leeonky/jfactory/DefaultListConsistency.java
1
package com.github.leeonky.jfactory;
2

3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Optional;
6
import java.util.function.Function;
7
import java.util.stream.Collectors;
8

9
import static com.github.leeonky.jfactory.DefaultConsistency.LINK_COMPOSER;
10
import static com.github.leeonky.jfactory.DefaultConsistency.LINK_DECOMPOSER;
11
import static com.github.leeonky.jfactory.PropertyChain.propertyChain;
12
import static com.github.leeonky.util.Zipped.zip;
13
import static com.github.leeonky.util.function.Extension.notAllowParallelReduce;
14
import static java.util.Arrays.asList;
15
import static java.util.Collections.singletonList;
16
import static java.util.Optional.ofNullable;
17
import static java.util.stream.IntStream.range;
18

19
class DefaultListConsistency<T, C extends Coordinate> implements ListConsistency<T, C> {
20
    final List<PropertyChain> listProperty;
21
    private final DefaultConsistency<T, C> consistency;
22
    final List<ListConsistencyItem<T>> items = new ArrayList<>();
1✔
23
    private final List<DefaultListConsistency<?, ?>> list = new ArrayList<>();
1✔
24
    private Function<Coordinate, C> aligner = this::convert;
1✔
25

26
    private C convert(Coordinate e) {
27
        return e.convertTo(consistency.coordinateType());
1✔
28
    }
29

30
    private Function<C, Coordinate> inverseAligner = e -> e;
1✔
31

32
    DefaultListConsistency(List<String> listProperty, DefaultConsistency<T, C> consistency) {
1✔
33
        this.listProperty = listProperty.stream().map(PropertyChain::propertyChain).collect(Collectors.toList());
1✔
34
        this.consistency = consistency;
1✔
35
    }
1✔
36

37
    @Override
38
    @SuppressWarnings("unchecked")
39
    public ListConsistency<T, C> direct(String property) {
40
        return property(property).read((Function<Object, T>) LINK_COMPOSER).write((Function<T, Object>) LINK_DECOMPOSER);
1✔
41
    }
42

43
    @Override
44
    public <P> ListConsistency.LC1<T, P, C> property(String property) {
45
        ListConsistencyItem<T> listConsistencyItem = new ListConsistencyItem<>(singletonList(property));
1✔
46
        items.add(listConsistencyItem);
1✔
47
        return new DefaultListConsistency.LC1<>(this, listConsistencyItem);
1✔
48
    }
49

50
    @Override
51
    public <P1, P2> ListConsistency.LC2<T, P1, P2, C> properties(String property1, String property2) {
52
        ListConsistencyItem<T> listConsistencyItem = new ListConsistencyItem<>(asList(property1, property2));
1✔
53
        items.add(listConsistencyItem);
1✔
54
        return new DefaultListConsistency.LC2<>(this, listConsistencyItem);
1✔
55
    }
56

57
    @Override
58
    public <P1, P2, P3> LC3<T, P1, P2, P3, C> properties(String property1, String property2, String property3) {
59
        ListConsistencyItem<T> listConsistencyItem = new ListConsistencyItem<>(asList(property1, property2, property3));
1✔
60
        items.add(listConsistencyItem);
1✔
61
        return new LC3<>(this, listConsistencyItem);
1✔
62
    }
63

64
    @Deprecated
65
    void populateConsistencies(ObjectProducer<?> producer, PropertyChain parentList) {
66
        PropertyChain listProperty = parentList.concat(this.listProperty.get(0));
×
67
        Producer<?> descendant = producer.descendantForUpdate(listProperty);
×
68
        if (!(descendant instanceof CollectionProducer))
×
UNCOV
69
            throw new IllegalStateException(listProperty + " is not List");
×
UNCOV
70
        range(0, ((CollectionProducer<?, ?>) descendant).childrenCount()).mapToObj(listProperty::concat)
×
UNCOV
71
                .forEach(elementProperty -> populateElementConsistency(producer, elementProperty));
×
UNCOV
72
    }
×
73

74
    private void populateElementConsistency(ObjectProducer<?> producer, PropertyChain elementProperty) {
UNCOV
75
        items.forEach(item -> item.populateConsistency(elementProperty, consistency));
×
UNCOV
76
        list.forEach(listConsistency -> listConsistency.populateConsistencies(producer, elementProperty));
×
UNCOV
77
    }
×
78

79
    Optional<PropertyChain> toProperty(C coordinate) {
80
        return ofNullable(inverseAligner.apply(coordinate)).map(co -> zip(listProperty, co.indexes()).stream().reduce(propertyChain(""),
1✔
81
                (p, z) -> p.concat(z.left()).concat(z.right().index()), notAllowParallelReduce()));
1✔
82
    }
83

84
    List<DefaultConsistency<T, C>> collectCoordinateAndProcess(ObjectProducer<?> producer, List<Index> baseIndex,
85
                                                               int l, PropertyChain baseProperty) {
86
        List<DefaultConsistency<T, C>> results = new ArrayList<>();
1✔
87
        PropertyChain list = baseProperty.concat(listProperty.get(l++));
1✔
88
        CollectionProducer<?, ?> collectionProducer = (CollectionProducer<?, ?>) producer.descendantForUpdate(list);
1✔
89
        for (int i = 0; i < collectionProducer.childrenCount(); i++) {
1✔
90
            Index index = new Index(collectionProducer.childrenCount(), i);
1✔
91
            List<Index> indexes = new ArrayList<>(baseIndex);
1✔
92
            indexes.add(index);
1✔
93
            if (listProperty.size() > l)
1✔
94
                results.addAll(collectCoordinateAndProcess(producer, indexes, l, list.concat(i)));
1✔
95
            else
96
                ofNullable(aligner.apply(new Coordinate(indexes))).ifPresent(c ->
1✔
97
                        results.add(consistency.populateConsistencyWithList(c)));
1✔
98
        }
99
        return results;
1✔
100
    }
101

102
    public void normalize(Function<Coordinate, C> aligner,
103
                          Function<C, Coordinate> inverseAligner) {
104
        this.aligner = aligner;
1✔
105
        this.inverseAligner = inverseAligner;
1✔
106
    }
1✔
107

108
    //    @Override
109
//    public NestedListConsistencyBuilder<T> list(String property) {
110
//        DefaultListConsistency<T> listConsistency = new DefaultListConsistency<>(property, consistency);
111
//        list.add(listConsistency);
112
//        return new NestedListConsistencyBuilder<>(this, listConsistency);
113
//    }
114
}
115

116
class DecorateListConsistency<T, C extends Coordinate> implements ListConsistency<T, C> {
117
    private final ListConsistency<T, C> delegate;
118

119
    public DecorateListConsistency(ListConsistency<T, C> delegate) {
1✔
120
        this.delegate = delegate;
1✔
121
    }
1✔
122

123
    @Override
124
    public ListConsistency<T, C> direct(String property) {
125
        return delegate.direct(property);
1✔
126
    }
127

128
    @Override
129
    public <P> ListConsistency.LC1<T, P, C> property(String property) {
UNCOV
130
        return delegate.property(property);
×
131
    }
132

133
    @Override
134
    public <P1, P2> ListConsistency.LC2<T, P1, P2, C> properties(String property1, String property2) {
UNCOV
135
        return delegate.properties(property1, property2);
×
136
    }
137

138
    @Override
139
    public <P1, P2, P3> LC3<T, P1, P2, P3, C> properties(String property1, String property2, String property3) {
UNCOV
140
        return delegate.properties(property1, property2, property3);
×
141
    }
142

143
    //    @Override
144
//    public NestedListConsistencyBuilder<T> list(String property) {
145
//        return delegate.list(property);
146
//    }
147
}
148

149
class MultiPropertyListConsistency<T, M extends MultiPropertyListConsistency<T, M, C>, C extends Coordinate>
150
        extends DecorateListConsistency<T, C> {
151
    final ListConsistencyItem<T> last;
152

153
    MultiPropertyListConsistency(ListConsistency<T, C> delegate, ListConsistencyItem<T> last) {
154
        super(delegate);
1✔
155
        this.last = last;
1✔
156
    }
1✔
157

158
    @SuppressWarnings("unchecked")
159
    public M read(Function<Object[], T> composer) {
160
        last.setComposer(new ComposerWrapper<>(composer, composer));
1✔
161
        return (M) this;
1✔
162
    }
163

164
    @SuppressWarnings("unchecked")
165
    public M write(Function<T, Object[]> decomposer) {
166
        last.setDecomposer(new DecomposerWrapper<>(decomposer, decomposer));
1✔
167
        return (M) this;
1✔
168
    }
169
}
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

© 2026 Coveralls, Inc