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

trydofor / professional-mirana / #68

31 Aug 2024 02:56AM UTC coverage: 84.4% (+1.0%) from 83.382%
#68

push

web-flow
Merge pull request #45 from trydofor/develop

v2.7.3 with minor change

474 of 568 new or added lines in 27 files covered. (83.45%)

8 existing lines in 6 files now uncovered.

5237 of 6205 relevant lines covered (84.4%)

0.84 hits per line

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

0.0
/src/main/java/pro/fessional/mirana/cond/IfSetter.java
1
package pro.fessional.mirana.cond;
2

3
import org.jetbrains.annotations.Contract;
4
import org.jetbrains.annotations.NotNull;
5
import org.jetbrains.annotations.Nullable;
6

7
import java.util.function.Consumer;
8
import java.util.function.Predicate;
9

10
/**
11
 * <pre>
12
 * should Partial/Conditional set property from Source(of) to Target(to)
13
 * - null/nonnull is nullability
14
 * - invalid/valid is business validation
15
 * </pre>
16
 *
17
 * @author trydofor
18
 * @since 2024-07-01
19
 */
20
public interface IfSetter<S, T> {
21

NEW
22
    enum Absent {
×
NEW
23
        Any,
×
NEW
24
        Null,
×
NEW
25
        Invalid
×
26
    }
27

NEW
28
    enum Present {
×
NEW
29
        Any,
×
NEW
30
        Nonnull,
×
NEW
31
        Valid
×
32
    }
33

34
    /**
35
     * should set source's props to target on target absent and source present.
36
     */
37
    @Contract("_,_,_,_->param1")
38
    T set(@NotNull T target, @Nullable S source, @NotNull Absent to, @NotNull Present of);
39

40
    /**
41
     * should set any source's props to target
42
     */
43
    @Contract("_,_->param1")
44
    default T toAny(@NotNull T target, @Nullable S source) {
NEW
45
        return set(target, source, Absent.Any, Present.Any);
×
46
    }
47

48
    /**
49
     * should set source's props to target if target's is null
50
     */
51
    @Contract("_,_->param1")
52
    default T toNull(@NotNull T target, @Nullable S source) {
NEW
53
        return set(target, source, Absent.Null, Present.Any);
×
54
    }
55

56
    /**
57
     * should set source's props to target if target's is invalid
58
     */
59
    @Contract("_,_->param1")
60
    default T toInvalid(@NotNull T target, @Nullable S source) {
NEW
61
        return set(target, source, Absent.Invalid, Present.Any);
×
62
    }
63

64

65
    /**
66
     * should set non-null source's props to target
67
     */
68
    @Contract("_,_->param1")
69
    default T ofNonnull(@NotNull T target, @Nullable S source) {
NEW
70
        return set(target, source, Absent.Any, Present.Nonnull);
×
71
    }
72

73
    /**
74
     * should set valid source's props to target
75
     */
76
    @Contract("_,_->param1")
77
    default T ofValid(@NotNull T target, @Nullable S source) {
NEW
78
        return set(target, source, Absent.Any, Present.Valid);
×
79
    }
80

81
    /**
82
     * should set if value is not null
83
     */
84
    static <T> void nonnull(@NotNull Consumer<T> setter, @Nullable T value) {
NEW
85
        if (value != null) setter.accept(value);
×
NEW
86
    }
×
87

88
    /**
89
     * should set if valid
90
     */
91
    static <T> void valid(@NotNull Consumer<T> setter, @Nullable T value, boolean valid) {
NEW
92
        if (valid) setter.accept(value);
×
NEW
93
    }
×
94

95
    /**
96
     * should set if validated value is valid
97
     */
98
    static <T> void valid(@NotNull Consumer<T> setter, @Nullable T value, @NotNull Predicate<T> validate) {
NEW
99
        if (validate.test(value)) setter.accept(value);
×
NEW
100
    }
×
101

102
    /**
103
     * should set if not valid
104
     */
105
    static <T> void invalid(@NotNull Consumer<T> setter, @Nullable T value, boolean valid) {
NEW
106
        if (!valid) setter.accept(value);
×
NEW
107
    }
×
108

109
    /**
110
     * should set if validated value is not valid
111
     */
112
    static <T> void invalid(@NotNull Consumer<T> setter, @Nullable T value, @NotNull Predicate<T> validate) {
NEW
113
        if (!validate.test(value)) setter.accept(value);
×
NEW
114
    }
×
115
}
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