當前位置: 首頁>>代碼示例>>Java>>正文


Java LongUnaryOperator類代碼示例

本文整理匯總了Java中java.util.function.LongUnaryOperator的典型用法代碼示例。如果您正苦於以下問題:Java LongUnaryOperator類的具體用法?Java LongUnaryOperator怎麽用?Java LongUnaryOperator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LongUnaryOperator類屬於java.util.function包,在下文中一共展示了LongUnaryOperator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: map

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:LongPipeline.java

示例2: iterate

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
/**
 * Returns an infinite sequential ordered {@code LongStream} 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 LongStream} 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 LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

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

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:38,代碼來源:LongStream.java

示例3: iterate

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
/**
 * Returns an infinite sequential ordered {@code LongStream} 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 LongStream} 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 LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    Spliterator.OfLong spliterator = new Spliterators.AbstractLongSpliterator(Long.MAX_VALUE,
           Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
        long prev;
        boolean started;

        @Override
        public boolean tryAdvance(LongConsumer action) {
            Objects.requireNonNull(action);
            long t;
            if (started)
                t = f.applyAsLong(prev);
            else {
                t = seed;
                started = true;
            }
            action.accept(prev = t);
            return true;
        }
    };
    return StreamSupport.longStream(spliterator, false);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:46,代碼來源:LongStream.java

示例4: iterate

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
/**
 * Returns an infinite sequential ordered {@code LongStream} 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 LongStream} 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 LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    Spliterator.OfLong spliterator = new Spliterators.AbstractLongSpliterator(Long.MAX_VALUE,
           Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
        long prev;
        boolean started;

        @Override
        public boolean tryAdvance(LongConsumer action) {
            Objects.requireNonNull(action);
            long t;
            if (started)
                t = f.applyAsLong(prev);
            else {
                t = seed;
                started = true;
            }
            action.accept(prev = t);
            return true;
        }
    };
    return StreamSupport.longStream(spliterator, false);
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:40,代碼來源:LongStream.java

示例5: schedule

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
/**
 * Implements {@link Timers#schedule(Runnable, TimerScheduler)}
 */
@Override
public void schedule(@Pin Consumer<? super Cancel> task, 
                     LongUnaryOperator scheduler,
                     Result<? super Cancel> result)
{
  Objects.requireNonNull(task);
  Objects.requireNonNull(scheduler);

  // cancel(task);

  long now = CurrentTime.currentTime();
  long nextTime = scheduler.applyAsLong(now);

  TimerListener listener = new TimerListener(task, scheduler);
  
  result.ok(listener);
  
  if (now <= nextTime) {
    listener.queueAt(nextTime);
  }
  
  /*
    return listener;
    */
}
 
開發者ID:baratine,項目名稱:baratine,代碼行數:29,代碼來源:TimerServiceRamp.java

示例6: testBinomialCurvePoints

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
@Test
public void testBinomialCurvePoints() {
    LongUnaryOperator idc = IntegerDistributions.forSpec("mapto_binomial(8,0.5)");

    long half = Long.MAX_VALUE / 2;
    long expected = idc.applyAsLong(half);
    assertThat(expected).isEqualTo(4);
    expected = idc.applyAsLong(1);
    assertThat(expected).isEqualTo(0);

    // threshold test against CDF
    expected = idc.applyAsLong((long) (0.03515d * (double) Long.MAX_VALUE));
    assertThat(expected).isEqualTo(1);
    expected = idc.applyAsLong((long) (0.03600d * (double) Long.MAX_VALUE));
    assertThat(expected).isEqualTo(2);
}
 
開發者ID:virtualdataset,項目名稱:metagen-java,代碼行數:17,代碼來源:IntegerDistributionsConcurrencyTest.java

示例7: call

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
@Override
        public long[] call() throws Exception {
            long[] output = new long[size];
            LongUnaryOperator mapper = IntegerDistributions.forSpec(mapperSpec);
//            System.out.println("resolved:" + mapper);
//            System.out.flush();

            synchronized (signal) {
                signal.wait(10000);
            }

            for (int i = 0; i < output.length; i++) {
                output[i] = mapper.applyAsLong(i);
//                if ((i % 100) == 0) {
//                    System.out.println("wrote t:" + slot + ", iter:" + i + ", val:" + output[i]);
//                }
            }
            return output;
        }
 
開發者ID:virtualdataset,項目名稱:metagen-java,代碼行數:20,代碼來源:IntegerDistributionsConcurrencyTest.java

示例8: shouldRequireNonNullCache

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<Long, Long> cache = null;
    final LongUnaryOperator operator = input -> input;
    final LongFunction<Long> keyFunction = Long::valueOf;

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

    // then
    new ConcurrentMapBasedLongUnaryOperatorMemoizer<>(cache, keyFunction, operator);
}
 
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:19,代碼來源:ConcurrentMapBasedLongUnaryOperatorMemoizerTest.java

