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


Java LongToIntFunction类代码示例

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


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

示例1: mapToInt

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

示例2: shouldRequireNonNullCache

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

示例3: shouldRequireNonNullFunction

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

示例4: shouldUseSetCacheKeyAndValue

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

示例5: shouldUseCallWrappedFunction

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

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

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

示例6: shouldMemoizeLongToIntFunctionWithKeyFunction

import java.util.function.LongToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongToIntFunctionWithKeyFunction() {
    // given
    final LongToIntFunction function = a -> 123;
    final LongFunction<String> keyFunction = a -> "key";

    // when
    final LongToIntFunction memoize = CaffeineMemoize.longToIntFunction(function, keyFunction);

    // then
    Assert.assertNotNull("Memoized LongToIntFunction is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:16,代码来源:CaffeineMemoizeCustomKeyTest.java

示例7: shouldMemoizeLongToIntFunction

import java.util.function.LongToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongToIntFunction() {
    // given
    final LongToIntFunction function = a -> 123;

    // when
    final LongToIntFunction memoize = CaffeineMemoize.longToIntFunction(function);

    // then
    Assert.assertNotNull("Memoized LongToIntFunction is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:15,代码来源:CaffeineMemoizeDefaultsTest.java

示例8: shouldMemoizeLongToIntFunctionWithLambda

import java.util.function.LongToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongToIntFunctionWithLambda() {
    // given

    // when
    final LongToIntFunction memoize = CaffeineMemoize.longToIntFunction(a -> 123);

    // then
    Assert.assertNotNull("Memoized LongToIntFunction is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:14,代码来源:CaffeineMemoizeLambdaTest.java

示例9: GuavaCacheBasedLongToIntFunctionMemoizer

import java.util.function.LongToIntFunction; //导入依赖的package包/类
GuavaCacheBasedLongToIntFunctionMemoizer(
        final Cache<KEY, Integer> cache,
        final LongFunction<KEY> keyFunction,
        final LongToIntFunction function) {
    super(cache);
    this.keyFunction = keyFunction;
    this.function = function;
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:9,代码来源:GuavaCacheBasedLongToIntFunctionMemoizer.java

示例10: shouldMemoizeLongToIntFunctionWithKeyFunction

import java.util.function.LongToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongToIntFunctionWithKeyFunction() {
    // given
    final LongToIntFunction function = a -> 123;
    final LongFunction<String> keyFunction = a -> "key";

    // when
    final LongToIntFunction memoize = GuavaMemoize.longToIntFunction(function, keyFunction);

    // then
    Assert.assertNotNull("Memoized LongToIntFunction is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:16,代码来源:GuavaMemoizeCustomKeyTest.java

示例11: shouldAcceptLoadingCache

import java.util.function.LongToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldAcceptLoadingCache() {
    // given
    final LongToIntFunction function = a -> 123;
    final LongFunction<Long> keyFunction = Long::valueOf;
    final Cache<Long, Integer> cache = CacheBuilder.newBuilder().build();

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

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

示例12: shouldTransformInput

import java.util.function.LongToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldTransformInput() {
    // given
    final LongToIntFunction function = a -> 123;
    final LongFunction<Long> keyFunction = Long::valueOf;
    final Cache<Long, Integer> cache = CacheBuilder.newBuilder().build();

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

    // then
    Assert.assertEquals("Memoized value does not match expectation", 123, memoizer.applyAsInt(789));
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:18,代码来源:GuavaCacheBasedLongToIntFunctionMemoizerTest.java

示例13: shouldMemoizeLongToIntFunctionWithLambda

import java.util.function.LongToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongToIntFunctionWithLambda() {
    // given

    // when
    final LongToIntFunction memoize = GuavaMemoize.longToIntFunction(a -> 123);

    // then
    Assert.assertNotNull("Memoized LongToIntFunction is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:14,代码来源:GuavaMemoizeLambdaTest.java

示例14: shouldMemoizeLongToIntFunction

import java.util.function.LongToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongToIntFunction() {
    // given
    final LongToIntFunction function = a -> 123;

    // when
    final LongToIntFunction memoize = GuavaMemoize.longToIntFunction(function);

    // then
    Assert.assertNotNull("Memoized LongToIntFunction is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:15,代码来源:GuavaMemoizeDefaultsTest.java

示例15: JCacheBasedLongToIntFunctionMemoizer

import java.util.function.LongToIntFunction; //导入依赖的package包/类
JCacheBasedLongToIntFunctionMemoizer(
        final Cache<KEY, Integer> cache,
        final LongFunction<KEY> keyFunction,
        final LongToIntFunction biFunction) {
    super(cache);
    this.keyFunction = keyFunction;
    this.biFunction = biFunction;
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:9,代码来源:JCacheBasedLongToIntFunctionMemoizer.java


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