當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。