示例9: shouldRequireNonNullOperator

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullOperator() {
    // given
    final ConcurrentMap<Long, Long> cache = new ConcurrentHashMap<>();
    final LongUnaryOperator operator = null;
    final LongFunction<Long> keyFunction = Long::valueOf;

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

    // then
    new ConcurrentMapBasedLongUnaryOperatorMemoizer<>(cache, keyFunction, operator);
}
 
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:20,代碼來源:ConcurrentMapBasedLongUnaryOperatorMemoizerTest.java

示例10: shouldUseSetCacheKeyAndValue

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
    // given
    final ConcurrentMap<Long, Long> cache = new ConcurrentHashMap<>();
    final LongUnaryOperator operator = input -> input;
    final LongFunction<Long> keyFunction = Long::valueOf;

    // when
    final ConcurrentMapBasedLongUnaryOperatorMemoizer<Long> memoizer = new ConcurrentMapBasedLongUnaryOperatorMemoizer<>(
            cache, keyFunction, operator);

    // then
    memoizer.applyAsLong(123L);
    Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
    Assert.assertEquals("Memoization key does not match expectations", 123L,
            memoizer.viewCacheForTest().keySet().iterator().next().longValue());
    Assert.assertEquals("Memoization value does not match expectations", 123L,
            memoizer.viewCacheForTest().values().iterator().next().longValue());
}
 
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:23,代碼來源:ConcurrentMapBasedLongUnaryOperatorMemoizerTest.java

示例11: shouldUseCallWrappedOperator

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
/**
*
*/
@Test
public void shouldUseCallWrappedOperator() {
    // given
    final ConcurrentMap<Long, Long> cache = new ConcurrentHashMap<>();
    final LongUnaryOperator operator = Mockito.mock(LongUnaryOperator.class);
    final LongFunction<Long> keyFunction = Long::valueOf;

    // when
    final ConcurrentMapBasedLongUnaryOperatorMemoizer<Long> memoizer = new ConcurrentMapBasedLongUnaryOperatorMemoizer<>(
            cache, keyFunction, operator);

    // then
    memoizer.applyAsLong(123L);
    Mockito.verify(operator).applyAsLong(123L);
}
 
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:19,代碼來源:ConcurrentMapBasedLongUnaryOperatorMemoizerTest.java

示例12: testLongUnaryOp

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
@Test public void testLongUnaryOp() {
	LongUnaryOperator longOperand = (l) -> {
		return l + 1;
	};
	long expected = 33L;
	assertEquals(expected, longOperand.applyAsLong(32L));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:8,代碼來源:TestLambdaJavaInterfaces.java

示例13: getAndUpdate

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
/**
 * Updates the value currently associated with {@code key} with the specified function,
 * and returns the old value.  If there is not currently a value associated with {@code key},
 * the function is applied to {@code 0L}.
 *
 * @since 21.0
 */
@CanIgnoreReturnValue
public long getAndUpdate(K key, LongUnaryOperator updaterFunction) {
  checkNotNull(updaterFunction);
  AtomicLong holder = new AtomicLong();
  map.compute(
      key,
      (k, value) -> {
        long oldValue = (value == null) ? 0L : value.longValue();
        holder.set(oldValue);
        return updaterFunction.applyAsLong(oldValue);
      });
  return holder.get();
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:21,代碼來源:AtomicLongMap.java

示例14: BotThread

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
/**
 * Constructs a bot thread.
 *
 * @param bot     the bot used by the reader
 * @param backOff back off to be used when long polling fails
 */
public BotThread(Bot bot, LongUnaryOperator backOff) {
  super();
  this.bot = bot;
  updateReader = new UpdateReader(bot, backOff);
  updateHandlers = new ArrayList<>();
  errorHandlers = new ArrayList<>();
  executor = Runnable::run;
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:15,代碼來源:BotThread.java

示例15: UpdateReader

import java.util.function.LongUnaryOperator; //導入依賴的package包/類
/**
 * Constructs an UpdateReader.
 *
 * @param connection the connection that receive updates
 * @param backOff    back off to be used when long polling fails
 */
public UpdateReader(TelegramConnection connection, LongUnaryOperator backOff) {
  this.connection = Objects.requireNonNull(connection);
  this.backOff = Objects.requireNonNull(backOff);
  updates = new ConcurrentLinkedQueue<>();
  lastUpdateId = -1;
  allowedUpdates = new String[0];
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:14,代碼來源:UpdateReader.java


注:本文中的java.util.function.LongUnaryOperator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。