本文整理汇总了Java中java.util.function.DoubleToLongFunction类的典型用法代码示例。如果您正苦于以下问题:Java DoubleToLongFunction类的具体用法?Java DoubleToLongFunction怎么用?Java DoubleToLongFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DoubleToLongFunction类属于java.util.function包,在下文中一共展示了DoubleToLongFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapToLong
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
@Override
public final LongStream mapToLong(DoubleToLongFunction mapper) {
Objects.requireNonNull(mapper);
return new LongPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override
Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
return new Sink.ChainedDouble<Long>(sink) {
@Override
public void accept(double t) {
downstream.accept(mapper.applyAsLong(t));
}
};
}
};
}
示例2: shouldRequireNonNullCache
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
// given
final ConcurrentMap<Double, Long> cache = null;
final DoubleToLongFunction function = input -> 123;
final DoubleFunction<Double> keyFunction = Double::valueOf;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage("Provide an empty map instead of NULL.");
// then
new ConcurrentMapBasedDoubleToLongFunctionMemoizer<>(cache, keyFunction, function);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedDoubleToLongFunctionMemoizerTest.java
示例3: shouldRequireNonNullFunction
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullFunction() {
// given
final ConcurrentMap<Double, Long> cache = new ConcurrentHashMap<>();
final DoubleToLongFunction function = null;
final DoubleFunction<Double> keyFunction = Double::valueOf;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage(
"Cannot memoize a NULL DoubleToLongFunction - provide an actual DoubleToLongFunction to fix this.");
// then
new ConcurrentMapBasedDoubleToLongFunctionMemoizer<>(cache, keyFunction, function);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:ConcurrentMapBasedDoubleToLongFunctionMemoizerTest.java
示例4: shouldUseSetCacheKeyAndValue
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
// given
final ConcurrentMap<Double, Long> cache = new ConcurrentHashMap<>();
final DoubleToLongFunction function = input -> 123;
final DoubleFunction<Double> keyFunction = Double::valueOf;
// when
final ConcurrentMapBasedDoubleToLongFunctionMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleToLongFunctionMemoizer<>(
cache, keyFunction, function);
// then
memoizer.applyAsLong(123D);
Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
Assert.assertEquals("Memoization key does not match expectations", 123D,
memoizer.viewCacheForTest().keySet().iterator().next().doubleValue(), 0.0D);
Assert.assertEquals("Memoization value does not match expectations", 123L,
memoizer.viewCacheForTest().values().iterator().next().longValue());
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:23,代码来源:ConcurrentMapBasedDoubleToLongFunctionMemoizerTest.java
示例5: shouldUseCallWrappedFunction
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseCallWrappedFunction() {
// given
final ConcurrentMap<Double, Long> cache = new ConcurrentHashMap<>();
final DoubleToLongFunction function = Mockito.mock(DoubleToLongFunction.class);
final DoubleFunction<Double> keyFunction = Double::valueOf;
// when
final ConcurrentMapBasedDoubleToLongFunctionMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleToLongFunctionMemoizer<>(
cache, keyFunction, function);
// then
memoizer.applyAsLong(123D);
Mockito.verify(function).applyAsLong(123D);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedDoubleToLongFunctionMemoizerTest.java
示例6: shouldMemoizeDoubleToLongFunctionWithKeyFunction
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithKeyFunction() {
// given
final DoubleToLongFunction function = a -> 123L;
final DoubleFunction<String> keyFunction = a -> "key";
// when
final DoubleToLongFunction memoize = CaffeineMemoize.doubleToLongFunction(function, keyFunction);
// then
Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
示例7: shouldMemoizeDoubleToLongFunction
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunction() {
// given
final DoubleToLongFunction function = a -> 123L;
// when
final DoubleToLongFunction memoize = CaffeineMemoize.doubleToLongFunction(function);
// then
Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
示例8: shouldMemoizeDoubleToLongFunctionWithLambda
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithLambda() {
// given
// when
final DoubleToLongFunction memoize = CaffeineMemoize.doubleToLongFunction(a -> 123L);
// then
Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
示例9: GuavaCacheBasedDoubleToLongFunctionMemoizer
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
GuavaCacheBasedDoubleToLongFunctionMemoizer(
final Cache<KEY, Long> cache,
final DoubleFunction<KEY> keyFunction,
final DoubleToLongFunction function) {
super(cache);
this.keyFunction = keyFunction;
this.function = function;
}
示例10: shouldMemoizeDoubleToLongFunctionWithKeyFunction
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithKeyFunction() {
// given
final DoubleToLongFunction function = a -> 123;
final DoubleFunction<Double> keyFunction = Double::valueOf;
// when
final DoubleToLongFunction memoize = GuavaMemoize.doubleToLongFunction(function, keyFunction);
// then
Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
示例11: shouldAcceptLoadingCache
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldAcceptLoadingCache() {
// given
final DoubleToLongFunction function = a -> 123L;
final DoubleFunction<Double> keyFunction = Double::valueOf;
final Cache<Double, Long> cache = CacheBuilder.newBuilder().build();
// when
final GuavaCacheBasedDoubleToLongFunctionMemoizer<Double> memoizer = new GuavaCacheBasedDoubleToLongFunctionMemoizer<>(
cache, keyFunction, function);
// then
Assert.assertNotNull(memoizer);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:18,代码来源:GuavaCacheBasedDoubleToLongFunctionMemoizerTest.java
示例12: shouldTransformInput
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldTransformInput() {
// given
final DoubleToLongFunction function = a -> 123L;
final DoubleFunction<Double> keyFunction = Double::valueOf;
final Cache<Double, Long> cache = CacheBuilder.newBuilder().build();
// when
final GuavaCacheBasedDoubleToLongFunctionMemoizer<Double> memoizer = new GuavaCacheBasedDoubleToLongFunctionMemoizer<>(
cache, keyFunction, function);
// then
Assert.assertEquals("Memoized value does not match expectation", 123L, memoizer.applyAsLong(789D));
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:18,代码来源:GuavaCacheBasedDoubleToLongFunctionMemoizerTest.java
示例13: shouldMemoizeDoubleToLongFunctionWithLambda
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithLambda() {
// given
// when
final DoubleToLongFunction memoize = GuavaMemoize.doubleToLongFunction(a -> 123);
// then
Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
示例14: shouldMemoizeDoubleToLongFunction
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunction() {
// given
final DoubleToLongFunction function = a -> 123;
// when
final DoubleToLongFunction memoize = GuavaMemoize.doubleToLongFunction(function);
// then
Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
示例15: JCacheBasedDoubleToLongFunctionMemoizer
import java.util.function.DoubleToLongFunction; //导入依赖的package包/类
JCacheBasedDoubleToLongFunctionMemoizer(
final Cache<KEY, Long> cache,
final DoubleFunction<KEY> keyFunction,
final DoubleToLongFunction biFunction) {
super(cache);
this.keyFunction = keyFunction;
this.biFunction = biFunction;
}