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

leeonky / test-charm-java / 311

27 Sep 2025 10:36AM UTC coverage: 74.329% (+3.1%) from 71.191%
311

push

circleci

leeonky
Remove useless code

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

43 existing lines in 9 files now uncovered.

8397 of 11297 relevant lines covered (74.33%)

0.74 hits per line

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

81.69
/jfactory/src/main/java/com/github/leeonky/jfactory/Consistency.java
1
package com.github.leeonky.jfactory;
2

3
import com.github.leeonky.util.BeanClass;
4
import com.github.leeonky.util.function.TriFunction;
5

6
import java.util.Arrays;
7
import java.util.Objects;
8
import java.util.function.BiFunction;
9
import java.util.function.Function;
10

11
import static com.github.leeonky.jfactory.ConsistencyItem.guessCustomerPositionStackTrace;
12
import static com.github.leeonky.jfactory.PropertyChain.propertyChain;
13
import static java.util.Arrays.asList;
14
import static java.util.Collections.singletonList;
15
import static java.util.stream.Collectors.toList;
16

17
public interface Consistency<T> {
18
    Function<Object[], ?> LINK_COMPOSER = objs -> objs[0];
1✔
19
    Function<?, Object[]> LINK_DECOMPOSER = t -> new Object[]{t};
1✔
20

21
    Consistency<T> link(ConsistencyItem<T> item);
22

23
//    void apply(Producer<?> producer);
24

25
    BeanClass<T> type();
26

27
    @SuppressWarnings("unchecked")
28
    default Consistency<T> direct(String property) {
29
        ConsistencyItem<T> item = new ConsistencyItem<>(singletonList(propertyChain(property)), this);
1✔
30
        item.setComposer(new ComposerWrapper(LINK_COMPOSER, LINK_COMPOSER));
1✔
31
        item.setDecomposer(new DecomposerWrapper(LINK_DECOMPOSER, LINK_DECOMPOSER));
1✔
32
        return link(item);
1✔
33
    }
34

35
    default <P> C1<T, P> property(String property) {
36
        return new C1<>(this, new ConsistencyItem<>(singletonList(propertyChain(property)), this));
1✔
37
    }
38

39
    default <P1, P2> C2<T, P1, P2> properties(String property1, String property2) {
40
        return new C2<>(this, new ConsistencyItem<>(asList(propertyChain(property1), propertyChain(property2)), this));
1✔
41
    }
42

43
    default <P1, P2, P3> C3<T, P1, P2, P3> properties(String property1, String property2, String property3) {
UNCOV
44
        return new C3<>(this, new ConsistencyItem<>(asList(propertyChain(property1), propertyChain(property2), propertyChain(property3)), this));
×
45
    }
46

47
    default CN<T> properties(String... properties) {
48
        return new CN<>(this, new ConsistencyItem<>(Arrays.stream(properties).map(PropertyChain::propertyChain).collect(toList()), this));
1✔
49
    }
50

51
    interface Identity {
52
        default Object identity() {
UNCOV
53
            return this;
×
54
        }
55

56
        default boolean same(Identity another) {
57
            return another != null && identity() == another.identity();
1✔
58
        }
59

60
        StackTraceElement getLocation();
61

62
        static boolean isSame(Identity identity1, Identity identity2) {
63
            return identity1 != null && identity2 != null && identity1.same(identity2);
1✔
64
        }
65

66
        static boolean isNotSame(Identity identity1, Identity identity2) {
UNCOV
67
            return identity1 != null && identity2 != null && !identity1.same(identity2);
×
68
        }
69

70
        static boolean isBothNull(Identity identity1, Identity identity2) {
71
            return identity1 == null && identity2 == null;
1✔
72
        }
73
    }
74

75
    interface Composer<T> extends Function<Object[], T>, Identity {
76
    }
77

78
    interface Decomposer<T> extends Function<T, Object[]>, Identity {
79
    }
80

81
    class DecorateConsistency<T> implements Consistency<T> {
82
        private final Consistency<T> consistency;
83

84
        public DecorateConsistency(Consistency<T> consistency) {
1✔
85
            this.consistency = consistency;
1✔
86
        }
1✔
87

88
        @Override
89
        public Consistency<T> link(ConsistencyItem<T> item) {
90
            return consistency.link(item);
1✔
91
        }
92

93
        @Override
94
        public BeanClass<T> type() {
UNCOV
95
            return consistency.type();
×
96
        }
97

98
        @Override
99
        public Consistency<T> direct(String property) {
100
            return consistency.direct(property);
1✔
101
        }
102

103
        @Override
104
        public <P> C1<T, P> property(String property) {
105
            return consistency.property(property);
1✔
106
        }
107

108
        @Override
109
        public <P1, P2> C2<T, P1, P2> properties(String property1, String property2) {
110
            return consistency.properties(property1, property2);
1✔
111
        }
112

113
        @Override
114
        public <P1, P2, P3> C3<T, P1, P2, P3> properties(String property1, String property2, String property3) {
UNCOV
115
            return consistency.properties(property1, property2, property3);
×
116
        }
117

118
        @Override
119
        public CN<T> properties(String... properties) {
120
            return consistency.properties(properties);
1✔
121
        }
122
    }
123

124
    class C1<T, P> extends DecorateConsistency<T> {
125
        private final ConsistencyItem<T> lastItem;
126

127
        public C1(Consistency<T> origin, ConsistencyItem<T> lastItem) {
128
            super(origin);
1✔
129
            link(this.lastItem = lastItem);
1✔
130
        }
1✔
131

132
        @SuppressWarnings("unchecked")
133
        public C1<T, P> read(Function<P, T> composer) {
134
            lastItem.setComposer(new ComposerWrapper<>(objs -> composer.apply((P) objs[0]), composer));
1✔
135
            return this;
1✔
136
        }
137

138
        public C1<T, P> write(Function<T, P> decomposer) {
139
            lastItem.setDecomposer(new DecomposerWrapper<>(t -> new Object[]{decomposer.apply(t)}, decomposer));
1✔
140
            return this;
1✔
141
        }
142
    }
143

144
    class MultiPropertyConsistency<T, C extends MultiPropertyConsistency<T, C>> extends DecorateConsistency<T> {
145
        protected final ConsistencyItem<T> lastItem;
146

147
        public MultiPropertyConsistency(Consistency<T> origin, ConsistencyItem<T> lastItem) {
148
            super(origin);
1✔
149
            this.lastItem = lastItem;
1✔
150
            link(lastItem);
1✔
151
        }
1✔
152

153
        @SuppressWarnings("unchecked")
154
        public C read(Function<Object[], T> composer) {
155
            lastItem.setComposer(new ComposerWrapper<>(composer, composer));
1✔
156
            return (C) this;
1✔
157
        }
158

159
        @SuppressWarnings("unchecked")
160
        public C write(Function<T, Object[]> decomposer) {
161
            lastItem.setDecomposer(new DecomposerWrapper<>(decomposer, decomposer));
1✔
162
            return (C) this;
1✔
163
        }
164
    }
165

166
    class C2<T, P1, P2> extends MultiPropertyConsistency<T, C2<T, P1, P2>> {
167
        public C2(Consistency<T> origin, ConsistencyItem<T> lastItem) {
168
            super(origin, lastItem);
1✔
169
        }
1✔
170

171
        @SuppressWarnings("unchecked")
172
        public C2<T, P1, P2> read(BiFunction<P1, P2, T> composer) {
173
            lastItem.setComposer(new ComposerWrapper<>(objs -> composer.apply((P1) objs[0], (P2) objs[1]), composer));
1✔
174
            return this;
1✔
175
        }
176

177
        public C2<T, P1, P2> write(Function<T, P1> decompose1, Function<T, P2> decompose2) {
178
            lastItem.setDecomposer(new DecomposerWrapper<>(
1✔
179
                    t -> new Object[]{decompose1.apply(t), decompose2.apply(t)}, asList(decompose1, decompose2)));
1✔
180
            return this;
1✔
181
        }
182
    }
183

184
    class C3<T, P1, P2, P3> extends MultiPropertyConsistency<T, C3<T, P1, P2, P3>> {
185
        public C3(Consistency<T> origin, ConsistencyItem<T> lastItem) {
UNCOV
186
            super(origin, lastItem);
×
UNCOV
187
        }
×
188

189
        @SuppressWarnings("unchecked")
190
        public C3<T, P1, P2, P3> read(TriFunction<P1, P2, P3, T> composer) {
UNCOV
191
            lastItem.setComposer(new ComposerWrapper<>(objs -> composer.apply((P1) objs[0], (P2) objs[1], (P3) objs[2]), composer));
×
UNCOV
192
            return this;
×
193
        }
194

195
        public C3<T, P1, P2, P3> write(Function<T, P1> decompose1, Function<T, P2> decompose2, Function<T, P3> decompose3) {
UNCOV
196
            lastItem.setDecomposer(new DecomposerWrapper<>(
×
UNCOV
197
                    t -> new Object[]{decompose1.apply(t), decompose2.apply(t), decompose3.apply(t)},
×
UNCOV
198
                    asList(decompose1, decompose2, decompose3)));
×
UNCOV
199
            return this;
×
200
        }
201
    }
202

203
    class CN<T> extends MultiPropertyConsistency<T, CN<T>> {
204
        public CN(Consistency<T> origin, ConsistencyItem<T> lastItem) {
205
            super(origin, lastItem);
1✔
206
        }
1✔
207
    }
208
}
209

