当前位置: 首页>>代码示例>>Java>>正文


Java IntUnaryOperator.applyAsInt方法代码示例

本文整理汇总了Java中java.util.function.IntUnaryOperator.applyAsInt方法的典型用法代码示例。如果您正苦于以下问题:Java IntUnaryOperator.applyAsInt方法的具体用法?Java IntUnaryOperator.applyAsInt怎么用?Java IntUnaryOperator.applyAsInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.function.IntUnaryOperator的用法示例。


在下文中一共展示了IntUnaryOperator.applyAsInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: iterate

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
/**
 * Returns an infinite sequential ordered {@code IntStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code IntStream} will be
 * the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * <p>The action of applying {@code f} for one element
 * <a href="../concurrent/package-summary.html#MemoryVisibility"><i>happens-before</i></a>
 * the action of applying {@code f} for subsequent elements.  For any given
 * element the action may be performed in whatever thread the library
 * chooses.
 *
 * @param seed the initial element
 * @param f a function to be applied to the previous element to produce
 *          a new element
 * @return a new sequential {@code IntStream}
 */
public static IntStream iterate(final int seed, final IntUnaryOperator f) {
    Objects.requireNonNull(f);
    Spliterator.OfInt spliterator = new Spliterators.AbstractIntSpliterator(Long.MAX_VALUE,
           Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
        int prev;
        boolean started;

        @Override
        public boolean tryAdvance(IntConsumer action) {
            Objects.requireNonNull(action);
            int t;
            if (started)
                t = f.applyAsInt(prev);
            else {
                t = seed;
                started = true;
            }
            action.accept(prev = t);
            return true;
        }
    };
    return StreamSupport.intStream(spliterator, false);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:IntStream.java

示例2: iterate

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
/**
 * Returns an infinite sequential ordered {@code IntStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code IntStream} will be
 * the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * @param seed the initial element
 * @param f a function to be applied to to the previous element to produce
 *          a new element
 * @return A new sequential {@code IntStream}
 */
public static IntStream iterate(final int seed, final IntUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfInt iterator = new PrimitiveIterator.OfInt() {
        int t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public int nextInt() {
            int v = t;
            t = f.applyAsInt(t);
            return v;
        }
    };
    return StreamSupport.intStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:38,代码来源:IntStream.java

示例3: makeInt

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
public static int[] makeInt(int n, IntUnaryOperator f) {
  int[] array = new int[n];
  for (int i = 0; i < n; i++) {
    array[i] = f.applyAsInt(i);
  }
  return array;
}
 
开发者ID:google,项目名称:kiwi-solver,代码行数:8,代码来源:Array.java

示例4: map

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
@NonNull
@Override
public MuVector4i map(@NonNull final IntUnaryOperator operator) {
  this.x = operator.applyAsInt(this.x);
  this.y = operator.applyAsInt(this.y);
  this.z = operator.applyAsInt(this.z);
  this.w = operator.applyAsInt(this.w);
  return this;
}
 
开发者ID:KyoriPowered,项目名称:math,代码行数:10,代码来源:MuVector4i.java

示例5: checkAndSetOrder

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
private void checkAndSetOrder(IntPredicate expectedValue,
                              IntUnaryOperator newValue) {
    if (!expectedValue.test(invocationOrder)) {
        throw new TestSupport.AssertionFailedException(
                expectedValue + " -> " + newValue);
    }
    invocationOrder = newValue.applyAsInt(invocationOrder);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:ReaderTest.java

示例6: getAndUpdate

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
public final int getAndUpdate(int i, IntUnaryOperator updateFunction) {
    long offset = checkedByteOffset(i);
    int prev, next;
    do {
        prev = getRaw(offset);
        next = updateFunction.applyAsInt(prev);
    } while (!compareAndSetRaw(offset, prev, next));
    return prev;
}
 
开发者ID:catap,项目名称:atomic,代码行数:10,代码来源:AtomicIntegerArray.java

示例7: updateAndGet

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
public final int updateAndGet(IntUnaryOperator updateFunction) {
    int prev, next;
    do {
        prev = value;
        next = updateFunction.applyAsInt(prev);
    } while (!compareAndSet(prev, next));
    return next;
}
 
开发者ID:catap,项目名称:atomic,代码行数:9,代码来源:AtomicInteger.java

示例8: getCount

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
private static long getCount(IntUnaryOperator countProvider, int segCount) {
	long result = countProvider.applyAsInt(0);
	for(int i = 1; i < segCount; i++) {
		result *= countProvider.applyAsInt(i);
	}
	return result;
}
 
开发者ID:seancfoley,项目名称:IPAddress,代码行数:8,代码来源:IPv4AddressSection.java

示例9: updateAndGet

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
/**
 * Atomically updates the current value with the results of
 * applying the given function, returning the updated value. The
 * function should be side-effect-free, since it may be re-applied
 * when attempted updates fail due to contention among threads.
 *
 * @param updateFunction a side-effect-free function
 * @return the updated value
 * @since 1.8
 */
public final int updateAndGet(IntUnaryOperator updateFunction) {
    int prev, next;
    do {
        prev = get();
        next = updateFunction.applyAsInt(prev);
    } while (!compareAndSet(prev, next));
    return next;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:AtomicInteger.java

示例10: updateAndGet

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
/**
 * Atomically updates the field of the given object managed by this updater
 * with the results of applying the given function, returning the updated
 * value. The function should be side-effect-free, since it may be
 * re-applied when attempted updates fail due to contention among threads.
 *
 * @param obj An object whose field to get and set
 * @param updateFunction a side-effect-free function
 * @return the updated value
 * @since 1.8
 */
public final int updateAndGet(T obj, IntUnaryOperator updateFunction) {
    int prev, next;
    do {
        prev = get(obj);
        next = updateFunction.applyAsInt(prev);
    } while (!compareAndSet(obj, prev, next));
    return next;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:AtomicIntegerFieldUpdater.java

示例11: getAndUpdate

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
/**
 * Atomically updates the element at index {@code i} with the results
 * of applying the given function, returning the previous value. The
 * function should be side-effect-free, since it may be re-applied
 * when attempted updates fail due to contention among threads.
 *
 * @param i the index
 * @param updateFunction a side-effect-free function
 * @return the previous value
 * @since 1.8
 */
public final int getAndUpdate(int i, IntUnaryOperator updateFunction) {
    long offset = checkedByteOffset(i);
    int prev, next;
    do {
        prev = getRaw(offset);
        next = updateFunction.applyAsInt(prev);
    } while (!compareAndSetRaw(offset, prev, next));
    return prev;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:AtomicIntegerArray.java

示例12: updateAndGet

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
/**
 * Atomically updates the element at index {@code i} with the results
 * of applying the given function, returning the updated value. The
 * function should be side-effect-free, since it may be re-applied
 * when attempted updates fail due to contention among threads.
 *
 * @param i the index
 * @param updateFunction a side-effect-free function
 * @return the updated value
 * @since 1.8
 */
public final int updateAndGet(int i, IntUnaryOperator updateFunction) {
    long offset = checkedByteOffset(i);
    int prev, next;
    do {
        prev = getRaw(offset);
        next = updateFunction.applyAsInt(prev);
    } while (!compareAndSetRaw(offset, prev, next));
    return next;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:AtomicIntegerArray.java

示例13: getAndUpdate

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
/**
 * Atomically updates the field of the given object managed by this updater
 * with the results of applying the given function, returning the previous
 * value. The function should be side-effect-free, since it may be
 * re-applied when attempted updates fail due to contention among threads.
 *
 * @param obj An object whose field to get and set
 * @param updateFunction a side-effect-free function
 * @return the previous value
 * @since 1.8
 */
public final int getAndUpdate(T obj, IntUnaryOperator updateFunction) {
    int prev, next;
    do {
        prev = get(obj);
        next = updateFunction.applyAsInt(prev);
    } while (!compareAndSet(obj, prev, next));
    return prev;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:AtomicIntegerFieldUpdater.java

示例14: getAndUpdate

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
/**
 * Atomically updates (with memory effects as specified by {@link
 * VarHandle#compareAndSet}) the field of the given object managed
 * by this updater with the results of applying the given
 * function, returning the previous value. The function should be
 * side-effect-free, since it may be re-applied when attempted
 * updates fail due to contention among threads.
 *
 * @param obj An object whose field to get and set
 * @param updateFunction a side-effect-free function
 * @return the previous value
 * @since 1.8
 */
public final int getAndUpdate(T obj, IntUnaryOperator updateFunction) {
    int prev, next;
    do {
        prev = get(obj);
        next = updateFunction.applyAsInt(prev);
    } while (!compareAndSet(obj, prev, next));
    return prev;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:AtomicIntegerFieldUpdater.java

示例15: getAndUpdate

import java.util.function.IntUnaryOperator; //导入方法依赖的package包/类
/**
 * Atomically updates the current value with the results of
 * applying the given function, returning the previous value. The
 * function should be side-effect-free, since it may be re-applied
 * when attempted updates fail due to contention among threads.
 *
 * @param updateFunction a side-effect-free function
 * @return the previous value
 * @since 1.8
 */
public final int getAndUpdate(IntUnaryOperator updateFunction) {
    int prev, next;
    do {
        prev = get();
        next = updateFunction.applyAsInt(prev);
    } while (!compareAndSet(prev, next));
    return prev;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:AtomicInteger.java


注:本文中的java.util.function.IntUnaryOperator.applyAsInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。