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

eu.lunisolar.magma.func.operator.unary.LDoubleUnaryOperatorX 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.operator.unary;
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) LDoubleUnaryOperatorX for Java 8.
 *
 * Type: operator
 *
 * Domain (lvl: 1): double d
 *
 * Co-domain: none
 *
 * @see LDoubleUnaryOperator
 */
@FunctionalInterface
@SuppressWarnings("UnusedDeclaration")
public interface LDoubleUnaryOperatorX extends java.util.function.DoubleUnaryOperator, MetaOperator, PrimitiveCodomain, MetaInterface.Throwing { // NOSONAR

	static final String DESCRIPTION = "LDoubleUnaryOperatorX: double doApplyAsDouble(double d) throws X";

	/**
	 * Default implementation for JRE method that calls exception nesting method.
	 * @deprecated Calling this method via LDoubleUnaryOperatorX interface should be discouraged.
	 */
	@Override
	@Deprecated
	default double applyAsDouble(double d) {
		return this.nestingDoApplyAsDouble(d);
	}

	double doApplyAsDouble(double d) throws X;

	/** Function call that handles exceptions by always nesting checked exceptions and propagating the otheres as is. */
	default double nestingDoApplyAsDouble(double d) {
		try {
			return this.doApplyAsDouble(d);
		} 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(double d) {
		return ((LDoubleUnaryOperatorX) this).doApplyAsDouble(d);
	}

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

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

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

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

	/** Captures arguments but delays the evaluation. */
	default LDoubleSupplierX captureDoubleUnaryOp(double d) {
		return () -> this.doApplyAsDouble(d);
	}

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

	/** Convenient method in case lambda expression is ambiguous for the compiler (that might happen for overloaded methods accepting different interfaces). */
	@Nonnull
	static  LDoubleUnaryOperatorX lX(final @Nonnull LDoubleUnaryOperatorX 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  LDoubleUnaryOperatorX lX(@Nonnull Class xClass, final @Nonnull LDoubleUnaryOperatorX lambda) {
		Null.nonNullArg(lambda, "lambda");
		return lambda;
	}

	// 

	/** Wraps JRE instance. */
	@Nonnull
	static  LDoubleUnaryOperatorX wrap(final java.util.function.DoubleUnaryOperator other) {
		return other::applyAsDouble;
	}

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

	// 

	// 

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

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

	// 

	// 

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

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

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

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

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

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

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

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

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

	// 

	/** Returns a function that always returns its input argument. */
	@Nonnull
	static  LDoubleUnaryOperatorX identity() {
		return t -> t;
	}
	// 

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

	/** Converts to throwing variant (RuntimeException). */
	@Nonnull
	default LDoubleUnaryOperatorX nestingDoubleUnaryOpX() {
		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 LDoubleUnaryOperator shovingDoubleUnaryOp() {
		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 LDoubleUnaryOperatorX shovingDoubleUnaryOpX() {
		return this::shovingDoApplyAsDouble;
	}

	// 

	// 

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

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

	// 

}