當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。