ThrowingBiConsumer.java

1
/*
2
 * Copyright 2014-2016 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.function;
17
18
import java.util.function.BiConsumer;
19
20
import static java.util.Objects.requireNonNull;
21
22
/**
23
 * Represents an operation that accepts two input arguments and returns no
24
 * result.  This is the two-arity specialization of {@link ThrowingConsumer}.
25
 * Unlike most other functional interfaces, {@code ThrowingBiConsumer}  is expected
26
 * to operate via side-effects.
27
 *
28
 * @param <T1> the type of the first argument to the operation
29
 * @param <T2> the type of the second argument to the operation
30
 * @param <EX> the type of the thrown checked exception
31
 *
32
 * @author Grzegorz Piwowarek
33
 * @see ThrowingConsumer
34
 */
35
@FunctionalInterface
36
public interface ThrowingBiConsumer<T1, T2, EX extends Exception> {
37
38
    /**
39
     * Performs this operation on the given arguments.
40
     *
41
     * @param t  the first input argument
42
     * @param t2 the second input argument
43
     * @throws EX the checked exception type
44
     */
45
    void accept(T1 t, T2 t2) throws EX;
46
47
    /**
48
     * Returns a new BiConsumer instance which wraps the thrown checked exception instance into a {@link CheckedException}
49
     *
50
     * @param <T>      the type of the first argument to the operation
51
     * @param <U>      the type of the second argument to the operation
52
     * @param consumer the ThrowingBiConsumer to wrap
53
     * @return BiConsumer instance that wraps the checked exception into a {@link CheckedException}
54
     */
55
    static <T, U> BiConsumer<T, U> unchecked(ThrowingBiConsumer<? super T, ? super U, ?> consumer) {
56
        requireNonNull(consumer);
57 1 1. unchecked : replaced return value with null for com/pivovarit/function/ThrowingBiConsumer::unchecked → KILLED
        return (arg1, arg2) -> {
58
            try {
59 1 1. lambda$unchecked$0 : removed call to com/pivovarit/function/ThrowingBiConsumer::accept → KILLED
                consumer.accept(arg1, arg2);
60
            } catch (final Exception e) {
61
                throw new CheckedException(e);
62
            }
63
        };
64
    }
65
66
    /**
67
     * Returns a new BiConsumer instance which rethrows the checked exception using the Sneaky Throws pattern
68
     *
69
     * @param <T>      the type of the first argument to the operation
70
     * @param <U>      the type of the second argument to the operation
71
     * @param consumer the ThrowingBiConsumer to wrap
72
     * @return BiConsumer instance that rethrows the checked exception using the Sneaky Throws pattern
73
     */
74
    static <T, U> BiConsumer<T, U> sneaky(ThrowingBiConsumer<? super T, ? super U, ?> consumer) {
75
        requireNonNull(consumer);
76 1 1. sneaky : replaced return value with null for com/pivovarit/function/ThrowingBiConsumer::sneaky → KILLED
        return (arg1, arg2) -> {
77
            try {
78 1 1. lambda$sneaky$0 : removed call to com/pivovarit/function/ThrowingBiConsumer::accept → KILLED
                consumer.accept(arg1, arg2);
79
            } catch (final Exception e) {
80
                SneakyThrowUtil.sneakyThrow(e);
81
            }
82
        };
83
    }
84
}

Mutations

57

1.1
Location : unchecked
Killed by : com.pivovarit.function.ThrowingBiConsumerTest.[engine:junit-jupiter]/[class:com.pivovarit.function.ThrowingBiConsumerTest]/[method:shouldConsumeUnchecked()]
replaced return value with null for com/pivovarit/function/ThrowingBiConsumer::unchecked → KILLED

59

1.1
Location : lambda$unchecked$0
Killed by : com.pivovarit.function.ThrowingBiConsumerTest.[engine:junit-jupiter]/[class:com.pivovarit.function.ThrowingBiConsumerTest]/[method:shouldConsumeAndThrowUnchecked()]
removed call to com/pivovarit/function/ThrowingBiConsumer::accept → KILLED

76

1.1
Location : sneaky
Killed by : com.pivovarit.function.ThrowingBiConsumerTest.[engine:junit-jupiter]/[class:com.pivovarit.function.ThrowingBiConsumerTest]/[method:shouldConsumeAndSneakyThrow()]
replaced return value with null for com/pivovarit/function/ThrowingBiConsumer::sneaky → KILLED

78

1.1
Location : lambda$sneaky$0
Killed by : com.pivovarit.function.ThrowingBiConsumerTest.[engine:junit-jupiter]/[class:com.pivovarit.function.ThrowingBiConsumerTest]/[method:shouldConsumeAndSneakyThrow()]
removed call to com/pivovarit/function/ThrowingBiConsumer::accept → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support