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


Java LongFunction类代码示例

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


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

示例1: submitNewRequest

import java.util.function.LongFunction; //导入依赖的package包/类
/**
 * A new request arrives, create it with {@link #nextSeqNum}
 * and then try sending it to the server.
 *
 * @param requestConstructor use seqNum to create a new request.
 * @return the new request.
 */
public synchronized REQUEST submitNewRequest(
    LongFunction<REQUEST> requestConstructor, Consumer<REQUEST> sendMethod) {
  if (!requests.isEmpty()) {
    Preconditions.assertTrue(nextSeqNum == requests.lastSeqNum() + 1,
        () -> "nextSeqNum=" + nextSeqNum + " but " + this);
  }

  final long seqNum = nextSeqNum++;
  final REQUEST r = requestConstructor.apply(seqNum);
  requests.putNewRequest(r);

  final boolean submitted = sendOrDelayRequest(r, sendMethod);
  LOG.debug("{}: submitting a new request {} in {}? {}",
      requests.getName(), r, this, submitted? "submitted": "delayed");
  return r;
}
 
开发者ID:apache,项目名称:incubator-ratis,代码行数:24,代码来源:SlidingWindow.java

示例2: sendAsync

import java.util.function.LongFunction; //导入依赖的package包/类
private CompletableFuture<RaftClientReply> sendAsync(Message message,
    boolean readOnly) {
  Objects.requireNonNull(message, "message == null");
  try {
    asyncRequestSemaphore.acquire();
  } catch (InterruptedException e) {
    throw new CompletionException(IOUtils.toInterruptedIOException(
        "Interrupted when sending " + message, e));
  }
  final long callId = nextCallId();
  final LongFunction<PendingAsyncRequest> constructor = seqNum -> new PendingAsyncRequest(seqNum,
      seq -> new RaftClientRequest(clientId, leaderId, groupId, callId, seq, message, readOnly));
  return slidingWindow.submitNewRequest(constructor, this::sendRequestWithRetryAsync
  ).getReplyFuture(
  ).thenApply(reply -> handleStateMachineException(reply, CompletionException::new)
  ).whenComplete((r, e) -> asyncRequestSemaphore.release());
}
 
开发者ID:apache,项目名称:incubator-ratis,代码行数:18,代码来源:RaftClientImpl.java

示例3: mapToObj

import java.util.function.LongFunction; //导入依赖的package包/类
@Override
public final <U> Stream<U> mapToObj(LongFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Long, U>(this, StreamShape.LONG_VALUE,
                                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedLong<U>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:LongPipeline.java

示例4: flatMap

import java.util.function.LongFunction; //导入依赖的package包/类
@Override
public final LongStream flatMap(LongFunction<? extends LongStream> mapper) {
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    try (LongStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:LongPipeline.java

示例5: numberProvider

import java.util.function.LongFunction; //导入依赖的package包/类
public <N extends Number> N[] numberProvider(LongFunction<N> boxer, int bits, N... extras) {
    List<N> numbers = new ArrayList<>();

    for(int bitmag = 0; bitmag < bits; bitmag++) {
        long value = 1L << bitmag;
        numbers.add(boxer.apply(value));
        numbers.add(boxer.apply(value - 1));
        numbers.add(boxer.apply(value + 1));
        numbers.add(boxer.apply(-value));
        for(int divisor = 0; divisor < SOME_PRIMES.length && value < SOME_PRIMES[divisor]; divisor++) {
            numbers.add(boxer.apply(value - SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value + SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value * SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value / SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value | SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value & SOME_PRIMES[divisor]));
            numbers.add(boxer.apply(value ^ SOME_PRIMES[divisor]));
        }
    }

    numbers.addAll(Arrays.asList(extras));

    return (N[]) numbers.toArray(new Number[numbers.size()]);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:IntegralPrimitiveToString.java

示例6: flatMap

import java.util.function.LongFunction; //导入依赖的package包/类
@Override
public final LongStream flatMap(LongFunction<? extends LongStream> mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    try (LongStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:LongPipeline.java

示例7: shouldRequireNonNullFunction

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

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

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

示例8: shouldRequireNonNullCache

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

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

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

示例9: shouldUseSetCacheKeyAndValue

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

    // when
    final ConcurrentMapBasedLongToIntFunctionMemoizer<Long> memoizer = new ConcurrentMapBasedLongToIntFunctionMemoizer<>(
            cache, keyFunction, function);

    // then
    memoizer.applyAsInt(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", 123,
            memoizer.viewCacheForTest().values().iterator().next().intValue());
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:23,代码来源:ConcurrentMapBasedLongToIntFunctionMemoizerTest.java

示例10: shouldRequireNonNullCache

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

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

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

示例11: shouldRequireNonNullCache

import java.util.function.LongFunction; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<String, String> cache = null;
    final LongFunction<String> function = input -> "output";
    final LongFunction<String> keyFunction = input -> "key";

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

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

示例12: shouldRequireNonNullFunction

import java.util.function.LongFunction; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullFunction() {
    // given
    final ConcurrentMap<String, String> cache = new ConcurrentHashMap<>();
    final LongFunction<String> function = null;
    final LongFunction<String> keyFunction = input -> "key";

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

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

示例13: shouldUseSetCacheKeyAndValue

import java.util.function.LongFunction; //导入依赖的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

示例14: shouldUseSetCacheKeyAndValue

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

    // when
    final ConcurrentMapBasedLongToDoubleFunctionMemoizer<Long> memoizer = new ConcurrentMapBasedLongToDoubleFunctionMemoizer<>(
            cache, keyFunction, function);

    // then
    memoizer.applyAsDouble(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", 123D,
            memoizer.viewCacheForTest().values().iterator().next().doubleValue(), 0.0D);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:23,代码来源:ConcurrentMapBasedLongToDoubleFunctionMemoizerTest.java

示例15: shouldWrapExecutionExceptionInMemoizationException

import java.util.function.LongFunction; //导入依赖的package包/类
/**
 * @throws ExecutionException
 *             Added for the call to 'cache.get(..)'.
 */
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldWrapExecutionExceptionInMemoizationException() throws ExecutionException {
    // given
    final LongFunction<Long> keyFunction = Long::valueOf;
    final Cache<Long, Integer> cache = Mockito.mock(Cache.class);
    given(cache.get(any(), any())).willThrow(ExecutionException.class);
    final GuavaCacheBasedLongToIntFunctionMemoizer<Long> memoizer = new GuavaCacheBasedLongToIntFunctionMemoizer<>(
            cache, keyFunction, null);

    // when
    thrown.expect(MemoizationException.class);

    // then
    memoizer.applyAsInt(789);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:21,代码来源:GuavaCacheBasedLongToIntFunctionMemoizerTest.java


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