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

项目:OpenJSharp    文件:LongPipeline.java   
@Override
public final DoubleStream mapToDouble(LongToDoubleFunction mapper) {
    Objects.requireNonNull(mapper);
    return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedLong<Double>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsDouble(t));
                }
            };
        }
    };
}
项目:jdk8u-jdk    文件:LongPipeline.java   
@Override
public final DoubleStream mapToDouble(LongToDoubleFunction mapper) {
    Objects.requireNonNull(mapper);
    return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedLong<Double>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsDouble(t));
                }
            };
        }
    };
}
项目:openjdk-jdk10    文件:LongPipeline.java   
@Override
public final DoubleStream mapToDouble(LongToDoubleFunction mapper) {
    Objects.requireNonNull(mapper);
    return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedLong<Double>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsDouble(t));
                }
            };
        }
    };
}
项目:openjdk9    文件:LongPipeline.java   
@Override
public final DoubleStream mapToDouble(LongToDoubleFunction mapper) {
    Objects.requireNonNull(mapper);
    return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedLong<Double>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsDouble(t));
                }
            };
        }
    };
}
项目:Java8CN    文件:LongPipeline.java   
@Override
public final DoubleStream mapToDouble(LongToDoubleFunction mapper) {
    Objects.requireNonNull(mapper);
    return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedLong<Double>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsDouble(t));
                }
            };
        }
    };
}
项目:metagen-java    文件:RealDistributionsConcurrencyTests.java   
@Override
        public double[] call() throws Exception {
            double[] output = new double[size];
            LongToDoubleFunction mapper = RealDistributions.forSpec(mapperSpec);
//            System.out.println("resolved:" + mapper);
//            System.out.flush();

            synchronized (signal) {
                signal.wait(10000);
            }

            for (int i = 0; i < output.length; i++) {
                output[i] = mapper.applyAsDouble(i);
//                if ((i % 100) == 0) {
//                    System.out.println("wrote t:" + slot + ", iter:" + i + ", val:" + output[i]);
//                }
            }
            return output;
        }
