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


Java DoubleToIntFunction类代码示例

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


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

示例1: mapToInt

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
@Override
public final IntStream mapToInt(DoubleToIntFunction mapper) {
    Objects.requireNonNull(mapper);
    return new IntPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                               StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedDouble<Integer>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:DoublePipeline.java

示例2: shouldRequireNonNullCache

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

示例3: shouldRequireNonNullFunction

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullFunction() {
    // given
    final ConcurrentMap<Double, Integer> cache = new ConcurrentHashMap<>();
    final DoubleToIntFunction function = null;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

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

    // then
    new ConcurrentMapBasedDoubleToIntFunctionMemoizer<>(cache, keyFunction, function);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:ConcurrentMapBasedDoubleToIntFunctionMemoizerTest.java

示例4: shouldUseSetCacheKeyAndValue

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

示例5: shouldUseCallWrappedFunction

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseCallWrappedFunction() {
    // given
    final ConcurrentMap<Double, Integer> cache = new ConcurrentHashMap<>();
    final DoubleToIntFunction function = Mockito.mock(DoubleToIntFunction.class);
    final DoubleFunction<Double> keyFunction = Double::valueOf;

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

    // then
    memoizer.applyAsInt(123D);
    Mockito.verify(function).applyAsInt(123D);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedDoubleToIntFunctionMemoizerTest.java

示例6: toImage

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
/**
 * Decodes the data into a multicolor image of
 * {@link BufferedImage#TYPE_INT_ARGB}.
 * <p>
 * This is similar to {@link #toImage()}, but is designed to allow greater
 * flexibility in the final image configuration. This processes data values
 * in parallel, providing the matrix value to the provided color function,
 * which responds with a packed integer in 0xAARRGGBB order that is applied
 * to the underlying image. This process is generally quite fast, even on
 * large images.
 * <p>
 * For a basic color picker implementation that hides some of the gory
 * details of this method, see {@link ColorChooser}.
 * 
 * @param converter
 *            the color generation function as described, which must be
 *            non-interfering for parallel usage (as described).
 * @return the constructed image.
 */
public BufferedImage toImage(DoubleToIntFunction converter)
{
	checkNotNull(converter, "converter cannot be null");
	
	// generate an int based version of the input data, scaling as we go
	final int[] scaled = stream()
			.mapToInt(converter)
			.toArray();
	
	// then make the image based on the streamed data
	// thanks to https://stackoverflow.com/questions/6319465#12062505
	// for the idea of directly bypassing the Java weirdness around this
	// stuff and just copy the array contents directly
	BufferedImage image = new BufferedImage(width, height,
			BufferedImage.TYPE_INT_ARGB);
	int[] imageData = ((DataBufferInt) image.getRaster().getDataBuffer())
			.getData();
	System.arraycopy(scaled, 0, imageData, 0, imageData.length);
	return image;
}
 
开发者ID:saybur,项目名称:fractala,代码行数:40,代码来源:Matrix.java

示例7: InterpolatingLongLongSampler

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
public InterpolatingLongLongSampler(DoubleToIntFunction icdSource, int resolution, boolean hash) {
    this.f = icdSource;
    this.resolution = resolution;
    if (hash) {
        this.hash = new ThreadSafeHash();
    }
    this.lut = precompute();
}
 
开发者ID:virtualdataset,项目名称:metagen-java,代码行数:9,代码来源:InterpolatingLongLongSampler.java

示例8: InterpolatingIntLongSampler

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
public InterpolatingIntLongSampler(DoubleToIntFunction icdSource, int resolution, boolean hash) {
    this.f = icdSource;
    this.resolution = resolution;
    if (hash) {
        this.hash = new ThreadSafeHash();
    }
    this.lut = precompute();
}
 
开发者ID:virtualdataset,项目名称:metagen-java,代码行数:9,代码来源:InterpolatingIntLongSampler.java

示例9: InterpolatingIntIntSampler

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
public InterpolatingIntIntSampler(DoubleToIntFunction icdSource, int resolution, boolean hash) {
    this.f = icdSource;
    this.resolution = resolution;
    if (hash) {
        this.hash = new ThreadSafeHash();
    }
    this.lut = precompute();
}
 
开发者ID:virtualdataset,项目名称:metagen-java,代码行数:9,代码来源:InterpolatingIntIntSampler.java

示例10: InterpolatingLongIntSampler

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
public InterpolatingLongIntSampler(DoubleToIntFunction icdSource, int resolution, boolean hash) {
    this.f = icdSource;
    this.resolution = resolution;
    if (hash) {
        this.hash = new ThreadSafeHash();
    }
    this.lut = precompute();
}
 
开发者ID:virtualdataset,项目名称:metagen-java,代码行数:9,代码来源:InterpolatingLongIntSampler.java

示例11: shouldMemoizeDoubleToIntFunctionWithKeyFunction

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunctionWithKeyFunction() {
    // given
    final DoubleToIntFunction function = a -> 123;
    final DoubleFunction<String> keyFunction = a -> "key";

    // when
    final DoubleToIntFunction memoize = CaffeineMemoize.doubleToIntFunction(function, keyFunction);

    // then
    Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:16,代码来源:CaffeineMemoizeCustomKeyTest.java

示例12: shouldMemoizeDoubleToIntFunction

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunction() {
    // given
    final DoubleToIntFunction function = a -> 123;

    // when
    final DoubleToIntFunction memoize = CaffeineMemoize.doubleToIntFunction(function);

    // then
    Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:15,代码来源:CaffeineMemoizeDefaultsTest.java

示例13: shouldMemoizeDoubleToIntFunctionWithLambda

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunctionWithLambda() {
    // given

    // when
    final DoubleToIntFunction memoize = CaffeineMemoize.doubleToIntFunction(a -> 123);

    // then
    Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:14,代码来源:CaffeineMemoizeLambdaTest.java

示例14: GuavaCacheBasedDoubleToIntFunctionMemoizer

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
GuavaCacheBasedDoubleToIntFunctionMemoizer(
        final Cache<KEY, Integer> cache,
        final DoubleFunction<KEY> keyFunction,
        final DoubleToIntFunction function) {
    super(cache);
    this.keyFunction = keyFunction;
    this.function = function;
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:9,代码来源:GuavaCacheBasedDoubleToIntFunctionMemoizer.java

示例15: shouldMemoizeDoubleToIntFunctionWithKeyFunction

import java.util.function.DoubleToIntFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunctionWithKeyFunction() {
    // given
    final DoubleToIntFunction function = a -> 123;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

    // when
    final DoubleToIntFunction memoize = GuavaMemoize.doubleToIntFunction(function, keyFunction);

    // then
    Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:16,代码来源:GuavaMemoizeCustomKeyTest.java


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