| 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.util.Objects; | |
| 19 | import java.util.concurrent.Executor; | |
| 20 | import java.util.concurrent.ThreadPoolExecutor; | |
| 21 | ||
| 22 | final class Preconditions { | |
| 23 | ||
| 24 | private Preconditions() { | |
| 25 | } | |
| 26 | ||
| 27 | static void requireValidParallelism(int parallelism) { | |
| 28 |
2
1. requireValidParallelism : negated conditional → KILLED 2. requireValidParallelism : changed conditional boundary → KILLED |
if (parallelism < 1) { |
| 29 | throw new IllegalArgumentException("Parallelism can't be lower than 1"); | |
| 30 | } | |
| 31 | } | |
| 32 | ||
| 33 | static void requireValidExecutor(Executor executor) { | |
| 34 | Objects.requireNonNull(executor, "Executor can't be null"); | |
| 35 |
1
1. requireValidExecutor : negated conditional → KILLED |
if (executor instanceof ThreadPoolExecutor tpe) { |
| 36 | switch (tpe.getRejectedExecutionHandler()) { | |
| 37 | case ThreadPoolExecutor.DiscardPolicy ignored -> | |
| 38 | throw new IllegalArgumentException("Executor's RejectedExecutionHandler can't discard tasks"); | |
| 39 | case ThreadPoolExecutor.DiscardOldestPolicy ignored -> | |
| 40 | throw new IllegalArgumentException("Executor's RejectedExecutionHandler can't discard tasks"); | |
| 41 | default -> { | |
| 42 | // no-op | |
| 43 | } | |
| 44 | } | |
| 45 | } | |
| 46 | } | |
| 47 | } | |
Mutations | ||
| 28 |
1.1 2.2 |
|
| 35 |
1.1 |