java.util.function.ToIntFunction Java Examples

The following examples show how to use java.util.function.ToIntFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmployeeServiceImpl.java    From Spring-5.0-Cookbook with MIT License 6 votes vote down vote up
@Override
public Mono<Double> getAveAge() {
	ToIntFunction<Employee> sizeEmpArr = (e) -> {
		System.out.println("flux:toIntFunction task executor: " + Thread.currentThread().getName());
		System.out.println("flux:toIntFunction task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
		return e.getAge();
	};
	Callable<Double> task = () ->{
		System.out.println("flux:callable task executor: " + Thread.currentThread().getName());
		System.out.println("flux:callable task executor login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
		return employeeDaoImpl.getEmployees().stream()
		.mapToInt(sizeEmpArr)
		.average()
		.getAsDouble();
	};

	Mono<Double> aveAge= Mono.fromCallable(task);
	return aveAge;
}
 
Example #2
Source File: ReferencePipeline.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public final IntStream mapToInt(ToIntFunction<? super P_OUT> mapper) {
    Objects.requireNonNull(mapper);
    return new IntPipeline.StatelessOp<P_OUT>(this, StreamShape.REFERENCE,
                                          StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<P_OUT> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedReference<P_OUT, Integer>(sink) {
                @Override
                public void accept(P_OUT u) {
                    downstream.accept(mapper.applyAsInt(u));
                }
            };
        }
    };
}
 
Example #3
Source File: TestClientsWithApacheServer.java    From drift with Apache License 2.0 6 votes vote down vote up
private static int testApacheServer(List<MethodInvocationFilter> filters)
        throws Exception
{
    ScribeService scribeService = new ScribeService();
    TProcessor processor = new scribe.Processor<>(scribeService);

    int invocationCount = 0;
    for (boolean secure : ImmutableList.of(true, false)) {
        for (Transport transport : Transport.values()) {
            for (Protocol protocol : Protocol.values()) {
                invocationCount += testApacheServer(secure, transport, protocol, processor, ImmutableList.<ToIntFunction<HostAndPort>>builder()
                        .addAll(legacyApacheThriftTestClients(filters, transport, protocol, secure))
                        .addAll(driftNettyTestClients(filters, transport, protocol, secure))
                        .addAll(apacheThriftTestClients(filters, transport, protocol, secure))
                        .build());
            }
        }
    }

    assertEquals(scribeService.getMessages(), newArrayList(concat(nCopies(invocationCount, MESSAGES))));

    return invocationCount;
}
 
Example #4
Source File: TestDriftNettyServerTransport.java    From drift with Apache License 2.0 6 votes vote down vote up
private static int testServerMethodInvoker(ServerMethodInvoker methodInvoker, boolean assumeClientsSupportOutOfOrderResponses, List<ToIntFunction<HostAndPort>> clients)
{
    DriftNettyServerConfig config = new DriftNettyServerConfig()
            .setAssumeClientsSupportOutOfOrderResponses(assumeClientsSupportOutOfOrderResponses);
    TestingPooledByteBufAllocator testingAllocator = new TestingPooledByteBufAllocator();
    ServerTransport serverTransport = new DriftNettyServerTransportFactory(config, testingAllocator).createServerTransport(methodInvoker);
    try {
        serverTransport.start();

        HostAndPort address = HostAndPort.fromParts("localhost", ((DriftNettyServerTransport) serverTransport).getPort());

        int sum = 0;
        for (ToIntFunction<HostAndPort> client : clients) {
            sum += client.applyAsInt(address);
        }
        return sum;
    }
    finally {
        serverTransport.shutdown();
        testingAllocator.close();
    }
}
 
Example #5
Source File: ShapeKey.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public ShapeKey(
		final T shapeId,
		final int scaleIndex,
		final int simplificationIterations,
		final double smoothingLambda,
		final int smoothingIterations,
		final double minLabelRatio,
		final long[] min,
		final long[] max,
		final ToIntFunction<T> shapeIdHashCode,
		final BiPredicate<T, Object> shapeIdEquals)
{
	this.shapeId = shapeId;
	this.scaleIndex = scaleIndex;
	this.simplificationIterations = simplificationIterations;
	this.smoothingLambda = smoothingLambda;
	this.smoothingIterations = smoothingIterations;
	this.minLabelRatio = minLabelRatio;
	this.min = min;
	this.max = max;
	this.shapeIdHashCode = shapeIdHashCode;
	this.shapeIdEquals = shapeIdEquals;
}
 
Example #6
Source File: TestData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected RefTestData(String name,
                      I state,
                      Function<I, Stream<T>> streamFn,
                      Function<I, Stream<T>> parStreamFn,
                      Function<I, Spliterator<T>> splitrFn,
                      ToIntFunction<I> sizeFn) {
    super(name, StreamShape.REFERENCE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #7
Source File: TestData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected IntTestData(String name,
                      I state,
                      Function<I, IntStream> streamFn,
                      Function<I, IntStream> parStreamFn,
                      Function<I, Spliterator.OfInt> splitrFn,
                      ToIntFunction<I> sizeFn) {
    super(name, StreamShape.INT_VALUE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #8
Source File: EmployeeParallelStreamService.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public double getParallelAverageAge(){
    ToIntFunction<Employee> sizeEmpArr = (e) -> {
    	System.out.println("Thread: " + Thread.currentThread().getName());
    	return e.getAge();
    };
	return employeeDaoImpl.getEmployees().parallelStream().mapToInt(sizeEmpArr).average().getAsDouble();
}
 
Example #9
Source File: EmployeeParallelStreamService.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public double getSequentialAverageAge(){
   ToIntFunction<Employee> sizeEmpArr = (e) -> {
    System.out.println("Thread: " + Thread.currentThread().getName());
    	return e.getAge();
   };
   return employeeDaoImpl.getEmployees().stream().mapToInt(sizeEmpArr).average().getAsDouble();
}
 
Example #10
Source File: TestData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected IntTestData(String name,
                      I state,
                      Function<I, IntStream> streamFn,
                      Function<I, IntStream> parStreamFn,
                      Function<I, Spliterator.OfInt> splitrFn,
                      ToIntFunction<I> sizeFn) {
    super(name, StreamShape.INT_VALUE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #11
Source File: ClassLoaderSafeNodePartitioningProvider.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public ToIntFunction<ConnectorSplit> getSplitBucketFunction(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle)
{
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        return delegate.getSplitBucketFunction(transactionHandle, session, partitioningHandle);
    }
}
 
Example #12
Source File: TestData.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected LongTestData(String name,
                       I state,
                       Function<I, LongStream> streamFn,
                       Function<I, LongStream> parStreamFn,
                       Function<I, Spliterator.OfLong> splitrFn,
                       ToIntFunction<I> sizeFn) {
    super(name, StreamShape.LONG_VALUE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #13
Source File: TestData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected RefTestData(String name,
                      I state,
                      Function<I, Stream<T>> streamFn,
                      Function<I, Stream<T>> parStreamFn,
                      Function<I, Spliterator<T>> splitrFn,
                      ToIntFunction<I> sizeFn) {
    super(name, StreamShape.REFERENCE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #14
Source File: TestData.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected IntTestData(String name,
                      I state,
                      Function<I, IntStream> streamFn,
                      Function<I, IntStream> parStreamFn,
                      Function<I, Spliterator.OfInt> splitrFn,
                      ToIntFunction<I> sizeFn) {
    super(name, StreamShape.INT_VALUE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #15
Source File: TestData.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected LongTestData(String name,
                       I state,
                       Function<I, LongStream> streamFn,
                       Function<I, LongStream> parStreamFn,
                       Function<I, Spliterator.OfLong> splitrFn,
                       ToIntFunction<I> sizeFn) {
    super(name, StreamShape.LONG_VALUE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #16
Source File: BlackHoleNodePartitioningProvider.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public ToIntFunction<ConnectorSplit> getSplitBucketFunction(
        ConnectorTransactionHandle transactionHandle,
        ConnectorSession session,
        ConnectorPartitioningHandle partitioningHandle)
{
    return value -> {
        throw new PrestoException(NOT_SUPPORTED, "Black hole connector does not supported distributed reads");
    };
}
 
Example #17
Source File: TestData.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected DoubleTestData(String name,
                         I state,
                         Function<I, DoubleStream> streamFn,
                         Function<I, DoubleStream> parStreamFn,
                         Function<I, Spliterator.OfDouble> splitrFn,
                         ToIntFunction<I> sizeFn) {
    super(name, StreamShape.DOUBLE_VALUE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #18
Source File: TestData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
AbstractTestData(String name,
                 StreamShape shape,
                 T_STATE state,
                 Function<T_STATE, S> streamFn,
                 Function<T_STATE, S> parStreamFn,
                 Function<T_STATE, T_SPLITR> splitrFn,
                 ToIntFunction<T_STATE> sizeFn) {
    this.name = name;
    this.shape = shape;
    this.state = state;
    this.streamFn = streamFn;
    this.parStreamFn = parStreamFn;
    this.splitrFn = splitrFn;
    this.sizeFn = sizeFn;
}
 
Example #19
Source File: TestData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected LongTestData(String name,
                       I state,
                       Function<I, LongStream> streamFn,
                       Function<I, LongStream> parStreamFn,
                       Function<I, Spliterator.OfLong> splitrFn,
                       ToIntFunction<I> sizeFn) {
    super(name, StreamShape.LONG_VALUE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #20
Source File: CollectStageFactoryTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test
public void create() throws ExecutionException, InterruptedException {
    TerminalStage<Integer, Integer> terminal = factory.create(null,
            () -> Collectors.summingInt((ToIntFunction<Integer>) value -> value));

    List<Integer> list = new ArrayList<>();
    Flowable<Integer> flowable = Flowable.fromArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
            .doOnNext(list::add)
            .subscribeOn(Schedulers.computation());
    CompletionStage<Integer> stage = terminal.apply(flowable);
    Integer result = stage.toCompletableFuture().get();

    assertThat(result).isEqualTo(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10);
    assertThat(list).hasSize(10);
}
 
Example #21
Source File: TestData.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
AbstractTestData(String name,
                 StreamShape shape,
                 T_STATE state,
                 Function<T_STATE, S> streamFn,
                 Function<T_STATE, S> parStreamFn,
                 Function<T_STATE, T_SPLITR> splitrFn,
                 ToIntFunction<T_STATE> sizeFn) {
    this.name = name;
    this.shape = shape;
    this.state = state;
    this.streamFn = streamFn;
    this.parStreamFn = parStreamFn;
    this.splitrFn = splitrFn;
    this.sizeFn = sizeFn;
}
 
Example #22
Source File: TestData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected IntTestData(String name,
                      I state,
                      Function<I, IntStream> streamFn,
                      Function<I, IntStream> parStreamFn,
                      Function<I, Spliterator.OfInt> splitrFn,
                      ToIntFunction<I> sizeFn) {
    super(name, StreamShape.INT_VALUE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #23
Source File: BasicTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void testIntComparator() {
    Thing[] things = new Thing[intValues.length];
    for (int i=0; i<intValues.length; i++)
        things[i] = new Thing(intValues[i], 0L, 0.0, null);
    Comparator<Thing> comp = Comparator.comparingInt(new ToIntFunction<Thing>() {
        @Override
        public int applyAsInt(Thing thing) {
            return thing.getIntField();
        }
    });

    assertComparisons(things, comp, comparisons);
}
 
Example #24
Source File: XDataFrame.java    From morpheus-core with Apache License 2.0 5 votes vote down vote up
@Override
public DataFrame<R, C> mapToInts(ToIntFunction<DataFrameValue<R, C>> mapper) {
    final Array<R> rowKeys = rows().keyArray();
    final Array<C> colKeys = cols().keyArray();
    final XDataFrame<R,C> result = (XDataFrame<R,C>)DataFrame.ofInts(rowKeys, colKeys);
    this.forEachValue(v -> {
        final int value = mapper.applyAsInt(v);
        final int rowOrdinal = v.rowOrdinal();
        final int colOrdinal = v.colOrdinal();
        result.content().setInt(rowOrdinal, colOrdinal, value);
    });
    return result;
}
 
Example #25
Source File: MinimalSourceStateSerializer.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MinimalSourceStateSerializer createSerializer(
		final Supplier<String> projectDirectory,
		final ToIntFunction<SourceState<?, ?>> stateToIndex)
{
	return new MinimalSourceStateSerializer(stateToIndex);
}
 
Example #26
Source File: BasicTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testIntComparator() {
    Thing[] things = new Thing[intValues.length];
    for (int i=0; i<intValues.length; i++)
        things[i] = new Thing(intValues[i], 0L, 0.0, null);
    Comparator<Thing> comp = Comparator.comparingInt(new ToIntFunction<Thing>() {
        @Override
        public int applyAsInt(Thing thing) {
            return thing.getIntField();
        }
    });

    assertComparisons(things, comp, comparisons);
}
 
Example #27
Source File: BasicTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void testIntComparator() {
    Thing[] things = new Thing[intValues.length];
    for (int i=0; i<intValues.length; i++)
        things[i] = new Thing(intValues[i], 0L, 0.0, null);
    Comparator<Thing> comp = Comparator.comparingInt(new ToIntFunction<Thing>() {
        @Override
        public int applyAsInt(Thing thing) {
            return thing.getIntField();
        }
    });

    assertComparisons(things, comp, comparisons);
}
 
Example #28
Source File: TestData.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected DoubleTestData(String name,
                         I state,
                         Function<I, DoubleStream> streamFn,
                         Function<I, DoubleStream> parStreamFn,
                         Function<I, Spliterator.OfDouble> splitrFn,
                         ToIntFunction<I> sizeFn) {
    super(name, StreamShape.DOUBLE_VALUE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #29
Source File: TestData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected IntTestData(String name,
                      I state,
                      Function<I, IntStream> streamFn,
                      Function<I, IntStream> parStreamFn,
                      Function<I, Spliterator.OfInt> splitrFn,
                      ToIntFunction<I> sizeFn) {
    super(name, StreamShape.INT_VALUE, state, streamFn, parStreamFn, splitrFn, sizeFn);
}
 
Example #30
Source File: BigIntegerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void squareRootAndRemainder() {
    ToIntFunction<BigInteger> g = (n) -> {
        int failCount = 0;
        BigInteger n2 = n.pow(2);

        // square root of n^2 -> n
        BigInteger[] actual = n2.sqrtAndRemainder();
        failCount += checkResult(n, actual[0], "sqrtAndRemainder()[0]");
        failCount += checkResult(BigInteger.ZERO, actual[1],
            "sqrtAndRemainder()[1]");

        // square root of n^2 + 1 -> n
        BigInteger n2up = n2.add(BigInteger.ONE);
        actual = n2up.sqrtAndRemainder();
        failCount += checkResult(n, actual[0], "sqrtAndRemainder()[0]");
        failCount += checkResult(BigInteger.ONE, actual[1],
            "sqrtAndRemainder()[1]");

        // square root of (n + 1)^2 - 1 -> n
        BigInteger up =
            n.add(BigInteger.ONE).pow(2).subtract(BigInteger.ONE);
        actual = up.sqrtAndRemainder();
        failCount += checkResult(n, actual[0], "sqrtAndRemainder()[0]");
        BigInteger r = up.subtract(n2);
        failCount += checkResult(r, actual[1], "sqrtAndRemainder()[1]");

        return failCount;
    };

    IntStream bits = random.ints(SIZE, 3, Short.MAX_VALUE);
    report("sqrtAndRemainder", bits.mapToObj(x ->
        BigInteger.valueOf(x)).collect(Collectors.summingInt(g)));
}