| 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.BinaryOperator; | |
| 19 | ||
| 20 | import static java.util.Objects.requireNonNull; | |
| 21 | ||
| 22 | /** | |
| 23 | * Represents an operation upon two operands of the same type, producing a result | |
| 24 | * of the same type as the operands. This is a specialization of | |
| 25 | * {@link ThrowingBiFunction} for the case where the operands and the result are all of | |
| 26 | * the same type. | |
| 27 | * | |
| 28 | * <p>This is a <a href="package-summary.html">functional interface</a> | |
| 29 | * whose functional method is {@link #apply(Object, Object)}. | |
| 30 | * | |
| 31 | * @param <T> the type of the operands and result of the operator | |
| 32 | * @param <E> the type of the thrown checked exception | |
| 33 | * | |
| 34 | * @author Grzegorz Piwowarek | |
| 35 | * @see ThrowingBiFunction | |
| 36 | * @see ThrowingUnaryOperator | |
| 37 | */ | |
| 38 | public interface ThrowingBinaryOperator<T, E extends Exception> extends ThrowingBiFunction<T, T, T, E> { | |
| 39 | ||
| 40 | /** | |
| 41 | * Returns a new BinaryOperator instance which wraps the thrown checked exception instance into a {@link CheckedException} | |
| 42 | * | |
| 43 | * @param <T> the type of the operands and result of the operator | |
| 44 | * @param function the ThrowingBinaryOperator to wrap | |
| 45 | * @return BinaryOperator instance that wraps the checked exception into a {@link CheckedException} | |
| 46 | */ | |
| 47 | static <T> BinaryOperator<T> unchecked(ThrowingBinaryOperator<T, ?> function) { | |
| 48 | requireNonNull(function); | |
| 49 |
1
1. unchecked : replaced return value with null for com/pivovarit/function/ThrowingBinaryOperator::unchecked → KILLED |
return (arg1, arg2) -> { |
| 50 | try { | |
| 51 |
1
1. lambda$unchecked$0 : replaced return value with null for com/pivovarit/function/ThrowingBinaryOperator::lambda$unchecked$0 → SURVIVED |
return function.apply(arg1, arg2); |
| 52 | } catch (final Exception e) { | |
| 53 | throw new CheckedException(e); | |
| 54 | } | |
| 55 | }; | |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * Returns a new BinaryOperator instance which rethrows the checked exception using the Sneaky Throws pattern | |
| 60 | * | |
| 61 | * @param <T> the type of the operands and result of the operator | |
| 62 | * @param function the ThrowingBinaryOperator to wrap | |
| 63 | * @return BinaryOperator instance that rethrows the checked exception using the Sneaky Throws pattern | |
| 64 | */ | |
| 65 | static <T> BinaryOperator<T> sneaky(ThrowingBinaryOperator<T, ?> function) { | |
| 66 | requireNonNull(function); | |
| 67 |
1
1. sneaky : replaced return value with null for com/pivovarit/function/ThrowingBinaryOperator::sneaky → KILLED |
return (t1, t2) -> { |
| 68 | try { | |
| 69 |
1
1. lambda$sneaky$0 : replaced return value with null for com/pivovarit/function/ThrowingBinaryOperator::lambda$sneaky$0 → NO_COVERAGE |
return function.apply(t1, t2); |
| 70 | } catch (final Exception e) { | |
| 71 |
1
1. lambda$sneaky$0 : replaced return value with null for com/pivovarit/function/ThrowingBinaryOperator::lambda$sneaky$0 → NO_COVERAGE |
return SneakyThrowUtil.sneakyThrow(e); |
| 72 | } | |
| 73 | }; | |
| 74 | } | |
| 75 | } | |
Mutations | ||
| 49 |
1.1 |
|
| 51 |
1.1 |
|
| 67 |
1.1 |
|
| 69 |
1.1 |
|
| 71 |
1.1 |