All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.lunisolar.magma.func.function.conversion.LShortToDoubleFunctionX Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
/*
 * This file is part of "lunisolar-magma".
 *
 * (C) Copyright 2015 Lunisolar (http://lunisolar.eu/).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package eu.lunisolar.magma.func.function.conversion;
import javax.annotation.Nonnull; // NOSONAR
import javax.annotation.Nullable; // NOSONAR
import java.util.Comparator; // NOSONAR
import java.util.Objects; // NOSONAR
import eu.lunisolar.magma.basics.*; //NOSONAR
import eu.lunisolar.magma.basics.builder.*; // NOSONAR
import eu.lunisolar.magma.basics.exceptions.*; // NOSONAR
import eu.lunisolar.magma.basics.meta.*; // NOSONAR
import eu.lunisolar.magma.basics.meta.functional.*; // NOSONAR
import eu.lunisolar.magma.basics.meta.functional.type.*; // NOSONAR
import eu.lunisolar.magma.basics.meta.functional.domain.*; // NOSONAR
import eu.lunisolar.magma.func.*; // NOSONAR
import eu.lunisolar.magma.func.operator.unary.*; // NOSONAR
import eu.lunisolar.magma.func.operator.binary.*; // NOSONAR
import eu.lunisolar.magma.func.operator.ternary.*; // NOSONAR
import eu.lunisolar.magma.func.function.*; // NOSONAR
import eu.lunisolar.magma.func.function.from.*; // NOSONAR
import eu.lunisolar.magma.func.function.to.*; // NOSONAR
import eu.lunisolar.magma.func.function.conversion.*; // NOSONAR
import eu.lunisolar.magma.func.predicate.*; // NOSONAR
import eu.lunisolar.magma.func.supplier.*; // NOSONAR
import eu.lunisolar.magma.func.consumer.*; // NOSONAR
import eu.lunisolar.magma.func.consumer.primitives.*; // NOSONAR
import eu.lunisolar.magma.func.consumer.primitives.bi.*; // NOSONAR
import eu.lunisolar.magma.func.consumer.primitives.tri.*; // NOSONAR
import eu.lunisolar.magma.func.consumer.primitives.obj.*; // NOSONAR
import eu.lunisolar.magma.func.action.*; // NOSONAR

/**
 * Throwing functional interface (lambda) LShortToDoubleFunctionX for Java 8.
 *
 * Type: function
 *
 * Domain (lvl: 1): short s
 *
 * Co-domain: none
 *
 * @see LShortToDoubleFunction
 */
@FunctionalInterface
@SuppressWarnings("UnusedDeclaration")
public interface LShortToDoubleFunctionX extends MetaFunction, PrimitiveCodomain, MetaInterface.Throwing { // NOSONAR

	static final String DESCRIPTION = "LShortToDoubleFunctionX: double doApplyAsDouble(short s) throws X";

	double doApplyAsDouble(short s) throws X;

	/** Function call that handles exceptions by always nesting checked exceptions and propagating the otheres as is. */
	default double nestingDoApplyAsDouble(short s) {
		try {
			return this.doApplyAsDouble(s);
		} catch (RuntimeException | Error e) { // NOSONAR
			throw e;
		} catch (Throwable e) { // NOSONAR
			throw new NestedException(e);
		}
	}

	/** Function call that handles exceptions by always propagating them as is even when they are undeclared checked ones. */
	default double shovingDoApplyAsDouble(short s) {
		return ((LShortToDoubleFunctionX) this).doApplyAsDouble(s);
	}

	/** Function call that handles exceptions according to the instructions. */
	default  double handlingDoApplyAsDouble(short s, HandlingInstructions handling) throws Y {

		try {
			return this.doApplyAsDouble(s);
		} catch (Throwable e) { // NOSONAR
			throw Handler.handleOrNest(e, handling);
		}
	}

	/** Just to mirror the method: Ensures the result is not null */
	default double nonNullDoApplyAsDouble(short s) throws X {
		return doApplyAsDouble(s);
	}

	/** Returns description of the functional interface. */
	@Nonnull
	default String functionalInterfaceDescription() {
		return LShortToDoubleFunctionX.DESCRIPTION;
	}

	/** Captures arguments but delays the evaluation. */
	default LDoubleSupplierX captureShortToDoubleFunc(short s) {
		return () -> this.doApplyAsDouble(s);
	}

	/** Creates function that always returns the same value. */
	static  LShortToDoubleFunctionX constant(double r) {
		return s -> r;
	}

	/** Convenient method in case lambda expression is ambiguous for the compiler (that might happen for overloaded methods accepting different interfaces). */
	@Nonnull
	static  LShortToDoubleFunctionX lX(final @Nonnull LShortToDoubleFunctionX lambda) {
		Null.nonNullArg(lambda, "lambda");
		return lambda;
	}

	/** Convenient method in case lambda expression is ambiguous for the compiler (that might happen for overloaded methods accepting different interfaces). */
	@Nonnull
	static  LShortToDoubleFunctionX lX(@Nonnull Class xClass, final @Nonnull LShortToDoubleFunctionX lambda) {
		Null.nonNullArg(lambda, "lambda");
		return lambda;
	}

