Example usage for java.util.function IntUnaryOperator applyAsInt

List of usage examples for java.util.function IntUnaryOperator applyAsInt

Introduction

In this page you can find the example usage for java.util.function IntUnaryOperator applyAsInt.

Prototype

int applyAsInt(int operand);

Source Link

Document

Applies this operator to the given operand.

Usage

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjIntToIntFunction.java

/**
 * Creates a {@link BiObjIntToIntFunction} which uses the {@code third} parameter of this one as argument for the
 * given {@link IntUnaryOperator}.//from  ww w . j a  v a 2s .c o m
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param operator The operator which accepts the {@code third} parameter of this one
 * @return Creates a {@code BiObjIntToIntFunction} which uses the {@code third} parameter of this one as argument
 * for the given {@code IntUnaryOperator}.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <T, U> BiObjIntToIntFunction<T, U> onlyThird(@Nonnull final IntUnaryOperator operator) {
    Objects.requireNonNull(operator);
    return (t, u, value) -> operator.applyAsInt(value);
}

From source file:com.simiacryptus.mindseye.applications.ArtistryUtil.java

/**
 * Expand plasma tensor./*w w w .  jav  a 2s .  c o  m*/
 *
 * @param seed  the seed
 * @param noise the noise
 * @return the tensor
 */
public static Tensor expandPlasma(final Tensor seed, double noise) {
    int bands = seed.getDimensions()[2];
    int width = seed.getDimensions()[0] * 2;
    int height = seed.getDimensions()[1] * 2;
    Tensor returnValue = new Tensor(width, height, bands);
    DoubleUnaryOperator fn1 = x -> Math.max(Math.min(x + noise * (Math.random() - 0.5), 255), 0);
    DoubleUnaryOperator fn2 = x -> Math.max(Math.min(x + Math.sqrt(2) * noise * (Math.random() - 0.5), 255), 0);
    IntUnaryOperator addrX = x -> {
        while (x >= width)
            x -= width;
        while (x < 0)
            x += width;
        return x;
    };
    IntUnaryOperator addrY = x -> {
        while (x >= height)
            x -= height;
        while (x < 0)
            x += height;
        return x;
    };
    for (int band = 0; band < bands; band++) {
        for (int x = 0; x < width; x += 2) {
            for (int y = 0; y < height; y += 2) {
                double value = seed.get(x / 2, y / 2, band);
                returnValue.set(x, y, band, value);
            }
        }
        for (int x = 1; x < width; x += 2) {
            for (int y = 1; y < height; y += 2) {
                double value = (returnValue.get(addrX.applyAsInt(x - 1), addrY.applyAsInt(y - 1), band))
                        + (returnValue.get(addrX.applyAsInt(x - 1), addrY.applyAsInt(y + 1), band))
                        + (returnValue.get(addrX.applyAsInt(x + 1), addrY.applyAsInt(y - 1), band))
                        + (returnValue.get(addrX.applyAsInt(x + 1), addrY.applyAsInt(y + 1), band));
                value = fn2.applyAsDouble(value / 4);
                returnValue.set(x, y, band, value);
            }
        }
        for (int x = 0; x < width; x += 2) {
            for (int y = 1; y < height; y += 2) {
                double value = (returnValue.get(addrX.applyAsInt(x - 1), addrY.applyAsInt(y), band))
                        + (returnValue.get(addrX.applyAsInt(x + 1), addrY.applyAsInt(y), band))
                        + (returnValue.get(addrX.applyAsInt(x), addrY.applyAsInt(y - 1), band))
                        + (returnValue.get(addrX.applyAsInt(x), addrY.applyAsInt(y + 1), band));
                value = fn1.applyAsDouble(value / 4);
                returnValue.set(x, y, band, value);
            }
        }
        for (int x = 1; x < width; x += 2) {
            for (int y = 0; y < height; y += 2) {
                double value = (returnValue.get(addrX.applyAsInt(x - 1), addrY.applyAsInt(y), band))
                        + (returnValue.get(addrX.applyAsInt(x + 1), addrY.applyAsInt(y), band))
                        + (returnValue.get(addrX.applyAsInt(x), addrY.applyAsInt(y - 1), band))
                        + (returnValue.get(addrX.applyAsInt(x), addrY.applyAsInt(y + 1), band));
                value = fn1.applyAsDouble(value / 4);
                returnValue.set(x, y, band, value);
            }
        }
    }
    return returnValue;
}

From source file:at.gridtec.lambda4j.function.bi.to.ToIntBiFunction2.java

/**
 * Returns a composed {@link ToIntBiFunction2} that first applies this function 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 function to an operation returning {@code int}.
 *
 * @param after The operator to apply after this function is applied
 * @return A composed {@code ToIntBiFunction2} that first applies this function 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
 * int}.//from  w w  w. j  a v  a  2  s . c o m
 */
