Java 类java.util.function.DoubleFunction 实例源码

项目:OpenJSharp    文件:DoublePipeline.java   
@Override
public final <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Double, U>(this, StreamShape.DOUBLE_VALUE,
                                                        StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedDouble<U>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
项目:OpenJSharp    文件:DoublePipeline.java   
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream 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));
                    }
                }
            };
        }
    };
}
项目:jdk8u-jdk    文件:DoublePipeline.java   
@Override
public final <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Double, U>(this, StreamShape.DOUBLE_VALUE,
                                                        StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedDouble<U>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
项目:jdk8u-jdk    文件:DoublePipeline.java   
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream 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));
                    }
                }
            };
        }
    };
}
项目:openjdk-jdk10    文件:DoublePipeline.java   
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream 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));
                    }
                }
            };
        }
    };
}
项目:memoization.java    文件:JCacheBasedDoubleToIntFunctionMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldWrapRuntimeExceptionInMemoizationException() {
    // given
    final DoubleFunction<String> keyfunction = a -> "key";
    try (final Cache<String, Integer> cache = Mockito.mock(Cache.class)) {
        final JCacheBasedDoubleToIntFunctionMemoizer<String> loader = new JCacheBasedDoubleToIntFunctionMemoizer<>(
                cache, keyfunction, null);
        given(cache.invoke(any(), any())).willThrow(RuntimeException.class);

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

        // then
        loader.applyAsInt(123);
    }
}
项目:openjdk9    文件:DoublePipeline.java   
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream 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));
                    }
                }
            };
        }
    };
}
项目:memoization.java    文件:JCacheBasedDoubleBinaryOperatorMemoizerTest.java   
/**
*
*/
@Test
public void shouldMemoizeFunction() {
    // given
    final DoubleBinaryOperator function = (a, b) -> 123.456D;
    final DoubleBinaryFunction<String> keyFunction = (a, b) -> "key";
    try (final Cache<String, Double> cache = JCacheMemoize.createCache(DoubleFunction.class)) {
        // when
        final JCacheBasedDoubleBinaryOperatorMemoizer<String> loader = new JCacheBasedDoubleBinaryOperatorMemoizer<>(
                cache, keyFunction, function);

        // then
        Assert.assertEquals("Memoized value does not match expectation", 123.456D,
                loader.applyAsDouble(123.456D, 789.123D), 0.0D);
    }
}
项目:jdk8u_jdk    文件:DoublePipeline.java   
@Override
public final <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper) {
    Objects.requireNonNull(mapper);
    return new ReferencePipeline.StatelessOp<Double, U>(this, StreamShape.DOUBLE_VALUE,
                                                        StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedDouble<U>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
项目:jdk8u_jdk    文件:DoublePipeline.java   
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream 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));
                    }
                }
            };
        }
    };
}
项目:lookaside_java-1.8.0-openjdk    文件:DoublePipeline.java   
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream 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));
                    }
                }
            };
        }
    };
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleConsumerMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<Double, Double> cache = null;
    final DoubleConsumer consumer = System.out::println;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

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

    // then
    new ConcurrentMapBasedDoubleConsumerMemoizer<>(cache, keyFunction, consumer);
}
项目:la-images    文件:ElementDataSurfaceAdapter.java   
/**
 * Generates a {@code Shape} to represent the data using the specified {@code interpolationLevel} and {@code colormap}.
 * 
 * @param interpolationLevel an integer specifying the interpolation level to use.
 * @param colorMap an {@code IColorMap} to configure the surface.
 * @param colorMapRange a {@code Range} to create the surface color mapper.
 * @param scale a {@code DoubleFunction<Double>} to scale the data.
 * @return a new {@code Shape} with the surface for this data.
 */
