/**
  * Returns a composed {@link ShortUnaryOperator} that first applies this operator to its input,
  * and then applies the {@code recover} operation if a {@link Throwable} is thrown from this one.
  * The {@code recover} operation is represented by a curried operation which is called with
  * throwable information and same argument of this operator.
  *
  * @param recover The operation to apply if this operator throws a {@code Throwable}
  * @return A composed {@link ShortUnaryOperator} that first applies this operator to its input,
  *     and then applies the {@code recover} operation if a {@code Throwable} is thrown from this
  *     one.
  * @throws NullPointerException If given argument or the returned enclosing operator is {@code
  *     null}
  * @implSpec The implementation checks that the returned enclosing operator from {@code recover}
  *     operation is not {@code null}. If it is, then a {@link NullPointerException} with
  *     appropriate message is thrown.
  * @implNote If thrown {@code Throwable} is of type {@link Error}, it is thrown as-is and thus not
  *     passed to {@code recover} operation.
  */
 @Nonnull
 default ShortUnaryOperator recover(
     @Nonnull final Function<? super Throwable, ? extends ShortUnaryOperator> recover) {
   Objects.requireNonNull(recover);
   return (value) -> {
     try {
       return this.applyAsShortThrows(value);
     } catch (Error e) {
       throw e;
     } catch (Throwable throwable) {
       final ShortUnaryOperator operator = recover.apply(throwable);
       Objects.requireNonNull(
           operator,
           () ->
               "recover returned null for "
                   + throwable.getClass()
                   + ": "
                   + throwable.getMessage());
       return operator.applyAsShort(value);
     }
   };
 }
Exemple #2
0
 /**
  * Returns a composed {@link ShortFunction} that first applies the {@code before} operator to its
  * input, and then applies this function to the result. If evaluation of either operation throws
  * an exception, it is relayed to the caller of the composed operation. This method is just
  * convenience, to provide the ability to execute an operation which accepts {@code short} input,
  * before this primitive function is executed.
  *
  * @param before The operator to apply before this function is applied
  * @return A composed {@code ShortFunction} that first applies the {@code before} operator to its
  *     input, and then applies this function to the result.
  * @throws NullPointerException If given argument is {@code null}
  * @implSpec The input argument of this method is a able to handle primitive values. In this case
  *     this is {@code short}.
  */
 @Nonnull
 default ShortFunction<R> composeFromShort(@Nonnull final ShortUnaryOperator before) {
   Objects.requireNonNull(before);
   return (value) -> apply(before.applyAsShort(value));
 }
 /**
  * Calls the given {@link ShortUnaryOperator} with the given argument and returns its result.
  *
  * @param operator The operator to be called
  * @param value The argument to the operator
  * @return The result from the given {@code ShortUnaryOperator}.
  * @throws NullPointerException If given argument is {@code null}
  */
 static short call(@Nonnull final ShortUnaryOperator operator, short value) {
   Objects.requireNonNull(operator);
   return operator.applyAsShort(value);
 }
 /**
  * Returns a composed {@link ShortUnaryOperator} that first applies this operator to its input,
  * and then applies the {@code after} operator to the result. If evaluation of either operation
  * throws an exception, it is relayed to the caller of the composed operation. This method is just
  * convenience, to provide the ability to transform this primitive operator to an operation
  * returning {@code short}.
  *
  * @param after The operator to apply after this operator is applied
  * @return A composed {@code ShortUnaryOperator} that first applies this operator to its input,
  *     and then applies the {@code after} operator to the result.
  * @throws NullPointerException If given argument is {@code null}
  * @implSpec The input argument of this method is a able to return primitive values. In this case
  *     this is {@code short}.
  */
 @Nonnull
 default ShortUnaryOperator andThenToShort(@Nonnull final ShortUnaryOperator after) {
   Objects.requireNonNull(after);
   return (value) -> after.applyAsShort(applyAsShort(value));
 }