@Nonnull
default ToIntBiFunction2<T, U> andThenToInt(@Nonnull final IntUnaryOperator after) {
    Objects.requireNonNull(after);
    return (t, u) -> after.applyAsInt(applyAsInt(t, u));
}

From source file:at.gridtec.lambda4j.function.tri.to.ToIntTriFunction.java

/**
 * Returns a composed {@link ToIntTriFunction} that first applies this function 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 function to an operation returning {@code int}.
 *
 * @param after The operator to apply after this function is applied
 * @return A composed {@code ToIntTriFunction} that first applies this function 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
 * int}.//from  www . ja  v a2s.c om
 */
@Nonnull
default ToIntTriFunction<T, U, V> andThenToInt(@Nonnull final IntUnaryOperator after) {
    Objects.requireNonNull(after);
    return (t, u, v) -> after.applyAsInt(applyAsInt(t, u, v));
}

From source file:at.gridtec.lambda4j.function.bi.BiIntFunction.java

/**
 * Returns a composed {@link BiIntFunction} that first applies the {@code before} operators 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 int} input,
 * before this primitive function is executed.
 *
 * @param before1 The first operator to apply before this function is applied
 * @param before2 The second operator to apply before this function is applied
 * @return A composed {@code BiIntFunction} that first applies the {@code before} operators to its input, and then
 * applies this function to the result.//  w  w  w .  j a  va 2 s .com
 * @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
 * int}.
 */
@Nonnull
default BiIntFunction<R> composeFromInt(@Nonnull final IntUnaryOperator before1,
        @Nonnull final IntUnaryOperator before2) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    return (value1, value2) -> apply(before1.applyAsInt(value1), before2.applyAsInt(value2));
}

From source file:at.gridtec.lambda4j.function.bi.obj.ObjIntFunction.java

/**
 * Returns a composed {@link BiIntFunction} that first applies the {@code before} functions 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 int} input,
 * before this primitive function is executed.
 *
 * @param before1 The first function to apply before this function is applied
 * @param before2 The second operator to apply before this function is applied
 * @return A composed {@code BiIntFunction} that first applies the {@code before} functions to its input, and then
 * applies this function to the result.//ww w . j  a  v a 2 s  .  c om
 * @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
 * int}.
 */
@Nonnull
default BiIntFunction<R> composeFromInt(@Nonnull final IntFunction<? extends T> before1,
        @Nonnull final IntUnaryOperator before2) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    return (value1, value2) -> apply(before1.apply(value1), before2.applyAsInt(value2));
}

From source file:at.gridtec.lambda4j.function.bi.conversion.BiBooleanToIntFunction.java

/**
 * Returns a composed {@link BiBooleanToIntFunction} that first applies this function 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 function to an operation returning {@code int}.
 *
 * @param after The operator to apply after this function is applied
 * @return A composed {@code BiBooleanToIntFunction} that first applies this function 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
 * int}.// www .  ja  v a  2  s .c  o m
 */
@Nonnull
default BiBooleanToIntFunction andThenToInt(@Nonnull final IntUnaryOperator after) {
    Objects.requireNonNull(after);
    return (value1, value2) -> after.applyAsInt(applyAsInt(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.conversion.BiByteToIntFunction.java

/**
 * Returns a composed {@link BiByteToIntFunction} that first applies this function 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 function to an operation returning {@code int}.
 *
 * @param after The operator to apply after this function is applied
 * @return A composed {@code BiByteToIntFunction} that first applies this function 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
 * int}.//www  .j  a va  2s.c  o  m
 */
@Nonnull
default BiByteToIntFunction andThenToInt(@Nonnull final IntUnaryOperator after) {
    Objects.requireNonNull(after);
    return (value1, value2) -> after.applyAsInt(applyAsInt(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.conversion.BiCharToIntFunction.java

/**
 * Returns a composed {@link BiCharToIntFunction} that first applies this function 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 function to an operation returning {@code int}.
 *
 * @param after The operator to apply after this function is applied
 * @return A composed {@code BiCharToIntFunction} that first applies this function 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
 * int}.// www.  j  ava 2 s.co m
 */
@Nonnull
default BiCharToIntFunction andThenToInt(@Nonnull final IntUnaryOperator after) {
    Objects.requireNonNull(after);
    return (value1, value2) -> after.applyAsInt(applyAsInt(value1, value2));
}

From source file:at.gridtec.lambda4j.function.bi.conversion.BiFloatToIntFunction.java

/**
 * Returns a composed {@link BiFloatToIntFunction} that first applies this function 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 function to an operation returning {@code int}.
 *
 * @param after The operator to apply after this function is applied
 * @return A composed {@code BiFloatToIntFunction} that first applies this function 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
 * int}.//  w w w.  j a  v  a  2s .c o m
 */
@Nonnull
default BiFloatToIntFunction andThenToInt(@Nonnull final IntUnaryOperator after) {
    Objects.requireNonNull(after);
    return (value1, value2) -> after.applyAsInt(applyAsInt(value1, value2));
}