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

项目:OpenJSharp    文件:IntPipeline.java   
@Override
public final LongStream mapToLong(IntToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedInt<Long>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:jdk8u-jdk    文件:IntPipeline.java   
@Override
public final LongStream mapToLong(IntToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedInt<Long>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:openjdk-jdk10    文件:IntPipeline.java   
@Override
public final LongStream mapToLong(IntToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedInt<Long>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:openjdk9    文件:IntPipeline.java   
@Override
public final LongStream mapToLong(IntToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedInt<Long>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:Java8CN    文件:IntPipeline.java   
@Override
public final LongStream mapToLong(IntToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedInt<Long>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:jdk8u_jdk    文件:IntPipeline.java   
@Override
public final LongStream mapToLong(IntToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedInt<Long>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:lookaside_java-1.8.0-openjdk    文件:IntPipeline.java   
@Override
public final LongStream mapToLong(IntToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedInt<Long>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:memoization.java    文件:ConcurrentMapBasedIntToLongFunctionMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<Integer, Long> cache = null;
    final IntToLongFunction function = input -> 123;
    final IntFunction<Integer> keyFunction = Integer::valueOf;

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

    // then
    new ConcurrentMapBasedIntToLongFunctionMemoizer<>(cache, keyFunction, function);
}
项目:memoization.java    文件:ConcurrentMapBasedIntToLongFunctionMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullFunction() {
    // given
    final ConcurrentMap<Integer, Long> cache = new ConcurrentHashMap<>();
    final IntToLongFunction function = null;
    final IntFunction<Integer> keyFunction = Integer::valueOf;

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

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

    // when
    final ConcurrentMapBasedIntToLongFunctionMemoizer<Integer> memoizer = new ConcurrentMapBasedIntToLongFunctionMemoizer<>(
            cache, keyFunction, function);

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

    // when
    final ConcurrentMapBasedIntToLongFunctionMemoizer<Integer> memoizer = new ConcurrentMapBasedIntToLongFunctionMemoizer<>(
            cache, keyFunction, function);

    // then
    memoizer.applyAsLong(123);
    Mockito.verify(function).applyAsLong(123);
}
项目:infobip-open-jdk-8    文件:IntPipeline.java   
@Override
public final LongStream mapToLong(IntToLongFunction mapper) {
    Objects.requireNonNull(mapper);
    return new LongPipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedInt<Long>(sink) {
                @Override
                public void accept(int t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
项目:jdk8u-jdk    文件:SetAllTest.java   
@Test(dataProvider = "long")
public void testSetAllLong(String name, int size, IntToLongFunction generator, long[] expected) {
    long[] result = new long[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(long[], IntToLongFunction) case " + name + " failed.");

    // ensure fresh array
    result = new long[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(long[], IntToLongFunction) case " + name + " failed.");
}
项目:openjdk-jdk10    文件:SetAllTest.java   
@Test(dataProvider = "long")
public void testSetAllLong(String name, int size, IntToLongFunction generator, long[] expected) {
    long[] result = new long[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(long[], IntToLongFunction) case " + name + " failed.");

    // ensure fresh array
    result = new long[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(long[], IntToLongFunction) case " + name + " failed.");
}
项目:openjdk9    文件:SetAllTest.java   
@Test(dataProvider = "long")
public void testSetAllLong(String name, int size, IntToLongFunction generator, long[] expected) {
    long[] result = new long[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(long[], IntToLongFunction) case " + name + " failed.");

    // ensure fresh array
    result = new long[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(long[], IntToLongFunction) case " + name + " failed.");
}
项目:jvm-primitive-ops-benchmarks    文件:AbstractBenchmark.java   
static long lookupRandomIndexes(IntToLongFunction func) {
    long sumOfIndexes = 0;
    Random r = new Random(31);
    for (int i = 0; i < LOOKUPS; i++) {
        int index = 1 + r.nextInt(10);
        sumOfIndexes += func.applyAsLong(index);
    }
    return sumOfIndexes;
}
项目:jdk8u_jdk    文件:SetAllTest.java   
@Test(dataProvider = "long")
public void testSetAllLong(String name, int size, IntToLongFunction generator, long[] expected) {
    long[] result = new long[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(long[], IntToLongFunction) case " + name + " failed.");

    // ensure fresh array
    result = new long[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(long[], IntToLongFunction) case " + name + " failed.");
}
项目:lookaside_java-1.8.0-openjdk    文件:SetAllTest.java   
@Test(dataProvider = "long")
public void testSetAllLong(String name, int size, IntToLongFunction generator, long[] expected) {
    long[] result = new long[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(long[], IntToLongFunction) case " + name + " failed.");

    // ensure fresh array
    result = new long[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(long[], IntToLongFunction) case " + name + " failed.");
}
项目:memoization.java    文件:CaffeineMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeIntToLongFunctionWithKeyFunction() {
    // given
    final IntToLongFunction function = a -> 123L;
    final IntFunction<String> keyFunction = a -> "key";

    // when
    final IntToLongFunction memoize = CaffeineMemoize.intToLongFunction(function, keyFunction);

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

    // when
    final IntToLongFunction memoize = CaffeineMemoize.intToLongFunction(function);

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

    // when
    final IntToLongFunction memoize = CaffeineMemoize.intToLongFunction(a -> 123L);

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

    // when
    final IntToLongFunction memoize = GuavaMemoize.intToLongFunction(function, keyFunction);

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

    // when
    final GuavaCacheBasedIntToLongFunctionMemoizer<Integer> memoizer = new GuavaCacheBasedIntToLongFunctionMemoizer<>(
            cache, keyFunction, function);

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

    // when
    final GuavaCacheBasedIntToLongFunctionMemoizer<Integer> memoizer = new GuavaCacheBasedIntToLongFunctionMemoizer<>(
            cache, keyFunction, function);

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

    // when
    final IntToLongFunction memoize = GuavaMemoize.intToLongFunction(a -> 123L);

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

    // when
    final IntToLongFunction memoize = GuavaMemoize.intToLongFunction(function);

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

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

    // when
    final IntToLongFunction memoize = JCacheMemoize.intToLongFunction(function, keyFunction);

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

    // when
    final IntToLongFunction memoize = JCacheMemoize.intToLongFunction(a -> 123);

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

    // when
    final IntToLongFunction memoize = JCacheMemoize.intToLongFunction(function);

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

    // when
    final IntToLongFunction memoize = MapMemoize.intToLongFunction(operator);

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

    // when
    final IntToLongFunction memoize = MapMemoize.intToLongFunction(input -> 123L);

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

    // when
    final ConcurrentMapBasedIntToLongFunctionMemoizer<Integer> memoizer = new ConcurrentMapBasedIntToLongFunctionMemoizer<>(
            cache, keyFunction, function);

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

    // when
    final ConcurrentMapBasedIntToLongFunctionMemoizer<Integer> memoizer = new ConcurrentMapBasedIntToLongFunctionMemoizer<>(
            cache, keyFunction, function);

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

    // when
    final ConcurrentMapBasedIntToLongFunctionMemoizer<Integer> memoizer = new ConcurrentMapBasedIntToLongFunctionMemoizer<>(
            cache, keyFunction, function);

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

    // when
    final IntToLongFunction memoize = MapMemoize.intToLongFunction(operator, keyFunction);

    // then
    Assert.assertNotNull("Memoized IntToLongFunction is NULL", memoize);
}
项目:parallel-stream-support    文件:ParallelIntStreamSupportTest.java   
@Test
public void mapToLong() {
  IntToLongFunction f = i -> 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);
}