public Shape generateSurface(int interpolationLevel, IColorMap colorMap, 
    Range colorMapRange, DoubleFunction<Double> scale
) {
    final List<Coord3d> coords = dataToCoord3d(
        scale(
            scale,
            interpolate(data, interpolationLevel)
        )
    );

    final Shape surface = Builder.buildDelaunay(coords);
    surface.setColorMapper(new ColorMapper(colorMap, colorMapRange));
    surface.setFaceDisplayed(true);
    surface.setWireframeDisplayed(false);
    return surface;
}
项目:memoization.java    文件:JCacheBasedDoubleConsumerMemoizerTest.java   
/**
*
*/
@Test
public void shouldMemoizeConsumer() {
    // given
    final DoubleConsumer consumer = Mockito.mock(DoubleConsumer.class);
    final DoubleFunction<String> keyFunction = a -> "key";
    try (final Cache<String, Double> cache = JCacheMemoize.createCache(DoubleConsumer.class)) {
        // when
        final JCacheBasedDoubleConsumerMemoizer<String> loader = new JCacheBasedDoubleConsumerMemoizer<>(cache,
                keyFunction, consumer);

        // then
        loader.accept(123.456D);
        Mockito.verify(consumer).accept(123.456D);
    }
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleToLongFunctionMemoizerTest.java   
/**
*
*/
@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);
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleToIntFunctionMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<Double, Integer> cache = null;
    final DoubleToIntFunction 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 ConcurrentMapBasedDoubleToIntFunctionMemoizer<>(cache, keyFunction, function);
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleFunctionMemoizerTest.java   
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<String, String> cache = null;
    final DoubleFunction<String> function = input -> "output";
    final DoubleFunction<String> keyFunction = input -> "key";

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

    // then
    new ConcurrentMapBasedDoubleFunctionMemoizer<>(cache, keyFunction, function);
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleUnaryOperatorMemoizerTest.java   
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
    // given
    final ConcurrentMap<Double, Double> cache = new ConcurrentHashMap<>();
    final DoubleUnaryOperator operator = input -> input;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

    // when
    final ConcurrentMapBasedDoubleUnaryOperatorMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleUnaryOperatorMemoizer<>(
            cache, keyFunction, operator);

    // then
    memoizer.applyAsDouble(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", 123D,
            memoizer.viewCacheForTest().values().iterator().next().doubleValue(), 0.0D);
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleToIntFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
    // given
    final ConcurrentMap<Double, Integer> cache = new ConcurrentHashMap<>();
    final DoubleToIntFunction function = input -> 123;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

    // when
    final ConcurrentMapBasedDoubleToIntFunctionMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleToIntFunctionMemoizer<>(
            cache, keyFunction, function);

    // then
    memoizer.applyAsInt(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", 123,
            memoizer.viewCacheForTest().values().iterator().next().intValue());
}
项目:memoization.java    文件:GuavaCacheBasedDoublePredicateMemoizerTest.java   
/**
*
*/
@Test
public void shouldTestGivenValue() {
    // given
    final DoublePredicate predicate = Mockito.mock(DoublePredicate.class);
    final DoubleFunction<String> keyFunction = a -> "key";
    final Cache<String, Boolean> cache = CacheBuilder.newBuilder().build();

    // when
    final GuavaCacheBasedDoublePredicateMemoizer<String> memoizer = new GuavaCacheBasedDoublePredicateMemoizer<>(
            cache, keyFunction, predicate);

    // then
    memoizer.test(123.456D);
    Mockito.verify(predicate).test(123.456D);
}
项目:memoization.java    文件:GuavaCacheBasedDoublePredicateMemoizerTest.java   
/**
 * @throws ExecutionException
 *             Added for the call to 'cache.get(..)'.
 */
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldWrapExecutionExceptionInMemoizationException() throws ExecutionException {
    // given
    final DoublePredicate predicate = a -> true;
    final DoubleFunction<String> keyFunction = a -> "key";
    final Cache<String, Boolean> cache = Mockito.mock(Cache.class);
    given(cache.get(any(), any())).willThrow(ExecutionException.class);
    final GuavaCacheBasedDoublePredicateMemoizer<String> memoizer = new GuavaCacheBasedDoublePredicateMemoizer<>(
            cache, keyFunction, predicate);

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

    // then
    memoizer.test(123.456D);
}
项目:memoization.java    文件:ConcurrentMapBasedDoublePredicateMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<Double, Boolean> cache = null;
    final DoublePredicate predicate = input -> true;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

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

    // then
    new ConcurrentMapBasedDoublePredicateMemoizer<>(cache, keyFunction, predicate);
}
项目:memoization.java    文件:GuavaCacheBasedDoubleUnaryOperatorMemoizerTest.java   
/**
 * @throws ExecutionException
 *             Added for the call to 'cache.get(..)'.
 */
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldWrapExecutionExceptionInMemoizationException() throws ExecutionException {
    // given
    final DoubleFunction<Double> keyFunction = Double::valueOf;
    final Cache<Double, Double> cache = Mockito.mock(Cache.class);
    given(cache.get(any(), any())).willThrow(ExecutionException.class);
    final GuavaCacheBasedDoubleUnaryOperatorMemoizer<Double> memoizer = new GuavaCacheBasedDoubleUnaryOperatorMemoizer<>(
            cache, keyFunction, null);

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

    // then
    memoizer.applyAsDouble(789D);
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleConsumerMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullConsumer() {
    // given
    final ConcurrentMap<Double, Double> cache = new ConcurrentHashMap<>();
    final DoubleConsumer consumer = null;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

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

    // then
    new ConcurrentMapBasedDoubleConsumerMemoizer<>(cache, keyFunction, consumer);
}
项目:memoization.java    文件:GuavaCacheBasedDoubleToIntFunctionMemoizerTest.java   
/**
 * @throws ExecutionException
 *             Added for the call to 'cache.get(..)'.
 */
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldWrapExecutionExceptionInMemoizationException() throws ExecutionException {
    // given
    final DoubleFunction<Double> keyFunction = Double::valueOf;
    final Cache<Double, Integer> cache = Mockito.mock(Cache.class);
    given(cache.get(any(), any())).willThrow(ExecutionException.class);
    final GuavaCacheBasedDoubleToIntFunctionMemoizer<Double> memoizer = new GuavaCacheBasedDoubleToIntFunctionMemoizer<>(
            cache, keyFunction, null);

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

    // then
    memoizer.applyAsInt(789D);
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleUnaryOperatorMemoizerTest.java   
/**
*
*/
@Test
public void shouldUseCallWrappedOperator() {
    // given
    final ConcurrentMap<Double, Double> cache = new ConcurrentHashMap<>();
    final DoubleUnaryOperator operator = Mockito.mock(DoubleUnaryOperator.class);
    final DoubleFunction<Double> keyFunction = Double::valueOf;

    // when
    final ConcurrentMapBasedDoubleUnaryOperatorMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleUnaryOperatorMemoizer<>(
            cache, keyFunction, operator);

    // then
    memoizer.applyAsDouble(123D);
    Mockito.verify(operator).applyAsDouble(123D);
}
项目:memoization.java    文件:JCacheBasedDoubleUnaryOperatorMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldWrapRuntimeExceptionInMemoizationException() {
    // given
    final DoubleFunction<String> keyfunction = a -> "key";
    try (final Cache<String, Double> cache = Mockito.mock(Cache.class)) {
        final JCacheBasedDoubleUnaryOperatorMemoizer<String> loader = new JCacheBasedDoubleUnaryOperatorMemoizer<>(
                cache, keyfunction, null);
        given(cache.invoke(any(), any())).willThrow(RuntimeException.class);

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

        // then
        loader.applyAsDouble(123);
    }
}
项目:memoization.java    文件:GuavaCacheBasedDoubleConsumerMemoizerTest.java   
/**
 * @throws ExecutionException
 *             Added for the call to 'cache.get(..)'.
 */
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldWrapExecutionExceptionInMemoizationException() throws ExecutionException {
    // given
    final DoubleFunction<String> keyFunction = a -> "key";
    final DoubleConsumer consumer = System.out::println;
    final Cache<String, Double> cache = Mockito.mock(Cache.class);
    given(cache.get(any(), any())).willThrow(ExecutionException.class);
    final GuavaCacheBasedDoubleConsumerMemoizer<String> memoizer = new GuavaCacheBasedDoubleConsumerMemoizer<>(
            cache, keyFunction, consumer);

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

    // then
    memoizer.accept(123.456D);
}
项目:memoization.java    文件:JCacheBasedDoubleFunctionMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldWrapRuntimeExceptionInMemoizationException() {
    // given
    final DoubleFunction<String> keyFunction = a -> "key";
    try (final Cache<String, String> cache = Mockito.mock(Cache.class)) {
        final JCacheBasedDoubleFunctionMemoizer<String, String> loader = new JCacheBasedDoubleFunctionMemoizer<>(
                cache,
                keyFunction, null);
        given(cache.invoke(any(), any())).willThrow(RuntimeException.class);

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

        // then
        loader.apply(123);
    }
}
项目:openjdk-jdk10    文件:DoublePipeline.java   
private <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper, int opFlags) {
    return new ReferencePipeline.StatelessOp<Double, U>(this, StreamShape.DOUBLE_VALUE, opFlags) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<U> sink) {
            return new Sink.ChainedDouble<U>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.apply(t));
                }
            };
        }
    };
}
项目:morpheus-core    文件:Printer.java   
/**
 * Creates an DOUBLE Printer that wraps the function provided
 * @param function  the function to wrap
 * @return          the newly created function Printer
 */