	// 

	/** Wraps opposite (throwing vs non-throwing) instance. */
	@Nonnull
	static  LShortToDoubleFunctionX wrapX(final @Nonnull LShortToDoubleFunction other) {
		return (LShortToDoubleFunctionX) other;
	}

	// 

	// 

	/** Allows to manipulate the domain of the function. */
	@Nonnull
	default LShortToDoubleFunctionX shortToDoubleFuncComposeShort(@Nonnull final LShortUnaryOperatorX before1) {
		Null.nonNullArg(before1, "before1");
		return v1 -> this.doApplyAsDouble(before1.doApplyAsShort(v1));
	}

	/** Allows to manipulate the domain of the function. */
	@Nonnull
	default  LToDoubleFunctionX shortToDoubleFuncCompose(@Nonnull final LToShortFunctionX before1) {
		Null.nonNullArg(before1, "before1");
		return v1 -> this.doApplyAsDouble(before1.doApplyAsShort(v1));
	}

	// 

	// 

	/** Combines two functions together in a order. */
	@Nonnull
	default  LShortFunctionX then(@Nonnull LDoubleFunctionX after) {
		Null.nonNullArg(after, "after");
		return s -> after.doApply(this.doApplyAsDouble(s));
	}

	/** Combines two functions together in a order. */
	@Nonnull
	default LShortToByteFunctionX thenToByte(@Nonnull LDoubleToByteFunctionX after) {
		Null.nonNullArg(after, "after");
		return s -> after.doApplyAsByte(this.doApplyAsDouble(s));
	}

	/** Combines two functions together in a order. */
	@Nonnull
	default LShortUnaryOperatorX thenToShort(@Nonnull LDoubleToShortFunctionX after) {
		Null.nonNullArg(after, "after");
		return s -> after.doApplyAsShort(this.doApplyAsDouble(s));
	}

	/** Combines two functions together in a order. */
	@Nonnull
	default LShortToIntFunctionX thenToInt(@Nonnull LDoubleToIntFunctionX after) {
		Null.nonNullArg(after, "after");
		return s -> after.doApplyAsInt(this.doApplyAsDouble(s));
	}

	/** Combines two functions together in a order. */
	@Nonnull
	default LShortToLongFunctionX thenToLong(@Nonnull LDoubleToLongFunctionX after) {
		Null.nonNullArg(after, "after");
		return s -> after.doApplyAsLong(this.doApplyAsDouble(s));
	}

	/** Combines two functions together in a order. */
	@Nonnull
	default LShortToFloatFunctionX thenToFloat(@Nonnull LDoubleToFloatFunctionX after) {
		Null.nonNullArg(after, "after");
		return s -> after.doApplyAsFloat(this.doApplyAsDouble(s));
	}

	/** Combines two functions together in a order. */
	@Nonnull
	default LShortToDoubleFunctionX thenToDouble(@Nonnull LDoubleUnaryOperatorX after) {
		Null.nonNullArg(after, "after");
		return s -> after.doApplyAsDouble(this.doApplyAsDouble(s));
	}

	/** Combines two functions together in a order. */
	@Nonnull
	default LShortToCharFunctionX thenToChar(@Nonnull LDoubleToCharFunctionX after) {
		Null.nonNullArg(after, "after");
		return s -> after.doApplyAsChar(this.doApplyAsDouble(s));
	}

	/** Combines two functions together in a order. */
	@Nonnull
	default LShortPredicateX thenToBoolean(@Nonnull LDoublePredicateX after) {
		Null.nonNullArg(after, "after");
		return s -> after.doTest(this.doApplyAsDouble(s));
	}

	// 
	// 

	/** Converts to non-throwing variant (if required). */
	@Nonnull
	default LShortToDoubleFunction nestingShortToDoubleFunc() {
		return this::nestingDoApplyAsDouble;
	}

	/** Converts to throwing variant (RuntimeException). */
	@Nonnull
	default LShortToDoubleFunctionX nestingShortToDoubleFuncX() {
		return this::nestingDoApplyAsDouble;
	}

	/** Converts to non-throwing variant that will propagate checked exception as it would be unchecked - there is no exception wrapping involved (at least not here). */
	default LShortToDoubleFunction shovingShortToDoubleFunc() {
		return this::shovingDoApplyAsDouble;
	}

	/** Converts to throwing variant (RuntimeException) that will propagate checked exception as it would be unchecked - there is no exception wrapping involved (at least not here). */
	default LShortToDoubleFunctionX shovingShortToDoubleFuncX() {
		return this::shovingDoApplyAsDouble;
	}

	// 

	// 

	/** Converts to function that handles exceptions according to the instructions. */
	@Nonnull
	default LShortToDoubleFunction handleShortToDoubleFunc(@Nonnull HandlingInstructions handling) {
		return s -> this.handlingDoApplyAsDouble(s, handling);
	}

	/** Converts to function that handles exceptions according to the instructions. */
	@Nonnull
	default  LShortToDoubleFunctionX handleShortToDoubleFuncX(@Nonnull HandlingInstructions handling) {
		return s -> this.handlingDoApplyAsDouble(s, handling);
	}

	// 

}