项目:jdk8u_jdk    文件:LongPipeline.java   
@Override
public final DoubleStream mapToDouble(LongToDoubleFunction mapper) {
    Objects.requireNonNull(mapper);
    return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedLong<Double>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsDouble(t));
                }
            };
        }
    };
}
项目:lookaside_java-1.8.0-openjdk    文件:LongPipeline.java   
@Override
public final DoubleStream mapToDouble(LongToDoubleFunction mapper) {
    Objects.requireNonNull(mapper);
    return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedLong<Double>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsDouble(t));
                }
            };
        }
    };
}
项目:memoization.java    文件:ConcurrentMapBasedLongToDoubleFunctionMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<Long, Double> cache = null;
    final LongToDoubleFunction function = input -> 123;
    final LongFunction<Long> keyFunction = Long::valueOf;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Provide an empty map instead of NULL.");

    // then
    new ConcurrentMapBasedLongToDoubleFunctionMemoizer<>(cache, keyFunction, function);
}
项目:memoization.java    文件:ConcurrentMapBasedLongToDoubleFunctionMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullFunction() {
    // given
    final ConcurrentMap<Long, Double> cache = new ConcurrentHashMap<>();
    final LongToDoubleFunction function = null;
    final LongFunction<Long> keyFunction = Long::valueOf;

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

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

    // when
    final ConcurrentMapBasedLongToDoubleFunctionMemoizer<Long> memoizer = new ConcurrentMapBasedLongToDoubleFunctionMemoizer<>(
            cache, keyFunction, function);

    // then
    memoizer.applyAsDouble(123);
    Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
    Assert.assertEquals("Memoization key does not match expectations", 123,
            memoizer.viewCacheForTest().keySet().iterator().next().intValue());
    Assert.assertEquals("Memoization value does not match expectations", 123D,
            memoizer.viewCacheForTest().values().iterator().next().doubleValue(), 0.0D);
}
项目:memoization.java    文件:ConcurrentMapBasedLongToDoubleFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldUseCallWrappedFunction() {
    // given
    final ConcurrentMap<Long, Double> cache = new ConcurrentHashMap<>();
    final LongToDoubleFunction function = Mockito.mock(LongToDoubleFunction.class);
    final LongFunction<Long> keyFunction = Long::valueOf;

    // when
    final ConcurrentMapBasedLongToDoubleFunctionMemoizer<Long> memoizer = new ConcurrentMapBasedLongToDoubleFunctionMemoizer<>(
            cache, keyFunction, function);

    // then
    memoizer.applyAsDouble(123);
    Mockito.verify(function).applyAsDouble(123);
}
项目:jdk8u-dev-jdk    文件:LongPipeline.java   
@Override
public final DoubleStream mapToDouble(LongToDoubleFunction mapper) {
    Objects.requireNonNull(mapper);
    return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedLong<Double>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsDouble(t));
                }
            };
        }
    };
}
项目:infobip-open-jdk-8    文件:LongPipeline.java   
@Override
public final DoubleStream mapToDouble(LongToDoubleFunction mapper) {
    Objects.requireNonNull(mapper);
    return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                                StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedLong<Double>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsDouble(t));
                }
            };
        }
    };
}
项目:metagen-java    文件:RealDistributions.java   
public static LongToDoubleFunction forSpec(String spec) {
    Optional<ResolvedFunction> resolvedFunction = new RealDistributions().resolveFunction(spec);
    return resolvedFunction
            .map(ResolvedFunction::getFunctionObject)
            .map(f -> ((LongToDoubleFunction) f))
            .orElseThrow(() -> new RuntimeException("Invalid spec: " + spec));
}
项目:memoization.java    文件:CaffeineMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunctionWithKeyFunction() {
    // given
    final LongToDoubleFunction function = a -> 123.456D;
    final LongFunction<String> keyFunction = a -> "key";

    // when
    final LongToDoubleFunction memoize = CaffeineMemoize.longToDoubleFunction(function, keyFunction);

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

    // when
    final LongToDoubleFunction memoize = CaffeineMemoize.longToDoubleFunction(function);

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

    // when
    final LongToDoubleFunction memoize = CaffeineMemoize.longToDoubleFunction(a -> 123.456D);

    // then
    Assert.assertNotNull("Memoized LongToDoubleFunction is NULL", memoize);
}
项目:memoization.java    文件:GuavaCacheBasedLongToDoubleFunctionMemoizer.java   
GuavaCacheBasedLongToDoubleFunctionMemoizer(
        final Cache<KEY, Double> cache,
        final LongFunction<KEY> keyFunction,
        final LongToDoubleFunction function) {
    super(cache);
    this.keyFunction = keyFunction;
    this.function = function;
}
项目:memoization.java    文件:GuavaMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunctionWithKeyFunction() {
    // given
    final LongToDoubleFunction function = a -> 123D;
    final LongFunction<String> keyFunction = a -> "key";

    // when
    final LongToDoubleFunction memoize = GuavaMemoize.longToDoubleFunction(function, keyFunction);

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

    // when
    final LongToDoubleFunction memoize = GuavaMemoize.longToDoubleFunction(a -> 123D);

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

    // when
    final GuavaCacheBasedLongToDoubleFunctionMemoizer<Long> memoizer = new GuavaCacheBasedLongToDoubleFunctionMemoizer<>(
            cache, keyFunction, function);

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

    // when
    final GuavaCacheBasedLongToDoubleFunctionMemoizer<Long> memoizer = new GuavaCacheBasedLongToDoubleFunctionMemoizer<>(
            cache, keyFunction, function);

    // then
    Assert.assertEquals("Memoized value does not match expectation", 123.456D, memoizer.applyAsDouble(789), 0.0D);
}
项目:memoization.java    文件:GuavaMemoizeDefaultsTest.java   
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunction() {
    // given
    final LongToDoubleFunction function = a -> 123D;

    // when
    final LongToDoubleFunction memoize = GuavaMemoize.longToDoubleFunction(function);

    // then
    Assert.assertNotNull("Memoized LongToDoubleFunction is NULL", memoize);
}
项目:memoization.java    文件:JCacheBasedLongToDoubleFunctionMemoizer.java   
JCacheBasedLongToDoubleFunctionMemoizer(
        final Cache<KEY, Double> cache,
        final LongFunction<KEY> keyFunction,
        final LongToDoubleFunction biFunction) {
    super(cache);
    this.keyFunction = keyFunction;
    this.biFunction = biFunction;
}
项目:memoization.java    文件:JCacheMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunctionWithKeyFunction() {
    // given
    final LongToDoubleFunction function = a -> 123;
    final LongFunction<String> keyFunction = a -> "key";

    // when
    final LongToDoubleFunction memoize = JCacheMemoize.longToDoubleFunction(function, keyFunction);

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

    // when
    final LongToDoubleFunction memoize = JCacheMemoize.longToDoubleFunction(a -> 123);

    // then
    Assert.assertNotNull("Memoized LongToDoubleFunction is NULL", memoize);
}
项目:memoization.java    文件:JCacheBasedLongToDoubleFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldMemoizeBiFunction() {
    // given
    final LongToDoubleFunction function = first -> 123;
    final LongFunction<String> keyfunction = a -> "key";
    try (final Cache<String, Double> cache = JCacheMemoize.createCache(ToDoubleBiFunction.class)) {
        // when
        final JCacheBasedLongToDoubleFunctionMemoizer<String> loader = new JCacheBasedLongToDoubleFunctionMemoizer<>(
                cache, keyfunction, function);

        // then
        Assert.assertEquals("Memoized value does not match expectation", 123D, loader.applyAsDouble(123), 0.0D);
    }
}
项目:memoization.java    文件:JCacheMemoizeDefaultsTest.java   
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunction() {
    // given
    final LongToDoubleFunction function = a -> 123;

    // when
    final LongToDoubleFunction memoize = JCacheMemoize.longToDoubleFunction(function);

    // then
    Assert.assertNotNull("Memoized LongToDoubleFunction is NULL", memoize);
}
项目:memoization.java    文件:ConcurrentMapBasedLongToDoubleFunctionMemoizer.java   
@SuppressWarnings(CompilerWarnings.NLS)
ConcurrentMapBasedLongToDoubleFunctionMemoizer(
        final ConcurrentMap<KEY, Double> cache,
        final LongFunction<KEY> keyFunction,
        final LongToDoubleFunction function) {
    super(cache);
    this.keyFunction = keyFunction;
    this.function = requireNonNull(function,
            "Cannot memoize a NULL LongToDoubleFunction - provide an actual LongToDoubleFunction to fix this.");
}
项目:memoization.java    文件:ConcurrentMapBasedLongToDoubleFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldAcceptCacheAndFunction() {
    // given
    final ConcurrentMap<Long, Double> cache = new ConcurrentHashMap<>();
    final LongToDoubleFunction function = input -> 123;
    final LongFunction<Long> keyFunction = Long::valueOf;

    // when
    final ConcurrentMapBasedLongToDoubleFunctionMemoizer<Long> memoizer = new ConcurrentMapBasedLongToDoubleFunctionMemoizer<>(
            cache, keyFunction, function);

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

    // when
    final ConcurrentMapBasedLongToDoubleFunctionMemoizer<Long> memoizer = new ConcurrentMapBasedLongToDoubleFunctionMemoizer<>(
            cache, keyFunction, function);

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

    // when
    final ConcurrentMapBasedLongToDoubleFunctionMemoizer<Long> memoizer = new ConcurrentMapBasedLongToDoubleFunctionMemoizer<>(
            cache, keyFunction, function);

    // then
    Assert.assertEquals(123D, memoizer.applyAsDouble(123), 0.0D);
}
项目:memoization.java    文件:MapMemoizeDefaultsTest.java   
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunction() {
    // given
    final LongToDoubleFunction operator = input -> 123D;

    // when
    final LongToDoubleFunction memoize = MapMemoize.longToDoubleFunction(operator);

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

    // when
    final LongToDoubleFunction memoize = MapMemoize.longToDoubleFunction(input -> 123D);

    // then
    Assert.assertNotNull("Memoized LongToDoubleFunction is NULL", memoize);
}
项目:memoization.java    文件:MapMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeLongToDoubleFunctionWithKeyFunction() {
    // given
    final LongToDoubleFunction operator = input -> 123D;
    final LongFunction<String> keyFunction = a -> "key";

    // when
    final LongToDoubleFunction memoize = MapMemoize.longToDoubleFunction(operator, keyFunction);

    // then
    Assert.assertNotNull("Memoized LongToDoubleFunction is NULL", memoize);
}
项目:throwable-interfaces    文件:LongToDoubleFunctionWithThrowable.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 LongToDoubleFunction thatReturnsOnCatch(final double defaultReturnValue) {
  return (final long v1) -> {
    try {
      return applyAsDoubleWithThrowable(v1);
    } catch(final Throwable throwable) {
      return defaultReturnValue;
    }
  };
}
项目:throwable-interfaces    文件:LongToDoubleFunctionWithThrowable.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 LongToDoubleFunction thatUnsafelyThrowsUnchecked() throws E {
  return (final long v1) -> {
    try {
      return applyAsDoubleWithThrowable(v1);
    } catch(final Throwable throwable) {
       SuppressedException.throwUnsafelyAsUnchecked(throwable);
       return 0;        }
  };
}
项目:parallel-stream-support    文件:ParallelLongStreamSupportTest.java   
@Test
public void mapToDouble() {
  LongToDoubleFunction f = i -> 1.0;
  DoubleStream stream = this.parallelStreamSupportMock.mapToDouble(f);

  verify(this.delegateMock).mapToDouble(f);
  assertThat(stream, instanceOf(ParallelDoubleStreamSupport.class));
  assertSame(ParallelDoubleStreamSupport.class.cast(stream).delegate, this.mappedDoubleDelegateMock);
  assertSame(ParallelDoubleStreamSupport.class.cast(stream).workerPool, this.workerPool);
}
项目:throwable-interfaces    文件:LongToDoubleFunctionWithThrowable.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 LongToDoubleFunction thatReturnsOnCatch(final double defaultReturnValue) {
  return (final long v1) -> {
    try {
      return applyAsDoubleWithThrowable(v1);
    } catch(final Throwable throwable) {
      return defaultReturnValue;
    }
  };
}