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

valkyrjaio / valkyrja-java / 27861744344

20 Jun 2026 05:37AM UTC coverage: 99.358%. First build
27861744344

Pull #27

github

web-flow
Merge ec3997cb7 into 9d8ae9377
Pull Request #27: [Tests] Reach 100% branch coverage

1557 of 1596 branches covered (97.56%)

Branch coverage included in aggregate %.

56 of 63 new or added lines in 17 files covered. (88.89%)

5713 of 5721 relevant lines covered (99.86%)

4.35 hits per line

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

97.01
/src/main/java/io/valkyrja/http/message/param/abstract_/ParamCollection.java
1
/*
2
 * This file is part of the Valkyrja Framework package.
3
 *
4
 * (c) Melech Mizrachi <melechmizrachi@gmail.com>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9

10
package io.valkyrja.http.message.param.abstract_;
11

12
import io.valkyrja.http.message.param.contract.ParamCollectionContract;
13
import java.util.Arrays;
14
import java.util.LinkedHashMap;
15
import java.util.Map;
16
import java.util.Set;
17
import java.util.stream.Collectors;
18
import org.jspecify.annotations.Nullable;
19

20
public abstract class ParamCollection implements ParamCollectionContract {
21

22
    protected Map<String, Object> params = new LinkedHashMap<>();
5✔
23

24
    public ParamCollection(Map<String, Object> params) {
2✔
25
        validateParams(params);
3✔
26
        this.params = new LinkedHashMap<>(params);
6✔
27
    }
1✔
28

29
    public static ParamCollection fromArray(Map<String, Object> data) {
30
        throw new UnsupportedOperationException("fromArray must be called on a concrete subclass");
5✔
31
    }
32

33
    protected static ParamCollection fromArrayInternal(
34
            Map<String, Object> data,
35
            java.util.function.Function<Map<String, Object>, ParamCollection> constructor) {
36
        Map<String, Object> result = new LinkedHashMap<>();
4✔
37

38
        for (Map.Entry<String, Object> entry : data.entrySet()) {
11✔
39
            Object value = entry.getValue();
3✔
40
            validateParam(value);
2✔
41
            result.put(entry.getKey(), value);
7✔
42
        }
1✔
43

44
        return constructor.apply(result);
5✔
45
    }
46

47
    protected static void validateParam(Object param) {
48
        if (!isValidParam(param)) {
3✔
49
            throw new IllegalArgumentException("Param must be scalar or null");
5✔
50
        }
51
    }
1✔
52

53
    protected static boolean isValidParam(Object param) {
54
        return param == null
24✔
55
                || param instanceof String
56
                || param instanceof Integer
57
                || param instanceof Long
58
                || param instanceof Double
59
                || param instanceof Float
60
                || param instanceof Boolean;
61
    }
62

63
    @Override
64
    public boolean has(String key) {
65
        return params.containsKey(key);
5✔
66
    }
67

68
    @Override
69
    public @Nullable Object get(String key) {
70
        return params.getOrDefault(key, null);
6✔
71
    }
72

73
    @Override
74
    public Map<String, Object> getAll() {
75
        return new LinkedHashMap<>(params);
6✔
76
    }
77

78
    @Override
79
    public Map<String, Object> getOnly(String... keys) {
80
        Set<String> keySet = Arrays.stream(keys).collect(Collectors.toSet());
6✔
81
        return params.entrySet().stream()
7✔
82
                .filter(e -> keySet.contains(e.getKey()))
10✔
83
                .collect(
2✔
84
                        Collectors.toMap(
1✔
85
                                Map.Entry::getKey,
86
                                Map.Entry::getValue,
NEW
87
                                (a, b) -> a,
×
88
                                LinkedHashMap::new));
89
    }
90

91
    @Override
92
    public Map<String, Object> getAllExcept(String... keys) {
93
        Set<String> keySet = Arrays.stream(keys).collect(Collectors.toSet());
6✔
94
        return params.entrySet().stream()
7✔
95
                .filter(e -> !keySet.contains(e.getKey()))
14✔
96
                .collect(
2✔
97
                        Collectors.toMap(
1✔
98
                                Map.Entry::getKey,
99
                                Map.Entry::getValue,
NEW
100
                                (a, b) -> a,
×
101
                                LinkedHashMap::new));
102
    }
103

104
    @Override
105
    public ParamCollectionContract with(Map<String, Object> params) {
106
        validateParams(params);
3✔
107
        ParamCollection copy = copy();
3✔
108
        copy.params = new LinkedHashMap<>(params);
6✔
109
        return copy;
2✔
110
    }
111

112
    @Override
113
    public ParamCollectionContract withAdded(Map<String, Object> params) {
114
        validateParams(params);
3✔
115
        ParamCollection copy = copy();
3✔
116
        copy.params = new LinkedHashMap<>(this.params);
7✔
117
        copy.params.putAll(params);
4✔
118
        return copy;
2✔
119
    }
120

121
    protected void validateParams(Map<String, Object> params) {
122
        for (Object param : params.values()) {
10✔
123
            validateParam(param);
2✔
124
        }
1✔
125
    }
1✔
126

127
    protected abstract ParamCollection copy();
128
}
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