Java Code Examples for java.util.function.ToIntFunction

The following examples show how to use java.util.function.ToIntFunction. These examples are extracted from open source projects. 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 Project: paintera   Source File: ShapeKey.java    License: 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 2
Source Project: drift   Source File: TestDriftNettyServerTransport.java    License: 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 3
Source Project: Spring-5.0-Cookbook   Source File: EmployeeServiceImpl.java    License: 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 4
Source Project: drift   Source File: TestClientsWithApacheServer.java    License: 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 5
Source Project: Bytecoder   Source File: ReferencePipeline.java    License: 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 6
Source Project: presto   Source File: BlackHoleNodePartitioningProvider.java    License: 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 7
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 8
@Override
public ToIntFunction<ConnectorSplit> getSplitBucketFunction(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle)
{
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        return delegate.getSplitBucketFunction(transactionHandle, session, partitioningHandle);
    }
}
 
Example 9
Source Project: openjdk-jdk8u   Source File: TestData.java    License: 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 10
Source Project: openjdk-jdk9   Source File: TestData.java    License: 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 Project: jdk8u-jdk   Source File: TestData.java    License: 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 12
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 13
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 Project: dragonwell8_jdk   Source File: TestData.java    License: 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 Project: dragonwell8_jdk   Source File: TestData.java    License: 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 Project: dragonwell8_jdk   Source File: TestData.java    License: 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 17
Source Project: openjdk-jdk9   Source File: TestData.java    License: 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 18
Source Project: openjdk-jdk9   Source File: TestData.java    License: 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 Project: jdk8u-jdk   Source File: TestData.java    License: 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
@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 Project: TencentKona-8   Source File: TestData.java    License: 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
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 Project: TencentKona-8   Source File: BasicTest.java    License: 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 Project: morpheus-core   Source File: XDataFrame.java    License: 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
@Override
public MinimalSourceStateSerializer createSerializer(
		final Supplier<String> projectDirectory,
		final ToIntFunction<SourceState<?, ?>> stateToIndex)
{
	return new MinimalSourceStateSerializer(stateToIndex);
}
 
Example 26
Source Project: jdk8u-jdk   Source File: BasicTest.java    License: 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 Project: openjdk-jdk9   Source File: BasicTest.java    License: 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 Project: openjdk-jdk8u   Source File: TestData.java    License: 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 Project: jdk8u60   Source File: TestData.java    License: 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 Project: openjdk-jdk9   Source File: BigIntegerTest.java    License: 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)));
}