当前位置: 首页>>代码示例>>Java>>正文


Java ToIntFunction类代码示例

本文整理汇总了Java中java.util.function.ToIntFunction的典型用法代码示例。如果您正苦于以下问题:Java ToIntFunction类的具体用法?Java ToIntFunction怎么用?Java ToIntFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ToIntFunction类属于java.util.function包,在下文中一共展示了ToIntFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAveAge

import java.util.function.ToIntFunction; //导入依赖的package包/类
@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;
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:20,代码来源:EmployeeServiceImpl.java

示例2: getSortedPotential

import java.util.function.ToIntFunction; //导入依赖的package包/类
/**
 * Sort possible goods types according to potential.
 *
 * @param unitType The {@code UnitType} to do the work.
 * @param owner the {@code Player} owning the unit.
 * @return A list of goods, highest potential production first.
 */
public List<AbstractGoods> getSortedPotential(UnitType unitType,
                                              Player owner) {
    // Defend against calls while partially read.
    if (getType() == null) return Collections.<AbstractGoods>emptyList();
    
    final ToIntFunction<GoodsType> productionMapper = cacheInt(gt ->
        getPotentialProduction(gt, unitType));
    final Predicate<GoodsType> productionPred = gt ->
        productionMapper.applyAsInt(gt) > 0;
    final Function<GoodsType, AbstractGoods> goodsMapper = gt ->
        new AbstractGoods(gt, productionMapper.applyAsInt(gt));
    final Comparator<AbstractGoods> goodsComp
        = ((owner == null || owner.getMarket() == null)
            ? AbstractGoods.descendingAmountComparator
            : owner.getMarket().getSalePriceComparator());
    // It is necessary to consider all farmed goods, since the
    // tile might have a resource that produces goods not produced
    // by the tile type.
    return transform(getSpecification().getFarmedGoodsTypeList(),
                     productionPred, goodsMapper, goodsComp);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:29,代码来源:Tile.java

示例3: testApacheServer

import java.util.function.ToIntFunction; //导入依赖的package包/类
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;
}
 
开发者ID:airlift,项目名称:drift,代码行数:24,代码来源:TestClientsWithApacheServer.java

示例4: callInt

import java.util.function.ToIntFunction; //导入依赖的package包/类
private static <A extends Annotation, E extends Throwable> int callInt(
        AnnotationInterceptor<A> annotationInterceptor,
        int annotationId, A[] annotations, CallContext context, Arguments currentArguments,
        ToIntFunction<Arguments> terminalInvokeFun) throws E {

    A annotation = annotations[annotationId];
    if (annotationId == annotations.length - 1) { // last annotation
        return annotationInterceptor.onCall(annotation, context,
                new SimpleIntInterceptionHandler(currentArguments, terminalInvokeFun));
    } else {
        return annotationInterceptor.onCall(annotation, context,
                new SimpleIntInterceptionHandler(currentArguments,
                        (args) -> callInt(annotationInterceptor, annotationId + 1, annotations, context, args,
                                terminalInvokeFun)));
    }
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:17,代码来源:RepeatedAnnotationObjectInterceptor.java

示例5: mapToInts

import java.util.function.ToIntFunction; //导入依赖的package包/类
/**
 * Maps the specified column to ints using the mapper function provided
 * @param frame     the frame reference
 * @param colKey    the column key to apply mapper function to
 * @param mapper    the mapper function to apply
 * @return          the newly created content, with update column
 */
@SuppressWarnings("unchecked")
final XDataFrameContent<R,C> mapToInts(XDataFrame<R,C> frame, C colKey, ToIntFunction<DataFrameValue<R,C>> mapper) {
    if (!isColumnStore()) {
        throw new DataFrameException("Cannot apply columns of a transposed DataFrame");
    } else {
        final int rowCount = rowKeys.size();
        final boolean parallel  = frame.isParallel();
        final int colIndex = colKeys.getIndexForKey(colKey);
        return new XDataFrameContent<>(rowKeys, colKeys, true, Mapper.apply(data, parallel, (index, array) -> {
            if (index != colIndex) {
                return array;
            } else {
                final int colOrdinal = colKeys.getOrdinalForKey(colKey);
                final Array<?> targetValues = Array.of(Integer.class, array.length());
                final Cursor cursor = new Cursor(frame, rowKeys.isEmpty() ? -1 : 0, colOrdinal);
                for (int i = 0; i < rowCount; ++i) {
                    cursor.atRowOrdinal(i);
                    final int value = mapper.applyAsInt(cursor);
                    targetValues.setInt(cursor.rowIndex, value);
                }
                return targetValues;
            }
        }));
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:33,代码来源:XDataFrameContent.java

示例6: getOrdinal

import java.util.function.ToIntFunction; //导入依赖的package包/类
private int getOrdinal(ResourcePoolEntry resource) {
    String path = resource.path();

    Integer value = orderedPaths.get(stripModule(path));

    if (value != null) {
        return value;
    }

    for (ToIntFunction<String> function : filters) {
        int ordinal = function.applyAsInt(path);

        if (ordinal != Integer.MAX_VALUE) {
            return ordinal;
        }
    }

    return Integer.MAX_VALUE;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:OrderResourcesPlugin.java

示例7: mapToInt

import java.util.function.ToIntFunction; //导入依赖的package包/类
@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));
                }
            };
        }
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ReferencePipeline.java

