1 | package com.pivovarit.collectors; | |
2 | ||
3 | import java.util.HashSet; | |
4 | import java.util.Optional; | |
5 | import java.util.OptionalInt; | |
6 | import java.util.Set; | |
7 | import java.util.concurrent.Executor; | |
8 | ||
9 | import static java.util.Objects.requireNonNull; | |
10 | ||
11 | final class ConfigProcessor { | |
12 | ||
13 | record Configuration(Optional<Boolean> ordered, Optional<Boolean> batching, OptionalInt parallelism, | |
14 | Optional<Executor> executor) { | |
15 | public Configuration { | |
16 | requireNonNull(ordered, "'ordered' can't be null"); | |
17 | requireNonNull(batching, "'batching' can't be null"); | |
18 | requireNonNull(parallelism, "'parallelism' can't be null"); | |
19 | requireNonNull(executor, "'executor' can't be null"); | |
20 | } | |
21 | } | |
22 | ||
23 | static ConfigProcessor.Configuration process(Options.CollectingOption... options) { | |
24 | requireNonNull(options, "options can't be null"); | |
25 | ||
26 | Set<Class<? extends Options.CollectingOption>> seen = new HashSet<>(); | |
27 | ||
28 | Optional<Boolean> batching = Optional.empty(); | |
29 | Optional<Boolean> ordered = Optional.empty(); | |
30 | OptionalInt parallelism = OptionalInt.empty(); | |
31 | Optional<Executor> executor = Optional.empty(); | |
32 | ||
33 | for (var option : options) { | |
34 |
1
1. process : negated conditional → KILLED |
if (!seen.add(option.getClass())) { |
35 | throw new IllegalArgumentException("each option can be used at most once, and you configured '%s' multiple times".formatted(toHumanReadableString(option))); | |
36 | } | |
37 | ||
38 | switch (option) { | |
39 | case Options.Batched __ -> batching = Optional.of(true); | |
40 | case Options.Parallelism parallelismOption -> parallelism = OptionalInt.of(parallelismOption.parallelism()); | |
41 | case Options.ThreadPool threadPoolOption -> executor = Optional.ofNullable(threadPoolOption.executor()); | |
42 | case Options.Ordered __ -> ordered = Optional.of(true); | |
43 | } | |
44 | } | |
45 | ||
46 |
1
1. process : replaced return value with null for com/pivovarit/collectors/ConfigProcessor::process → KILLED |
return new Configuration(ordered, batching, parallelism, executor); |
47 | } | |
48 | ||
49 | private static String toHumanReadableString(Options.CollectingOption option) { | |
50 |
1
1. toHumanReadableString : replaced return value with "" for com/pivovarit/collectors/ConfigProcessor::toHumanReadableString → KILLED |
return switch (option) { |
51 | case Options.Batched __ -> "batching"; | |
52 | case Options.Parallelism __ -> "parallelism"; | |
53 | case Options.ThreadPool __ -> "executor"; | |
54 | case Options.Ordered __ -> "ordered"; | |
55 | }; | |
56 | } | |
57 | } | |
Mutations | ||
34 |
1.1 |
|
46 |
1.1 |
|
50 |
1.1 |