本文整理汇总了Java中java.util.function.IntToLongFunction类的典型用法代码示例。如果您正苦于以下问题:Java IntToLongFunction类的具体用法?Java IntToLongFunction怎么用?Java IntToLongFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IntToLongFunction类属于java.util.function包,在下文中一共展示了IntToLongFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapToLong
import java.util.function.IntToLongFunction; //导入依赖的package包/类
@Override
public final LongStream mapToLong(IntToLongFunction mapper) {
Objects.requireNonNull(mapper);
return new LongPipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override
Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
return new Sink.ChainedInt<Long>(sink) {
@Override
public void accept(int t) {
downstream.accept(mapper.applyAsLong(t));
}
};
}
};
}
示例2: shouldRequireNonNullCache
import java.util.function.IntToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
// given
final ConcurrentMap<Integer, Long> cache = null;
final IntToLongFunction function = input -> 123;
final IntFunction<Integer> keyFunction = Integer::valueOf;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage("Provide an empty map instead of NULL.");
// then
new ConcurrentMapBasedIntToLongFunctionMemoizer<>(cache, keyFunction, function);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedIntToLongFunctionMemoizerTest.java
示例3: shouldRequireNonNullFunction
import java.util.function.IntToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullFunction() {
// given
final ConcurrentMap<Integer, Long> cache = new ConcurrentHashMap<>();
final IntToLongFunction function = null;
final IntFunction<Integer> keyFunction = Integer::valueOf;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage(
"Cannot memoize a NULL IntToLongFunction - provide an actual IntToLongFunction to fix this.");
// then
new ConcurrentMapBasedIntToLongFunctionMemoizer<>(cache, keyFunction, function);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:ConcurrentMapBasedIntToLongFunctionMemoizerTest.java
示例4: shouldUseSetCacheKeyAndValue
import java.util.function.IntToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
// given
final ConcurrentMap<Integer, Long> cache = new ConcurrentHashMap<>();
final IntToLongFunction function = input -> 123;
final IntFunction<Integer> keyFunction = Integer::valueOf;
// when
final ConcurrentMapBasedIntToLongFunctionMemoizer<Integer> memoizer = new ConcurrentMapBasedIntToLongFunctionMemoizer<>(
cache, keyFunction, function);
// then
memoizer.applyAsLong(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", 123L,
memoizer.viewCacheForTest().values().iterator().next().longValue());
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:23,代码来源:ConcurrentMapBasedIntToLongFunctionMemoizerTest.java
示例5: shouldUseCallWrappedFunction
import java.util.function.IntToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseCallWrappedFunction() {
// given
final ConcurrentMap<Integer, Long> cache = new ConcurrentHashMap<>();
final IntToLongFunction function = Mockito.mock(IntToLongFunction.class);
final IntFunction<Integer> keyFunction = Integer::valueOf;
// when
final ConcurrentMapBasedIntToLongFunctionMemoizer<Integer> memoizer = new ConcurrentMapBasedIntToLongFunctionMemoizer<>(
cache, keyFunction, function);
// then
memoizer.applyAsLong(123);
Mockito.verify(function).applyAsLong(123);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedIntToLongFunctionMemoizerTest.java
示例6: testSetAllLong
import java.util.function.IntToLongFunction; //导入依赖的package包/类
@Test(dataProvider = "long")
public void testSetAllLong(String name, int size, IntToLongFunction generator, long[] expected) {
long[] result = new long[size];
Arrays.setAll(result, generator);
assertEquals(result, expected, "setAll(long[], IntToLongFunction) case " + name + " failed.");
// ensure fresh array
result = new long[size];
Arrays.parallelSetAll(result, generator);
assertEquals(result, expected, "parallelSetAll(long[], IntToLongFunction) case " + name + " failed.");
}
示例7: lookupRandomIndexes
import java.util.function.IntToLongFunction; //导入依赖的package包/类
static long lookupRandomIndexes(IntToLongFunction func) {
long sumOfIndexes = 0;
Random r = new Random(31);
for (int i = 0; i < LOOKUPS; i++) {
int index = 1 + r.nextInt(10);
sumOfIndexes += func.applyAsLong(index);
}
return sumOfIndexes;
}
示例8: shouldMemoizeIntToLongFunctionWithKeyFunction
import java.util.function.IntToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeIntToLongFunctionWithKeyFunction() {
// given
final IntToLongFunction function = a -> 123L;
final IntFunction<String> keyFunction = a -> "key";
// when
final IntToLongFunction memoize = CaffeineMemoize.intToLongFunction(function, keyFunction);
// then
Assert.assertNotNull("Memoized IntToLongFunction is NULL", memoize);
}
示例9: shouldMemoizeIntToLongFunction
import java.util.function.IntToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeIntToLongFunction() {
// given
final IntToLongFunction function = a -> 123L;
// when
final IntToLongFunction memoize = CaffeineMemoize.intToLongFunction(function);
// then
Assert.assertNotNull("Memoized IntToLongFunction is NULL", memoize);
}
示例10: shouldMemoizeIntToLongFunctionWithLambda
import java.util.function.IntToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeIntToLongFunctionWithLambda() {
// given
// when
final IntToLongFunction memoize = CaffeineMemoize.intToLongFunction(a -> 123L);
// then
Assert.assertNotNull("Memoized IntToLongFunction is NULL", memoize);
}
示例11: GuavaCacheBasedIntToLongFunctionMemoizer
import java.util.function.IntToLongFunction; //导入依赖的package包/类
GuavaCacheBasedIntToLongFunctionMemoizer(
final Cache<KEY, Long> cache,
final IntFunction<KEY> keyFunction,
final IntToLongFunction function) {
super(cache);
this.keyFunction = keyFunction;
this.function = function;
}
示例12: shouldMemoizeIntToLongFunctionWithKeyFunction
import java.util.function.IntToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeIntToLongFunctionWithKeyFunction() {
// given
final IntToLongFunction function = a -> 123;
final IntFunction<Integer> keyFunction = Integer::valueOf;
// when
final IntToLongFunction memoize = GuavaMemoize.intToLongFunction(function, keyFunction);
// then
Assert.assertNotNull("Memoized IntToLongFunction is NULL", memoize);
}
示例13: shouldAcceptLoadingCache
import java.util.function.IntToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldAcceptLoadingCache() {
// given
final IntToLongFunction function = a -> 123L;
final IntFunction<Integer> keyFunction = Integer::valueOf;
final Cache<Integer, Long> cache = CacheBuilder.newBuilder().build();
// when
final GuavaCacheBasedIntToLongFunctionMemoizer<Integer> memoizer = new GuavaCacheBasedIntToLongFunctionMemoizer<>(
cache, keyFunction, function);
// then
Assert.assertNotNull(memoizer);
}
示例14: shouldTransformInput
import java.util.function.IntToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldTransformInput() {
// given
final IntToLongFunction function = a -> 123L;
final IntFunction<Integer> keyFunction = Integer::valueOf;
final Cache<Integer, Long> cache = CacheBuilder.newBuilder().build();
// when
final GuavaCacheBasedIntToLongFunctionMemoizer<Integer> memoizer = new GuavaCacheBasedIntToLongFunctionMemoizer<>(
cache, keyFunction, function);
// then
Assert.assertEquals("Memoized value does not match expectation", 123L, memoizer.applyAsLong(789));
}
示例15: shouldMemoizeIntToLongFunctionWithLambda
import java.util.function.IntToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeIntToLongFunctionWithLambda() {
// given
// when
final IntToLongFunction memoize = GuavaMemoize.intToLongFunction(a -> 123L);
// then
Assert.assertNotNull("Memoized IntToLongFunction is NULL", memoize);
}