當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。