210
class IdentityAction implements Consistency.Identity {
211
    protected final Object identity;
212
    private final StackTraceElement location;
213

214
    public IdentityAction(Object identity) {
1✔
215
        this.identity = Objects.requireNonNull(identity);
1✔
216
        location = guessCustomerPositionStackTrace();
1✔
217
    }
1✔
218

219
    @Override
220
    public Object identity() {
221
        return identity;
1✔
222
    }
223

224
    @Override
225
    public StackTraceElement getLocation() {
226
        return location;
1✔
227
    }
228
}
229

230
class ComposerWrapper<T> extends IdentityAction implements Consistency.Composer<T> {
231
    private final Function<Object[], T> action;
232

233
    ComposerWrapper(Function<Object[], T> action, Object identity) {
234
        super(identity);
1✔
235
        this.action = Objects.requireNonNull(action);
1✔
236
    }
1✔
237

238
    @Override
239
    public T apply(Object[] objects) {
240
        return action.apply(objects);
1✔
241
    }
242
}
243

244
class DecomposerWrapper<T> extends IdentityAction implements Consistency.Decomposer<T> {
245
    private final Function<T, Object[]> action;
246

247
    DecomposerWrapper(Function<T, Object[]> action, Object identity) {
248
        super(identity);
1✔
249
        this.action = Objects.requireNonNull(action);
1✔
250
    }
1✔
251

252
    @Override
253
    public Object[] apply(T t) {
254
        return action.apply(t);
1✔
255
    }
256
}
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