本文整理汇总了Java中java.util.function.LongToDoubleFunction类的典型用法代码示例。如果您正苦于以下问题:Java LongToDoubleFunction类的具体用法?Java LongToDoubleFunction怎么用?Java LongToDoubleFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LongToDoubleFunction类属于java.util.function包,在下文中一共展示了LongToDoubleFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapToDouble
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
@Override
public final DoubleStream mapToDouble(LongToDoubleFunction mapper) {
Objects.requireNonNull(mapper);
return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override
Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedLong<Double>(sink) {
@Override
public void accept(long t) {
downstream.accept(mapper.applyAsDouble(t));
}
};
}
};
}
示例2: call
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
@Override
public double[] call() throws Exception {
double[] output = new double[size];
LongToDoubleFunction mapper = RealDistributions.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.applyAsDouble(i);
// if ((i % 100) == 0) {
// System.out.println("wrote t:" + slot + ", iter:" + i + ", val:" + output[i]);
// }
}
return output;
}
示例3: shouldRequireNonNullCache
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
// given
final ConcurrentMap<Long, Double> cache = null;
final LongToDoubleFunction 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 ConcurrentMapBasedLongToDoubleFunctionMemoizer<>(cache, keyFunction, function);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedLongToDoubleFunctionMemoizerTest.java
示例4: shouldRequireNonNullFunction
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullFunction() {
// given
final ConcurrentMap<Long, Double> cache = new ConcurrentHashMap<>();
final LongToDoubleFunction function = null;
final LongFunction<Long> keyFunction = Long::valueOf;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage(
"Cannot memoize a NULL LongToDoubleFunction - provide an actual LongToDoubleFunction to fix this.");
// then
new ConcurrentMapBasedLongToDoubleFunctionMemoizer<>(cache, keyFunction, function);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:ConcurrentMapBasedLongToDoubleFunctionMemoizerTest.java
示例5: shouldUseSetCacheKeyAndValue
import java.util.function.LongToDoubleFunction; //导入依赖的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
示例6: shouldUseCallWrappedFunction
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseCallWrappedFunction() {
// given
final ConcurrentMap<Long, Double> cache = new ConcurrentHashMap<>();
final LongToDoubleFunction function = Mockito.mock(LongToDoubleFunction.class);
final LongFunction<Long> keyFunction = Long::valueOf;
// when
final ConcurrentMapBasedLongToDoubleFunctionMemoizer<Long> memoizer = new ConcurrentMapBasedLongToDoubleFunctionMemoizer<>(
cache, keyFunction, function);
// then
memoizer.applyAsDouble(123);
Mockito.verify(function).applyAsDouble(123);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedLongToDoubleFunctionMemoizerTest.java
示例7: forSpec
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
public static LongToDoubleFunction forSpec(String spec) {
Optional<ResolvedFunction> resolvedFunction = new RealDistributions().resolveFunction(spec);
return resolvedFunction
.map(ResolvedFunction::getFunctionObject)
.map(f -> ((LongToDoubleFunction) f))
.orElseThrow(() -> new RuntimeException("Invalid spec: " + spec));
}
示例8: shouldMemoizeLongToDoubleFunctionWithKeyFunction
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunctionWithKeyFunction() {
// given
final LongToDoubleFunction function = a -> 123.456D;
final LongFunction<String> keyFunction = a -> "key";
// when
final LongToDoubleFunction memoize = CaffeineMemoize.longToDoubleFunction(function, keyFunction);
// then
Assert.assertNotNull("Memoized LongToDoubleFunction is NULL", memoize);
}
示例9: shouldMemoizeLongToDoubleFunction
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunction() {
// given
final LongToDoubleFunction function = a -> 123.456D;
// when
final LongToDoubleFunction memoize = CaffeineMemoize.longToDoubleFunction(function);
// then
Assert.assertNotNull("Memoized LongToDoubleFunction is NULL", memoize);
}
示例10: shouldMemoizeLongToDoubleFunctionWithLambda
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunctionWithLambda() {
// given
// when
final LongToDoubleFunction memoize = CaffeineMemoize.longToDoubleFunction(a -> 123.456D);
// then
Assert.assertNotNull("Memoized LongToDoubleFunction is NULL", memoize);
}
示例11: GuavaCacheBasedLongToDoubleFunctionMemoizer
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
GuavaCacheBasedLongToDoubleFunctionMemoizer(
final Cache<KEY, Double> cache,
final LongFunction<KEY> keyFunction,
final LongToDoubleFunction function) {
super(cache);
this.keyFunction = keyFunction;
this.function = function;
}
示例12: shouldMemoizeLongToDoubleFunctionWithKeyFunction
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunctionWithKeyFunction() {
// given
final LongToDoubleFunction function = a -> 123D;
final LongFunction<String> keyFunction = a -> "key";
// when
final LongToDoubleFunction memoize = GuavaMemoize.longToDoubleFunction(function, keyFunction);
// then
Assert.assertNotNull("Memoized LongToDoubleFunction is NULL", memoize);
}
示例13: shouldMemoizeLongToDoubleFunctionWithLambda
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunctionWithLambda() {
// given
// when
final LongToDoubleFunction memoize = GuavaMemoize.longToDoubleFunction(a -> 123D);
// then
Assert.assertNotNull("Memoized LongToDoubleFunction is NULL", memoize);
}
示例14: shouldAcceptLoadingCache
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldAcceptLoadingCache() {
// given
final LongToDoubleFunction function = a -> 123;
final LongFunction<Long> keyFunction = Long::valueOf;
final Cache<Long, Double> cache = CacheBuilder.newBuilder().build();
// when
final GuavaCacheBasedLongToDoubleFunctionMemoizer<Long> memoizer = new GuavaCacheBasedLongToDoubleFunctionMemoizer<>(
cache, keyFunction, function);
// then
Assert.assertNotNull(memoizer);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:18,代码来源:GuavaCacheBasedLongToDoubleFunctionMemoizerTest.java
示例15: shouldTransformInput
import java.util.function.LongToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldTransformInput() {
// given
final LongToDoubleFunction function = a -> 123.456D;
final LongFunction<Long> keyFunction = Long::valueOf;
final Cache<Long, Double> cache = CacheBuilder.newBuilder().build();
// when
final GuavaCacheBasedLongToDoubleFunctionMemoizer<Long> memoizer = new GuavaCacheBasedLongToDoubleFunctionMemoizer<>(
cache, keyFunction, function);
// then
Assert.assertEquals("Memoized value does not match expectation", 123.456D, memoizer.applyAsDouble(789), 0.0D);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:18,代码来源:GuavaCacheBasedLongToDoubleFunctionMemoizerTest.java