示例8: getParallelAverageAge

import java.util.function.ToIntFunction; //导入依赖的package包/类
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();
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:8,代码来源:EmployeeParallelStreamService.java

示例9: getAverageMoreProcessors

import java.util.function.ToIntFunction; //导入依赖的package包/类
public double getAverageMoreProcessors() throws InterruptedException, ExecutionException{
	ToIntFunction<Employee> sizeEmpArr = (e) -> {
	    System.out.println("Thread: " + Thread.currentThread().getName());
	    	return e.getAge();
	   };
	Callable<Double> task = () -> employeeDaoImpl.getEmployees().stream().mapToInt(sizeEmpArr).average().getAsDouble();
	ForkJoinPool forkJoinPool = new ForkJoinPool(4);
	
	double avgAge = forkJoinPool.submit(task).get();
	return avgAge;
	
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:13,代码来源:EmployeeParallelStreamService.java

示例10: testProcessor

import java.util.function.ToIntFunction; //导入依赖的package包/类
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
        throws Exception
{
    try (TServerSocket serverTransport = new TServerSocket(0)) {
        TProtocolFactory protocolFactory = new Factory();
        TTransportFactory transportFactory = new TFramedTransport.Factory();
        TServer server = new TSimpleServer(new Args(serverTransport)
                .protocolFactory(protocolFactory)
                .transportFactory(transportFactory)
                .processor(processor));

        Thread serverThread = new Thread(server::serve);
        try {
            serverThread.start();

            int localPort = serverTransport.getServerSocket().getLocalPort();
            HostAndPort address = HostAndPort.fromParts("localhost", localPort);

            int sum = 0;
            for (ToIntFunction<HostAndPort> client : clients) {
                sum += client.applyAsInt(address);
            }
            return sum;
        }
        finally {
            server.stop();
            serverThread.interrupt();
        }
    }
}
 
开发者ID:airlift,项目名称:drift,代码行数:31,代码来源:TestApacheThriftMethodInvoker.java

示例11: testProcessor

import java.util.function.ToIntFunction; //导入依赖的package包/类
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
        throws Exception
{
    try (TServerSocket serverTransport = new TServerSocket(0)) {
        TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
        TTransportFactory transportFactory = new TFramedTransport.Factory();
        TServer server = new TSimpleServer(new Args(serverTransport)
                .protocolFactory(protocolFactory)
                .transportFactory(transportFactory)
                .processor(processor));

        Thread serverThread = new Thread(server::serve);
        try {
            serverThread.start();

            int localPort = serverTransport.getServerSocket().getLocalPort();
            HostAndPort address = HostAndPort.fromParts("localhost", localPort);

            int sum = 0;
            for (ToIntFunction<HostAndPort> client : clients) {
                sum += client.applyAsInt(address);
            }
            return sum;
        }
        finally {
            server.stop();
            serverThread.interrupt();
        }
    }
}
 
开发者ID:airlift,项目名称:drift,代码行数:31,代码来源:TestDriftNettyMethodInvoker.java

示例12: driftNettyTestClients

import java.util.function.ToIntFunction; //导入依赖的package包/类
public static List<ToIntFunction<HostAndPort>> driftNettyTestClients(List<MethodInvocationFilter> filters, Transport transport, Protocol protocol, boolean secure)
{
    return ImmutableList.of(
            address -> logNettyDriftClient(address, DRIFT_MESSAGES, filters, transport, protocol, secure),
            address -> logNettyStaticDriftClient(address, DRIFT_MESSAGES, filters, transport, protocol, secure),
            address -> logNettyDriftClientAsync(address, DRIFT_MESSAGES, filters, transport, protocol, secure),
            address -> logNettyClientBinder(address, DRIFT_MESSAGES, filters, transport, protocol, secure));
}
 
开发者ID:airlift,项目名称:drift,代码行数:9,代码来源:DriftNettyTesterUtil.java

示例13: apacheThriftTestClients

import java.util.function.ToIntFunction; //导入依赖的package包/类
public static List<ToIntFunction<HostAndPort>> apacheThriftTestClients(List<MethodInvocationFilter> filters, Transport transport, Protocol protocol, boolean secure)
{
    return ImmutableList.of(
            address -> logApacheThriftDriftClient(address, DRIFT_MESSAGES, filters, transport, protocol, secure),
            address -> logApacheThriftStaticDriftClient(address, DRIFT_MESSAGES, filters, transport, protocol, secure),
            address -> logApacheThriftDriftClientAsync(address, DRIFT_MESSAGES, filters, transport, protocol, secure),
            address -> logApacheThriftClientBinder(address, DRIFT_MESSAGES, filters, transport, protocol, secure));
}
 
开发者ID:airlift,项目名称:drift,代码行数:9,代码来源:ApacheThriftTesterUtil.java

示例14: DoubleTestData

import java.util.function.ToIntFunction; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TestData.java

示例15: testIntComparator

import java.util.function.ToIntFunction; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:BasicTest.java


注:本文中的java.util.function.ToIntFunction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。