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

项目:OpenJSharp    文件:DoublePipeline.java   
@Override
public final LongStream mapToLong(DoubleToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedDouble<Long>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:jdk8u-jdk    文件:DoublePipeline.java   
@Override
public final LongStream mapToLong(DoubleToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedDouble<Long>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:openjdk-jdk10    文件:DoublePipeline.java   
@Override
public final LongStream mapToLong(DoubleToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedDouble<Long>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:openjdk9    文件:DoublePipeline.java   
@Override
public final LongStream mapToLong(DoubleToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedDouble<Long>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:Java8CN    文件:DoublePipeline.java   
@Override
public final LongStream mapToLong(DoubleToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedDouble<Long>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:jdk8u_jdk    文件:DoublePipeline.java   
@Override
public final LongStream mapToLong(DoubleToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedDouble<Long>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:lookaside_java-1.8.0-openjdk    文件:DoublePipeline.java   
@Override
public final LongStream mapToLong(DoubleToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedDouble<Long>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目: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    文件:ConcurrentMapBasedDoubleToLongFunctionMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullFunction() {
    // given
    final ConcurrentMap<Double, Long> cache = new ConcurrentHashMap<>();
    final DoubleToLongFunction function = null;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

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

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

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

    // then
    memoizer.applyAsLong(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", 123L,
            memoizer.viewCacheForTest().values().iterator().next().longValue());
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleToLongFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldUseCallWrappedFunction() {
    // given
    final ConcurrentMap<Double, Long> cache = new ConcurrentHashMap<>();
    final DoubleToLongFunction function = Mockito.mock(DoubleToLongFunction.class);
    final DoubleFunction<Double> keyFunction = Double::valueOf;

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

    // then
    memoizer.applyAsLong(123D);
    Mockito.verify(function).applyAsLong(123D);
}
项目:jdk8u-dev-jdk    文件:DoublePipeline.java   
@Override
public final LongStream mapToLong(DoubleToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedDouble<Long>(sink) {
                @Override
                public void accept(double t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:memoization.java    文件:CaffeineMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithKeyFunction() {
    // given
    final DoubleToLongFunction function = a -> 123L;
    final DoubleFunction<String> keyFunction = a -> "key";

    // when
    final DoubleToLongFunction memoize = CaffeineMemoize.doubleToLongFunction(function, keyFunction);

    // then
    Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
项目:memoization.java    文件:CaffeineMemoizeDefaultsTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunction() {
    // given
    final DoubleToLongFunction function = a -> 123L;

    // when
    final DoubleToLongFunction memoize = CaffeineMemoize.doubleToLongFunction(function);

    // then
    Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
项目:memoization.java    文件:CaffeineMemoizeLambdaTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithLambda() {
    // given

    // when
    final DoubleToLongFunction memoize = CaffeineMemoize.doubleToLongFunction(a -> 123L);

    // then
    Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
项目:memoization.java    文件:GuavaCacheBasedDoubleToLongFunctionMemoizer.java   
GuavaCacheBasedDoubleToLongFunctionMemoizer(
        final Cache<KEY, Long> cache,
        final DoubleFunction<KEY> keyFunction,
        final DoubleToLongFunction function) {
    super(cache);
    this.keyFunction = keyFunction;
    this.function = function;
}
项目:memoization.java    文件:GuavaMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithKeyFunction() {
    // given
    final DoubleToLongFunction function = a -> 123;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

    // when
    final DoubleToLongFunction memoize = GuavaMemoize.doubleToLongFunction(function, keyFunction);

    // then
    Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
项目:memoization.java    文件:GuavaCacheBasedDoubleToLongFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldAcceptLoadingCache() {
    // given
    final DoubleToLongFunction function = a -> 123L;
    final DoubleFunction<Double> keyFunction = Double::valueOf;
    final Cache<Double, Long> cache = CacheBuilder.newBuilder().build();

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

    // then
    Assert.assertNotNull(memoizer);
}
项目:memoization.java    文件:GuavaCacheBasedDoubleToLongFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldTransformInput() {
    // given
    final DoubleToLongFunction function = a -> 123L;
    final DoubleFunction<Double> keyFunction = Double::valueOf;
    final Cache<Double, Long> cache = CacheBuilder.newBuilder().build();

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

    // then
    Assert.assertEquals("Memoized value does not match expectation", 123L, memoizer.applyAsLong(789D));
}
项目:memoization.java    文件:GuavaMemoizeLambdaTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithLambda() {
    // given

    // when
    final DoubleToLongFunction memoize = GuavaMemoize.doubleToLongFunction(a -> 123);

    // then
    Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
项目:memoization.java    文件:GuavaMemoizeDefaultsTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunction() {
    // given
    final DoubleToLongFunction function = a -> 123;

    // when
    final DoubleToLongFunction memoize = GuavaMemoize.doubleToLongFunction(function);

    // then
    Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
项目:memoization.java    文件:JCacheBasedDoubleToLongFunctionMemoizer.java   
JCacheBasedDoubleToLongFunctionMemoizer(
        final Cache<KEY, Long> cache,
        final DoubleFunction<KEY> keyFunction,
        final DoubleToLongFunction biFunction) {
    super(cache);
    this.keyFunction = keyFunction;
    this.biFunction = biFunction;
}
项目:memoization.java    文件:JCacheBasedDoubleToLongFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldMemoizeBiFunction() {
    // given
    final DoubleToLongFunction function = first -> 123;
    final DoubleFunction<String> keyfunction = a -> "key";
    try (final Cache<String, Long> cache = JCacheMemoize.createCache(ToDoubleBiFunction.class)) {
        // when
        final JCacheBasedDoubleToLongFunctionMemoizer<String> loader = new JCacheBasedDoubleToLongFunctionMemoizer<>(
                cache, keyfunction, function);

        // then
        Assert.assertEquals("Memoized value does not match expectation", 123, loader.applyAsLong(123));
    }
}
项目:memoization.java    文件:JCacheMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithKeyFunction() {
    // given
    final DoubleToLongFunction function = a -> 123;
    final DoubleFunction<String> keyFunction = a -> "key";

    // when
    final DoubleToLongFunction memoize = JCacheMemoize.doubleToLongFunction(function, keyFunction);

    // then
    Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
项目:memoization.java    文件:JCacheMemoizeLambdaTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithLambda() {
    // given

    // when
    final DoubleToLongFunction memoize = JCacheMemoize.doubleToLongFunction(a -> 123);

    // then
    Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
项目:memoization.java    文件:JCacheMemoizeDefaultsTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunction() {
    // given
    final DoubleToLongFunction function = a -> 123;

    // when
    final DoubleToLongFunction memoize = JCacheMemoize.doubleToLongFunction(function);

    // then
    Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleToLongFunctionMemoizer.java   
@SuppressWarnings(CompilerWarnings.NLS)
ConcurrentMapBasedDoubleToLongFunctionMemoizer(
        final ConcurrentMap<KEY, Long> cache,
        final DoubleFunction<KEY> keyFunction,
        final DoubleToLongFunction function) {
    super(cache);
    this.keyFunction = keyFunction;
    this.function = requireNonNull(function,
            "Cannot memoize a NULL DoubleToLongFunction - provide an actual DoubleToLongFunction to fix this.");
}
项目:memoization.java    文件:MapMemoizeDefaultsTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunction() {
    // given
    final DoubleToLongFunction operator = input -> 123L;

    // when
    final DoubleToLongFunction memoize = MapMemoize.doubleToLongFunction(operator);

    // then
    Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
项目:memoization.java    文件:MapMemoizeLambdaTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithLambda() {
    // given

    // when
    final DoubleToLongFunction memoize = MapMemoize.doubleToLongFunction(input -> 123L);

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

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

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

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

    // then
    memoizer.applyAsLong(123.456D);
}
项目:memoization.java    文件:ConcurrentMapBasedDoubleToLongFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldUseReturnFunctionResult() {
    // given
    final ConcurrentMap<Double, Long> cache = new ConcurrentHashMap<>();
    final DoubleToLongFunction function = input -> 123;
    final DoubleFunction<Double> keyFunction = Double::valueOf;

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

    // then
    Assert.assertEquals(123L, memoizer.applyAsLong(123D));
}
项目:memoization.java    文件:MapMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeDoubleToLongFunctionWithKeyFunction() {
    // given
    final DoubleToLongFunction operator = input -> 123L;
    final DoubleFunction<String> keyFunction = a -> "key";

    // when
    final DoubleToLongFunction memoize = MapMemoize.doubleToLongFunction(operator, keyFunction);

    // then
    Assert.assertNotNull("Memoized DoubleToLongFunction is NULL", memoize);
}
项目:throwable-interfaces    文件:DoubleToLongFunctionWithThrowable.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 DoubleToLongFunction thatReturnsOnCatch(final long defaultReturnValue) {
  return (final double v1) -> {
    try {
      return applyAsLongWithThrowable(v1);
    } catch(final Throwable throwable) {
      return defaultReturnValue;
    }
  };
}
项目:throwable-interfaces    文件:DoubleToLongFunctionWithThrowable.java   
/**
 * @throws E if an exception E has been thrown, it is rethrown by this method
 * @return An interface that is only returned if no exception has been thrown.
 */
default DoubleToLongFunction thatUnsafelyThrowsUnchecked() throws E {
  return (final double v1) -> {
    try {
      return applyAsLongWithThrowable(v1);
    } catch(final Throwable throwable) {
       SuppressedException.throwUnsafelyAsUnchecked(throwable);
       return 0;        }
  };
}
项目:parallel-stream-support    文件:ParallelDoubleStreamSupportTest.java   
@Test
public void mapToLong() {
  DoubleToLongFunction f = d -> 1L;
  LongStream stream = this.parallelStreamSupportMock.mapToLong(f);

  verify(this.delegateMock).mapToLong(f);
  assertThat(stream, instanceOf(ParallelLongStreamSupport.class));
  assertSame(ParallelLongStreamSupport.class.cast(stream).delegate, this.mappedLongDelegateMock);
  assertSame(ParallelLongStreamSupport.class.cast(stream).workerPool, this.workerPool);
}
项目:monadic-exceptions    文件:ThrowableDoubleToLongFunction.java   
/**
 * @param function
 * @return
 */
public static DoubleToLongFunction asDoubleToLongFunction(final ThrowableDoubleToLongFunction function) {
    return t -> {
        long result;

        try {
            result = function.applyAsLong(t);
        } catch (Exception e) {
            throw new MonadicException(e);
        }

        return result;
    };
}
项目:throwable-interfaces    文件:DoubleToLongFunctionWithThrowable.java   
/**
 * @throws E if an exception E has been thrown, it is rethrown by this method
 * @return An interface that is only returned if no exception has been thrown.
 */
default DoubleToLongFunction thatUnsafelyThrowsUnchecked() throws E {
  return (final double v1) -> {
    try {
      return applyAsLongWithThrowable(v1);
    } catch(final Throwable throwable) {
       SuppressedException.throwUnsafelyAsUnchecked(throwable);
       return 0;        }
  };
}
项目:LambdaOmega    文件:F.java   
F(DoubleToLongFunction doubleToLongFunction) {
    this((Function<T, R>) new Function<Double, Long>() {
        @Override
        public Long apply(Double t) {
            return doubleToLongFunction.applyAsLong(t);
        }
    });
}
项目:openjdk-jdk10    文件:DefaultMethodStreams.java   
@Override
public LongStream mapToLong(DoubleToLongFunction mapper) {
    return s.mapToLong(mapper);
}