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

项目:OpenJSharp    文件:LongPipeline.java   
@Override
public final IntStream mapToInt(LongToIntFunction mapper) {
    Objects.requireNonNull(mapper);
    return new IntPipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                             StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedLong<Integer>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
项目:jdk8u-jdk    文件:LongPipeline.java   
@Override
public final IntStream mapToInt(LongToIntFunction mapper) {
    Objects.requireNonNull(mapper);
    return new IntPipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                             StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedLong<Integer>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
项目:openjdk-jdk10    文件:LongPipeline.java   
@Override
public final IntStream mapToInt(LongToIntFunction mapper) {
    Objects.requireNonNull(mapper);
    return new IntPipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                             StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedLong<Integer>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
项目:openjdk9    文件:LongPipeline.java   
@Override
public final IntStream mapToInt(LongToIntFunction mapper) {
    Objects.requireNonNull(mapper);
    return new IntPipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                             StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedLong<Integer>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
项目:Java8CN    文件:LongPipeline.java   
@Override
public final IntStream mapToInt(LongToIntFunction mapper) {
    Objects.requireNonNull(mapper);
    return new IntPipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                             StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedLong<Integer>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
项目:jdk8u_jdk    文件:LongPipeline.java   
@Override
public final IntStream mapToInt(LongToIntFunction mapper) {
    Objects.requireNonNull(mapper);
    return new IntPipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                             StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedLong<Integer>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
项目:lookaside_java-1.8.0-openjdk    文件:LongPipeline.java   
@Override
public final IntStream mapToInt(LongToIntFunction mapper) {
    Objects.requireNonNull(mapper);
    return new IntPipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                             StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedLong<Integer>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
项目:memoization.java    文件:ConcurrentMapBasedLongToIntFunctionMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<Long, Integer> cache = null;
    final LongToIntFunction 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 ConcurrentMapBasedLongToIntFunctionMemoizer<>(cache, keyFunction, function);
}
项目:memoization.java    文件:ConcurrentMapBasedLongToIntFunctionMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullFunction() {
    // given
    final ConcurrentMap<Long, Integer> cache = new ConcurrentHashMap<>();
    final LongToIntFunction function = null;
    final LongFunction<Long> keyFunction = Long::valueOf;

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

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

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

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

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

    // then
    memoizer.applyAsInt(123L);
    Mockito.verify(function).applyAsInt(123L);
}
项目:jdk8u-dev-jdk    文件:LongPipeline.java   
@Override
public final IntStream mapToInt(LongToIntFunction mapper) {
    Objects.requireNonNull(mapper);
    return new IntPipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                             StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedLong<Integer>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
项目:infobip-open-jdk-8    文件:LongPipeline.java   
@Override
public final IntStream mapToInt(LongToIntFunction mapper) {
    Objects.requireNonNull(mapper);
    return new IntPipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                             StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedLong<Integer>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsInt(t));
                }
            };
        }
    };
}
项目:memoization.java    文件:CaffeineMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeLongToIntFunctionWithKeyFunction() {
    // given
    final LongToIntFunction function = a -> 123;
    final LongFunction<String> keyFunction = a -> "key";

    // when
    final LongToIntFunction memoize = CaffeineMemoize.longToIntFunction(function, keyFunction);

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

    // when
    final LongToIntFunction memoize = CaffeineMemoize.longToIntFunction(function);

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

    // when
    final LongToIntFunction memoize = CaffeineMemoize.longToIntFunction(a -> 123);

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

    // when
    final LongToIntFunction memoize = GuavaMemoize.longToIntFunction(function, keyFunction);

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

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

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

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

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

    // when
    final LongToIntFunction memoize = GuavaMemoize.longToIntFunction(a -> 123);

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

    // when
    final LongToIntFunction memoize = GuavaMemoize.longToIntFunction(function);

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

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

    // when
    final LongToIntFunction memoize = JCacheMemoize.longToIntFunction(function, keyFunction);

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

    // when
    final LongToIntFunction memoize = JCacheMemoize.longToIntFunction(a -> 123);

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

    // when
    final LongToIntFunction memoize = JCacheMemoize.longToIntFunction(function);

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

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

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

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

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

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

    // then
    Assert.assertEquals(123, memoizer.applyAsInt(123L));
}
项目:memoization.java    文件:MapMemoizeDefaultsTest.java   
/**
*
*/
@Test
public void shouldMemoizeLongToIntFunction() {
    // given
    final LongToIntFunction operator = input -> 123;

    // when
    final LongToIntFunction memoize = MapMemoize.longToIntFunction(operator);

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

    // when
    final LongToIntFunction memoize = MapMemoize.longToIntFunction(input -> 123);

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

    // when
    final LongToIntFunction memoize = MapMemoize.longToIntFunction(operator, keyFunction);

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

  verify(this.delegateMock).mapToInt(f);
  assertThat(stream, instanceOf(ParallelIntStreamSupport.class));
  assertSame(ParallelIntStreamSupport.class.cast(stream).delegate, this.mappedIntDelegateMock);
  assertSame(ParallelIntStreamSupport.class.cast(stream).workerPool, this.workerPool);
}
项目:monadic-exceptions    文件:ThrowableLongToIntFunction.java   
/**
 * @param function
 * @return
 */
public static LongToIntFunction asLongToIntFunction(final ThrowableLongToIntFunction function) {
    return t -> {
        int result;

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

        return result;
    };
}
项目:throwable-interfaces    文件:LongToIntFunctionWithThrowable.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 LongToIntFunction thatReturnsOnCatch(final int defaultReturnValue) {
  return (final long v1) -> {
    try {
      return applyAsIntWithThrowable(v1);
    } catch(final Throwable throwable) {
      return defaultReturnValue;
    }
  };
}
项目:openjdk-jdk10    文件:DefaultMethodStreams.java   
@Override
public IntStream mapToInt(LongToIntFunction mapper) {
    return s.mapToInt(mapper);
}