Java 类java.util.function.DoubleToIntFunction 实例源码
项目:OpenJSharp
文件:DoublePipeline.java
@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));
}
};
}
};
}
项目:jdk8u-jdk
文件:DoublePipeline.java
@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));
}
};
}
};
}
项目:openjdk-jdk10
文件:DoublePipeline.java
@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));
}
};
}
};
}
项目:openjdk9
文件:DoublePipeline.java
@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));
}
};
}
};
}
项目:Java8CN
文件:DoublePipeline.java
@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));
}
};
}
};
}
项目:jdk8u_jdk
文件:DoublePipeline.java
@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));
}
};
}
};
}
项目:lookaside_java-1.8.0-openjdk
文件:DoublePipeline.java
@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));
}
};
}
};
}
项目: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
文件:ConcurrentMapBasedDoubleToIntFunctionMemoizerTest.java
/**
*
*/
@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);
}
项目: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
文件:ConcurrentMapBasedDoubleToIntFunctionMemoizerTest.java
/**
*
*/
@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);
}
项目:fractala
文件:Matrix.java
/**
* 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;
}
项目:jdk8u-dev-jdk
文件:DoublePipeline.java
@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));
}
};
}
};
}
项目:infobip-open-jdk-8
文件:DoublePipeline.java
@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));
}
};
}
};
}
项目:metagen-java
文件:InterpolatingLongLongSampler.java
public InterpolatingLongLongSampler(DoubleToIntFunction icdSource, int resolution, boolean hash) {
this.f = icdSource;
this.resolution = resolution;
if (hash) {
this.hash = new ThreadSafeHash();
}
this.lut = precompute();
}
项目:metagen-java
文件:InterpolatingIntLongSampler.java
public InterpolatingIntLongSampler(DoubleToIntFunction icdSource, int resolution, boolean hash) {
this.f = icdSource;
this.resolution = resolution;
if (hash) {
this.hash = new ThreadSafeHash();
}
this.lut = precompute();
}
项目:metagen-java
文件:InterpolatingIntIntSampler.java
public InterpolatingIntIntSampler(DoubleToIntFunction icdSource, int resolution, boolean hash) {
this.f = icdSource;
this.resolution = resolution;
if (hash) {
this.hash = new ThreadSafeHash();
}
this.lut = precompute();
}
项目:metagen-java
文件:InterpolatingLongIntSampler.java
public InterpolatingLongIntSampler(DoubleToIntFunction icdSource, int resolution, boolean hash) {
this.f = icdSource;
this.resolution = resolution;
if (hash) {
this.hash = new ThreadSafeHash();
}
this.lut = precompute();
}
项目:memoization.java
文件:CaffeineMemoizeCustomKeyTest.java
/**
*
*/
@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);
}
项目:memoization.java
文件:CaffeineMemoizeDefaultsTest.java
/**
*
*/
@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);
}
项目:memoization.java
文件:CaffeineMemoizeLambdaTest.java
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunctionWithLambda() {
// given
// when
final DoubleToIntFunction memoize = CaffeineMemoize.doubleToIntFunction(a -> 123);
// then
Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
项目:memoization.java
文件:GuavaCacheBasedDoubleToIntFunctionMemoizer.java
GuavaCacheBasedDoubleToIntFunctionMemoizer(
final Cache<KEY, Integer> cache,
final DoubleFunction<KEY> keyFunction,
final DoubleToIntFunction function) {
super(cache);
this.keyFunction = keyFunction;
this.function = function;
}
项目:memoization.java
文件:GuavaMemoizeCustomKeyTest.java
/**
*
*/
@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);
}
项目:memoization.java
文件:GuavaCacheBasedDoubleToIntFunctionMemoizerTest.java
/**
*
*/
@Test
public void shouldAcceptLoadingCache() {
// given
final DoubleToIntFunction function = a -> 123;
final DoubleFunction<Double> keyFunction = Double::valueOf;
final Cache<Double, Integer> cache = CacheBuilder.newBuilder().build();
// when
final GuavaCacheBasedDoubleToIntFunctionMemoizer<Double> memoizer = new GuavaCacheBasedDoubleToIntFunctionMemoizer<>(
cache, keyFunction, function);
// then
Assert.assertNotNull(memoizer);
}
项目:memoization.java
文件:GuavaCacheBasedDoubleToIntFunctionMemoizerTest.java
/**
*
*/
@Test
public void shouldTransformInput() {
// given
final DoubleToIntFunction function = a -> 123;
final DoubleFunction<Double> keyFunction = Double::valueOf;
final Cache<Double, Integer> cache = CacheBuilder.newBuilder().build();
// when
final GuavaCacheBasedDoubleToIntFunctionMemoizer<Double> memoizer = new GuavaCacheBasedDoubleToIntFunctionMemoizer<>(
cache, keyFunction, function);
// then
Assert.assertEquals("Memoized value does not match expectation", 123, memoizer.applyAsInt(789D));
}
项目:memoization.java
文件:GuavaMemoizeLambdaTest.java
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunctionWithLambda() {
// given
// when
final DoubleToIntFunction memoize = GuavaMemoize.doubleToIntFunction(a -> 123);
// then
Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
项目:memoization.java
文件:GuavaMemoizeDefaultsTest.java
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunction() {
// given
final DoubleToIntFunction function = a -> 123;
// when
final DoubleToIntFunction memoize = GuavaMemoize.doubleToIntFunction(function);
// then
Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
项目:memoization.java
文件:JCacheBasedDoubleToIntFunctionMemoizer.java
JCacheBasedDoubleToIntFunctionMemoizer(
final Cache<KEY, Integer> cache,
final DoubleFunction<KEY> keyFunction,
final DoubleToIntFunction biFunction) {
super(cache);
this.keyFunction = keyFunction;
this.biFunction = biFunction;
}
项目:memoization.java
文件:JCacheBasedDoubleToIntFunctionMemoizerTest.java
/**
*
*/
@Test
public void shouldMemoizeBiFunction() {
// given
final DoubleToIntFunction function = first -> 123;
final DoubleFunction<String> keyfunction = a -> "key";
try (final Cache<String, Integer> cache = JCacheMemoize.createCache(ToDoubleBiFunction.class)) {
// when
final JCacheBasedDoubleToIntFunctionMemoizer<String> loader = new JCacheBasedDoubleToIntFunctionMemoizer<>(
cache, keyfunction, function);
// then
Assert.assertEquals("Memoized value does not match expectation", 123, loader.applyAsInt(123));
}
}
项目:memoization.java
文件:JCacheMemoizeCustomKeyTest.java
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunctionWithKeyFunction() {
// given
final DoubleToIntFunction function = a -> 123;
final DoubleFunction<String> keyFunction = a -> "key";
// when
final DoubleToIntFunction memoize = JCacheMemoize.doubleToIntFunction(function, keyFunction);
// then
Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
项目:memoization.java
文件:JCacheMemoizeLambdaTest.java
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunctionWithLambda() {
// given
// when
final DoubleToIntFunction memoize = JCacheMemoize.doubleToIntFunction(a -> 123);
// then
Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
项目:memoization.java
文件:JCacheMemoizeDefaultsTest.java
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunction() {
// given
final DoubleToIntFunction function = a -> 123;
// when
final DoubleToIntFunction memoize = JCacheMemoize.doubleToIntFunction(function);
// then
Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
项目:memoization.java
文件:ConcurrentMapBasedDoubleToIntFunctionMemoizer.java
@SuppressWarnings(CompilerWarnings.NLS)
ConcurrentMapBasedDoubleToIntFunctionMemoizer(
final ConcurrentMap<KEY, Integer> cache,
final DoubleFunction<KEY> keyFunction,
final DoubleToIntFunction function) {
super(cache);
this.keyFunction = keyFunction;
this.function = requireNonNull(function,
"Cannot memoize a NULL DoubleToIntFunction - provide an actual DoubleToIntFunction to fix this.");
}
项目:memoization.java
文件:MapMemoizeDefaultsTest.java
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunction() {
// given
final DoubleToIntFunction operator = input -> 123;
// when
final DoubleToIntFunction memoize = MapMemoize.doubleToIntFunction(operator);
// then
Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
项目:memoization.java
文件:MapMemoizeLambdaTest.java
/**
*
*/
@Test
public void shouldMemoizeDoubleToIntFunctionWithLambda() {
// given
// when
final DoubleToIntFunction memoize = MapMemoize.doubleToIntFunction(input -> 123);
// then
Assert.assertNotNull("Memoized DoubleToIntFunction is NULL", memoize);
}
项目:memoization.java
文件:ConcurrentMapBasedDoubleToIntFunctionMemoizerTest.java
/**
*
*/
@Test
public void shouldAcceptCacheAndFunction() {
// 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
Assert.assertNotNull("Memoizer is NULL", memoizer);
}
项目: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
文件:ConcurrentMapBasedDoubleToIntFunctionMemoizerTest.java
/**
*
*/
@Test
public void shouldUseReturnFunctionResult() {
// 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
Assert.assertEquals(123, memoizer.applyAsInt(123D));
}
项目: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);
}
项目:throwable-interfaces
文件:DoubleToIntFunctionWithThrowable.java
/**
* @param defaultReturnValue A value to return if any throwable is caught.
* @return An interface that returns a default value if any exception occurs.
*/
default DoubleToIntFunction thatReturnsOnCatch(final int defaultReturnValue) {
return (final double v1) -> {
try {
return applyAsIntWithThrowable(v1);
} catch(final Throwable throwable) {
return defaultReturnValue;
}
};
}