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

leeonky / test-charm-java / 335

04 Oct 2025 03:47PM UTC coverage: 74.611% (-0.04%) from 74.653%
335

push

circleci

leeonky
Process list and list consistency

40 of 42 new or added lines in 3 files covered. (95.24%)

29 existing lines in 4 files now uncovered.

8590 of 11513 relevant lines covered (74.61%)

0.75 hits per line

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

76.36
/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.function.Function;
6
import java.util.stream.Collectors;
7

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

17
class DefaultListConsistency<T> implements ListConsistency<T> {
18
    final List<PropertyChain> listProperty;
19
    private final DefaultConsistency<T> consistency;
20
    final List<ListConsistencyItem<T>> items = new ArrayList<>();
1✔
21
    private final List<DefaultListConsistency<?>> list = new ArrayList<>();
1✔
22

23
    DefaultListConsistency(List<String> listProperty, DefaultConsistency<T> consistency) {
1✔
24
        this.listProperty = listProperty.stream().map(PropertyChain::propertyChain).collect(Collectors.toList());
1✔
25
        this.consistency = consistency;
1✔
26
    }
1✔
27

28
    @Override
29
    @SuppressWarnings("unchecked")
30
    public ListConsistency<T> direct(String property) {
31
        return property(property).read((Function<Object, T>) LINK_COMPOSER).write((Function<T, Object>) LINK_DECOMPOSER);
1✔
32
    }
33

34
    @Override
35
    public <P> ListConsistency.LC1<T, P> property(String property) {
36
        ListConsistencyItem<T> listConsistencyItem = new ListConsistencyItem<>(singletonList(property));
1✔
37
        items.add(listConsistencyItem);
1✔
38
        return new DefaultListConsistency.LC1<>(this, listConsistencyItem);
1✔
39
    }
40

41
    @Override
42
    public <P1, P2> ListConsistency.LC2<T, P1, P2> properties(String property1, String property2) {
43
        ListConsistencyItem<T> listConsistencyItem = new ListConsistencyItem<>(asList(property1, property2));
1✔
44
        items.add(listConsistencyItem);
1✔
45
        return new DefaultListConsistency.LC2<>(this, listConsistencyItem);
1✔
46
    }
47

48
    @Override
49
    public <P1, P2, P3> LC3<T, P1, P2, P3> properties(String property1, String property2, String property3) {
50
        ListConsistencyItem<T> listConsistencyItem = new ListConsistencyItem<>(asList(property1, property2, property3));
1✔
51
        items.add(listConsistencyItem);
1✔
52
        return new LC3<>(this, listConsistencyItem);
1✔
53
    }
54

55
    @Deprecated
56
    void populateConsistencies(ObjectProducer<?> producer, PropertyChain parentList) {
NEW
57
        PropertyChain listProperty = parentList.concat(this.listProperty.get(0));
×
UNCOV
58
        Producer<?> descendant = producer.descendantForUpdate(listProperty);
×
59
        if (!(descendant instanceof CollectionProducer))
×
UNCOV
60
            throw new IllegalStateException(listProperty + " is not List");
×
UNCOV
61
        range(0, ((CollectionProducer<?, ?>) descendant).childrenCount()).mapToObj(listProperty::concat)
×
UNCOV
62
                .forEach(elementProperty -> populateElementConsistency(producer, elementProperty));
×
UNCOV
63
    }
×
64

65
    private void populateElementConsistency(ObjectProducer<?> producer, PropertyChain elementProperty) {
UNCOV
66
        items.forEach(item -> item.populateConsistency(elementProperty, consistency));
×
UNCOV
67
        list.forEach(listConsistency -> listConsistency.populateConsistencies(producer, elementProperty));
×
UNCOV
68
    }
×
69

70
    PropertyChain toProperty(Coordinate coordinate) {
71
        return zip(listProperty, coordinate.index).stream().reduce(propertyChain(""),
1✔
72
                (p, z) -> p.concat(z.left()).concat(z.right().index), notAllowParallelReduce());
1✔
73
    }
74

75
    List<DefaultConsistency<T>> collectCoordinateAndProcess(ObjectProducer<?> producer, List<Index> baseIndex,
76
                                                            int l, PropertyChain baseProperty) {
77
        List<DefaultConsistency<T>> results = new ArrayList<>();
1✔
78
        PropertyChain list = baseProperty.concat(listProperty.get(l++));
1✔
79
        CollectionProducer<?, ?> collectionProducer = (CollectionProducer<?, ?>) producer.descendantForUpdate(list);
1✔
80
        for (int i = 0; i < collectionProducer.childrenCount(); i++) {
1✔
81
            Index index = new Index();
1✔
82
            index.index = i;
1✔
83
            index.size = collectionProducer.childrenCount();
1✔
84
            List<Index> indexes = new ArrayList<>(baseIndex);
1✔
85
            indexes.add(index);
1✔
86
            if (listProperty.size() > l)
1✔
87
                results.addAll(collectCoordinateAndProcess(producer, indexes, l, list.concat(i)));
1✔
88
            else
89
                results.add(consistency.populateConsistencyWithList(new Coordinate(indexes)));
1✔
90
        }
91
        return results;
1✔
92
    }
93

94
    //    @Override
95
//    public NestedListConsistencyBuilder<T> list(String property) {
96
//        DefaultListConsistency<T> listConsistency = new DefaultListConsistency<>(property, consistency);
97
//        list.add(listConsistency);
98
//        return new NestedListConsistencyBuilder<>(this, listConsistency);
99
//    }
100
}
101

102
class DecorateListConsistency<T> implements ListConsistency<T> {
103
    private final ListConsistency<T> delegate;
104

105
    public DecorateListConsistency(ListConsistency<T> delegate) {
1✔
106
        this.delegate = delegate;
1✔
107
    }
1✔
108

109
    @Override
110
    public ListConsistency<T> direct(String property) {
111
        return delegate.direct(property);
1✔
112
    }
113

114
    @Override
115
    public <P> ListConsistency.LC1<T, P> property(String property) {
UNCOV
116
        return delegate.property(property);
×
117
    }
118

119
    @Override
120
    public <P1, P2> ListConsistency.LC2<T, P1, P2> properties(String property1, String property2) {
UNCOV
121
        return delegate.properties(property1, property2);
×
122
    }
123

124
    @Override
125
    public <P1, P2, P3> LC3<T, P1, P2, P3> properties(String property1, String property2, String property3) {
UNCOV
126
        return delegate.properties(property1, property2, property3);
×
127
    }
128

129
//    @Override
130
//    public NestedListConsistencyBuilder<T> list(String property) {
131
//        return delegate.list(property);
132
//    }
133
}
134

135
class MultiPropertyListConsistency<T, C extends MultiPropertyListConsistency<T, C>> extends DecorateListConsistency<T> {
136
    final ListConsistencyItem<T> last;
137

138
    MultiPropertyListConsistency(ListConsistency<T> delegate, ListConsistencyItem<T> last) {
139
        super(delegate);
1✔
140
        this.last = last;
1✔
141
    }
1✔
142

143
    @SuppressWarnings("unchecked")
144
    public C read(Function<Object[], T> composer) {
145
        last.setComposer(new ComposerWrapper<>(composer, composer));
1✔
146
        return (C) this;
1✔
147
    }
148

149
    @SuppressWarnings("unchecked")
150
    public C write(Function<T, Object[]> decomposer) {
151
        last.setDecomposer(new DecomposerWrapper<>(decomposer, decomposer));
1✔
152
        return (C) this;
1✔
153
    }
154
}
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