| 1 | /* | |
| 2 | * Copyright 2014-2026 Grzegorz Piwowarek, https://4comprehension.com/ | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package com.pivovarit.collectors; | |
| 17 | ||
| 18 | import java.time.Duration; | |
| 19 | import java.util.ArrayList; | |
| 20 | import java.util.Collections; | |
| 21 | import java.util.HashSet; | |
| 22 | import java.util.List; | |
| 23 | import java.util.Objects; | |
| 24 | import java.util.Set; | |
| 25 | import java.util.concurrent.Executor; | |
| 26 | import java.util.concurrent.TimeUnit; | |
| 27 | import java.util.function.UnaryOperator; | |
| 28 | ||
| 29 | final class ConfigurerState { | |
| 30 | ||
| 31 | private final List<ConfigProcessor.Option> modifiers = new ArrayList<>(); | |
| 32 | private final Set<Class<? extends ConfigProcessor.Option>> seen = new HashSet<>(); | |
| 33 | ||
| 34 | void ordered() { | |
| 35 |
1
1. ordered : removed call to com/pivovarit/collectors/ConfigurerState::addOnce → KILLED |
addOnce(ConfigProcessor.Option.Ordered.INSTANCE); |
| 36 | } | |
| 37 | ||
| 38 | void batching() { | |
| 39 |
1
1. batching : removed call to com/pivovarit/collectors/ConfigurerState::addOnce → KILLED |
addOnce(ConfigProcessor.Option.Batched.INSTANCE); |
| 40 | } | |
| 41 | ||
| 42 | void parallelism(int parallelism) { | |
| 43 |
1
1. parallelism : removed call to com/pivovarit/collectors/ConfigurerState::addOnce → KILLED |
addOnce(new ConfigProcessor.Option.Parallelism(parallelism)); |
| 44 | } | |
| 45 | ||
| 46 | void timeout(long duration, TimeUnit unit) { | |
| 47 |
1
1. timeout : removed call to com/pivovarit/collectors/Preconditions::requireValidTimeout → SURVIVED |
Preconditions.requireValidTimeout(duration, unit); |
| 48 | ||
| 49 |
1
1. timeout : removed call to com/pivovarit/collectors/ConfigurerState::timeout → KILLED |
timeout(Duration.ofNanos(unit.toNanos(duration))); |
| 50 | } | |
| 51 | ||
| 52 | void timeout(Duration duration) { | |
| 53 |
1
1. timeout : removed call to com/pivovarit/collectors/ConfigurerState::addOnce → KILLED |
addOnce(new ConfigProcessor.Option.Timeout(duration)); |
| 54 | } | |
| 55 | ||
| 56 | void executor(Executor executor) { | |
| 57 |
1
1. executor : removed call to com/pivovarit/collectors/ConfigurerState::addOnce → KILLED |
addOnce(new ConfigProcessor.Option.ThreadPool(executor)); |
| 58 | } | |
| 59 | ||
| 60 | void executorDecorator(UnaryOperator<Executor> decorator) { | |
| 61 | Objects.requireNonNull(decorator, "executor decorator can't be null"); | |
| 62 | ||
| 63 |
1
1. executorDecorator : removed call to com/pivovarit/collectors/ConfigurerState::addOnce → KILLED |
addOnce(new ConfigProcessor.Option.ExecutorDecorator(decorator)); |
| 64 | } | |
| 65 | ||
| 66 | void taskDecorator(UnaryOperator<Runnable> decorator) { | |
| 67 | Objects.requireNonNull(decorator, "task decorator can't be null"); | |
| 68 | ||
| 69 |
1
1. taskDecorator : removed call to com/pivovarit/collectors/ConfigurerState::addOnce → KILLED |
addOnce(new ConfigProcessor.Option.TaskDecorator(decorator)); |
| 70 | } | |
| 71 | ||
| 72 | List<ConfigProcessor.Option> getConfig() { | |
| 73 |
1
1. getConfig : replaced return value with Collections.emptyList for com/pivovarit/collectors/ConfigurerState::getConfig → KILLED |
return Collections.unmodifiableList(modifiers); |
| 74 | } | |
| 75 | ||
| 76 | void validate() { | |
| 77 |
2
1. validate : negated conditional → KILLED 2. validate : negated conditional → KILLED |
if (seen.contains(ConfigProcessor.Option.Batched.class) && !seen.contains(ConfigProcessor.Option.Parallelism.class)) { |
| 78 | throw new IllegalStateException("parallelism must be configured when batching is enabled"); | |
| 79 | } | |
| 80 | } | |
| 81 | ||
| 82 | private void addOnce(ConfigProcessor.Option option) { | |
| 83 |
1
1. addOnce : negated conditional → KILLED |
if (!seen.add(option.getClass())) { |
| 84 | throw new IllegalArgumentException("'%s' can only be configured once".formatted(ConfigProcessor.toHumanReadableString(option))); | |
| 85 | } | |
| 86 | modifiers.add(option); | |
| 87 | } | |
| 88 | } | |
Mutations | ||
| 35 |
1.1 |
|
| 39 |
1.1 |
|
| 43 |
1.1 |
|
| 47 |
1.1 |
|
| 49 |
1.1 |
|
| 53 |
1.1 |
|
| 57 |
1.1 |
|
| 63 |
1.1 |
|
| 69 |
1.1 |
|
| 73 |
1.1 |
|
| 77 |
1.1 2.2 |
|
| 83 |
1.1 |