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


Java IntUnaryOperator类代码示例

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


IntUnaryOperator类属于java.util.function包,在下文中一共展示了IntUnaryOperator类的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}.
 *
 * @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:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:IntStream.java

示例2: map

import java.util.function.IntUnaryOperator; //导入依赖的package包/类
@Override
public final IntStream map(IntUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedInt<Integer>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:IntPipeline.java

示例3: mergeObjectEntry

import java.util.function.IntUnaryOperator; //导入依赖的package包/类
/**
 * Fill the inputs of the PhiNode corresponding to one {@link JavaKind#Object} entry in the
 * virtual object.
 *
 * @return true if materialization happened during the merge, false otherwise
 */
private boolean mergeObjectEntry(IntUnaryOperator objectIdFunc, PartialEscapeBlockState<?>[] states, PhiNode phi, int entryIndex) {
    boolean materialized = false;
    for (int i = 0; i < states.length; i++) {
        int object = objectIdFunc.applyAsInt(i);
        ObjectState objectState = states[i].getObjectState(object);
        if (!objectState.isVirtual()) {
            break;
        }
        ValueNode entry = objectState.getEntry(entryIndex);
        if (entry instanceof VirtualObjectNode) {
            VirtualObjectNode entryVirtual = (VirtualObjectNode) entry;
            Block predecessor = getPredecessor(i);
            materialized |= ensureMaterialized(states[i], entryVirtual.getObjectId(), predecessor.getEndNode(), blockEffects.get(predecessor), COUNTER_MATERIALIZATIONS_MERGE);
            objectState = states[i].getObjectState(object);
            if (objectState.isVirtual()) {
                states[i].setEntry(object, entryIndex, entry = states[i].getObjectState(entryVirtual.getObjectId()).getMaterializedValue());
            }
        }
        setPhiInput(phi, i, entry);
    }
    return materialized;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:PartialEscapeClosure.java

示例4: 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

示例5: tick

import java.util.function.IntUnaryOperator; //导入依赖的package包/类
private void tick() {
    int time = this.time.updateAndGet( new IntUnaryOperator() {
        @Override
        public int applyAsInt( int operand ) {
            return operand < maxWorldTicks ? ( operand + 1 ) : 0;
        }
    } );
    int age = worldAge.incrementAndGet();
    if ( timeCounter == 20 ) {
        timeCounter = 0;
        for ( FlexPlayer player : playerSet ) {
            player.getConnectionHandler().sendMessage( new MessageS47TimeUpdate( age, time ) );
        }
    } else {
        timeCounter++;
    }
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:18,代码来源:FlexWorld.java

示例6: 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 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:campolake,项目名称:openjdk9,代码行数:40,代码来源:IntStream.java

示例7: shouldUseSetCacheKeyAndValue

import java.util.function.IntUnaryOperator; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
    // given
    final ConcurrentMap<Integer, Integer> cache = new ConcurrentHashMap<>();
    final IntUnaryOperator operator = input -> input;
    final IntFunction<Integer> keyFunction = Integer::valueOf;

    // when
    final ConcurrentMapBasedIntUnaryOperatorMemoizer<Integer> memoizer = new ConcurrentMapBasedIntUnaryOperatorMemoizer<>(
            cache, keyFunction, operator);

    // then
    memoizer.applyAsInt(123);
    Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
    Assert.assertEquals("Memoization key does not match expectations", 123,
            memoizer.viewCacheForTest().keySet().iterator().next().intValue());
    Assert.assertEquals("Memoization value does not match expectations", 123,
            memoizer.viewCacheForTest().values().iterator().next().intValue());
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:23,代码来源:ConcurrentMapBasedIntUnaryOperatorMemoizerTest.java

示例8: shouldUseCallWrappedOperator

import java.util.function.IntUnaryOperator; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseCallWrappedOperator() {
    // given
    final ConcurrentMap<Integer, Integer> cache = new ConcurrentHashMap<>();
    final IntUnaryOperator operator = Mockito.mock(IntUnaryOperator.class);
    final IntFunction<Integer> keyFunction = Integer::valueOf;

    // when
    final ConcurrentMapBasedIntUnaryOperatorMemoizer<Integer> memoizer = new ConcurrentMapBasedIntUnaryOperatorMemoizer<>(
            cache, keyFunction, operator);

    // then
    memoizer.applyAsInt(123);
    Mockito.verify(operator).applyAsInt(123);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedIntUnaryOperatorMemoizerTest.java

示例9: shouldRequireNonNullCache

import java.util.function.IntUnaryOperator; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<Integer, Integer> cache = null;
    final IntUnaryOperator operator = input -> input;
    final IntFunction<Integer> keyFunction = Integer::valueOf;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Provide an empty map instead of NULL.");

    // then
    new ConcurrentMapBasedIntUnaryOperatorMemoizer<>(cache, keyFunction, operator);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedIntUnaryOperatorMemoizerTest.java

示例10: shouldRequireNonNullOperator

import java.util.function.IntUnaryOperator; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullOperator() {
    // given
    final ConcurrentMap<Integer, Integer> cache = new ConcurrentHashMap<>();
    final IntUnaryOperator operator = null;
    final IntFunction<Integer> keyFunction = Integer::valueOf;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage(
            "Cannot memoize a NULL IntUnaryOperator - provide an actual IntUnaryOperator to fix this.");

    // then
    new ConcurrentMapBasedIntUnaryOperatorMemoizer<>(cache, keyFunction, operator);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:ConcurrentMapBasedIntUnaryOperatorMemoizerTest.java

示例11: BinaryVarVal

import java.util.function.IntUnaryOperator; //导入依赖的package包/类
public BinaryVarVal(IntVar[] variables, IntUnaryOperator varCost, IntUnaryOperator valSelector) {
  this.variables = variables;
  this.unassigned = Array.makeInt(variables.length, i -> i);
  this.nUnassignedT = new TrailedInt(variables[0].trail(), variables.length);
  this.varCost = varCost;
  this.valSelector = valSelector;
}
 
开发者ID:google,项目名称:kiwi-solver,代码行数:8,代码来源:BinaryVarVal.java

示例12: 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

示例13: luhnChecksum

import java.util.function.IntUnaryOperator; //导入依赖的package包/类
protected static int luhnChecksum(IntUnaryOperator provider, int length)
{
    return IntStream.range(0, length)
            .map(condition(i -> i % 2 == length % 2, i -> provider.applyAsInt(i)*2, provider))
            .map(condition(v -> v > 9, v -> v - 9))
            .sum() % 10;
}
 
开发者ID:vthub,项目名称:luhn-utils,代码行数:8,代码来源:LuhnUtils.java

示例14: 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

示例15: map

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


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