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


Java DoubleFunction类代码示例

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


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

示例1: mapToObj

import java.util.function.DoubleFunction; //导入依赖的package包/类
@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));
                }
            };
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:DoublePipeline.java

示例2: flatMap

import java.util.function.DoubleFunction; //导入依赖的package包/类
@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));
                    }
                }
            };
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:DoublePipeline.java

示例3: flatMap

import java.util.function.DoubleFunction; //导入依赖的package包/类
@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));
                    }
                }
            };
        }
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:DoublePipeline.java

示例4: shouldWrapRuntimeExceptionInMemoizationException

import java.util.function.DoubleFunction; //导入依赖的package包/类
/**
*
*/
@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);
    }
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:21,代码来源:JCacheBasedDoubleToIntFunctionMemoizerTest.java

示例5: shouldMemoizeFunction

import java.util.function.DoubleFunction; //导入依赖的package包/类
/**
*
*/
@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);
    }
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:JCacheBasedDoubleBinaryOperatorMemoizerTest.java

示例6: shouldRequireNonNullCache

import java.util.function.DoubleFunction; //导入依赖的package包/类
/**
*
*/
@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);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedDoubleConsumerMemoizerTest.java

示例7: generateSurface

import java.util.function.DoubleFunction; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:sing-group,项目名称:la-images,代码行数:26,代码来源:ElementDataSurfaceAdapter.java

示例8: shouldMemoizeConsumer

import java.util.function.DoubleFunction; //导入依赖的package包/类
/**
*
*/
@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);
    }
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:JCacheBasedDoubleConsumerMemoizerTest.java

示例9: shouldRequireNonNullCache

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

示例10: shouldRequireNonNullCache

import java.util.function.DoubleFunction; //导入依赖的package包/类
/**
*
*/
@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);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedDoubleToIntFunctionMemoizerTest.java

示例11: shouldRequireNonNullCache

import java.util.function.DoubleFunction; //导入依赖的package包/类
/**
 *
 */
@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);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedDoubleFunctionMemoizerTest.java

示例12: shouldUseSetCacheKeyAndValue

import java.util.function.DoubleFunction; //导入依赖的package包/类
/**
*
*/
@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);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:23,代码来源:ConcurrentMapBasedDoubleUnaryOperatorMemoizerTest.java

示例13: shouldUseSetCacheKeyAndValue

import java.util.function.DoubleFunction; //导入依赖的package包/类
/**
*
*/
@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());
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:23,代码来源:ConcurrentMapBasedDoubleToIntFunctionMemoizerTest.java

示例14: shouldTestGivenValue

import java.util.function.DoubleFunction; //导入依赖的package包/类
/**
*
*/
@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);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:GuavaCacheBasedDoublePredicateMemoizerTest.java

示例15: shouldWrapExecutionExceptionInMemoizationException

import java.util.function.DoubleFunction; //导入依赖的package包/类
/**
 * @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);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:22,代码来源:GuavaCacheBasedDoublePredicateMemoizerTest.java


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