public static Printer<Double> forDouble(DoubleFunction<String> function) {
    return new Printer<Double>(FunctionStyle.DOUBLE, DEFAULT_NULL) {
        @Override
        public final String apply(double input) {
            return function.apply(input);
        }
    };
}
项目:morpheus-core    文件:Function2.java   
/**
 * Creates an LONG function that wraps to function provided
 * @param function  the function to wrap
 * @param <O>       the output type
 * @return          the newly created function wrapper
 */
public static <O> Function2<Double,O> fromDouble(DoubleFunction<O> function) {
    return new Function2<Double,O>(FunctionStyle.DOUBLE) {
        @Override
        public final O apply(double input) {
            return function.apply(input);
        }
    };
}
项目:memoization.java    文件:JCacheBasedDoubleConsumerMemoizer.java   
JCacheBasedDoubleConsumerMemoizer(
        final Cache<KEY, Double> cache,
        final DoubleFunction<KEY> keyFunction,
        final DoubleConsumer consumer) {
    super(cache);
    this.keyFunction = keyFunction;
    this.consumer = consumer;
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleConsumerMemoizerTest.java   
/**
*
*/
@Test
public void shouldAcceptCacheAndKeyFunctionAndConsumer() {
    // given
    final ConcurrentMap<Double, Double> cache = new ConcurrentHashMap<>();
    final DoubleConsumer consumer = System.out::println;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

    // when
    final ConcurrentMapBasedDoubleConsumerMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleConsumerMemoizer<>(
            cache, keyFunction, consumer);

    // then
    Assert.assertNotNull("Memoizer is NULL", memoizer);
}
项目:memoization.java    文件:MapMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleUnaryOperatorWithKeyFunction() {
    // given
    final DoubleUnaryOperator operator = input -> 123.456D;
    final DoubleFunction<String> keyFunction = a -> "key";

    // when
    final DoubleUnaryOperator memoize = MapMemoize.doubleUnaryOperator(operator, keyFunction);

    // then
    Assert.assertNotNull("Memoized DoubleUnaryOperator is NULL", memoize);
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleToIntFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldMemoizeFunction() {
    // given
    final ConcurrentMap<Double, Integer> cache = new ConcurrentHashMap<>();
    final DoubleToIntFunction function = input -> 123;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

    // when
    final ConcurrentMapBasedDoubleToIntFunctionMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleToIntFunctionMemoizer<>(
            cache, keyFunction, function);

    // then
    memoizer.applyAsInt(123.456D);
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleUnaryOperatorMemoizerTest.java   
/**
*
*/
@Test
public void shouldMemoizeOperator() {
    // given
    final ConcurrentMap<Double, Double> cache = new ConcurrentHashMap<>();
    final DoubleUnaryOperator operator = input -> input;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

    // when
    final ConcurrentMapBasedDoubleUnaryOperatorMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleUnaryOperatorMemoizer<>(
            cache, keyFunction, operator);

    // then
    memoizer.applyAsDouble(123.456D);
}
项目:memoization.java    文件:MapMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleFunction() {
    // given
    final DoubleFunction<String> function = a -> "test";
    final DoubleFunction<String> keyFunction = a -> "key";

    // when
    final DoubleFunction<String> memoize = MapMemoize.doubleFunction(function, keyFunction);

    // then
    Assert.assertNotNull("Memoized DoubleFunction is NULL", memoize);
}
项目:memoization.java    文件:MapMemoizeDefaultsTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleFunction() {
    // given
    final DoubleFunction<String> function = a -> "test";

    // when
    final DoubleFunction<String> memoize = MapMemoize.doubleFunction(function);

    // then
    Assert.assertNotNull("Memoized DoubleFunction is NULL", memoize);
}
项目:memoization.java    文件:MapMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunctionWithKeyFunction() {
    // given
    final DoubleToIntFunction operator = input -> 123;
    final DoubleFunction<String> keyFunction = a -> "key";

    // when
    final DoubleToIntFunction memoize = MapMemoize.doubleToIntFunction(operator, keyFunction);

    // then
    Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}