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


Java ToDoubleFunction类代码示例

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


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

示例1: getBestGoodsWish

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
/**
 * Gets the best goods wish for a carrier unit.
 *
 * @param aiUnit The carrier {@code AIUnit}.
 * @param goodsType The {@code GoodsType} to wish for.
 * @return The best {@code GoodsWish} for the unit.
 */
public GoodsWish getBestGoodsWish(AIUnit aiUnit, GoodsType goodsType) {
    final Unit carrier = aiUnit.getUnit();
    final ToDoubleFunction<GoodsWish> wishValue
        = cacheDouble(gw -> {
                int turns = carrier.getTurnsToReach(carrier.getLocation(),
                                                    gw.getDestination());
                return (turns >= Unit.MANY_TURNS) ? -1.0
                    : (double)gw.getValue() / turns;
            });
    final Comparator<GoodsWish> comp
        = Comparator.comparingDouble(wishValue);

    List<GoodsWish> wishes = goodsWishes.get(goodsType);
    return (wishes == null) ? null
        : maximize(wishes, gw -> wishValue.applyAsDouble(gw) > 0.0, comp);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:24,代码来源:EuropeanAIPlayer.java

示例2: mapToDoubles

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
/**
 * Maps the specified column to doubles 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> mapToDoubles(XDataFrame<R,C> frame, C colKey, ToDoubleFunction<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(Double.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 double value = mapper.applyAsDouble(cursor);
                    targetValues.setDouble(cursor.rowIndex, value);
                }
                return targetValues;
            }
        }));
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:33,代码来源:XDataFrameContent.java

示例3: callDouble

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

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

示例4: summingDouble

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
/**
 * Returns a {@code Collector} that produces the sum of a double-valued
 * function applied to the input elements.  If no elements are present,
 * the result is 0.
 *
 * <p>The sum returned can vary depending upon the order in which
 * values are recorded, due to accumulated rounding error in
 * addition of values of differing magnitudes. Values sorted by increasing
 * absolute magnitude tend to yield more accurate results.  If any recorded
 * value is a {@code NaN} or the sum is at any point a {@code NaN} then the
 * sum will be {@code NaN}.
 *
 * @param <T> the type of the input elements
 * @param mapper a function extracting the property to be summed
 * @return a {@code Collector} that produces the sum of a derived property
 */
public static <T> Collector<T, ?, Double>
summingDouble(ToDoubleFunction<? super T> mapper) {
    /*
     * In the arrays allocated for the collect operation, index 0
     * holds the high-order bits of the running sum, index 1 holds
     * the low-order bits of the sum computed via compensated
     * summation, and index 2 holds the simple sum used to compute
     * the proper result if the stream contains infinite values of
     * the same sign.
     */
    return new CollectorImpl<>(
            () -> new double[3],
            (a, t) -> { double val = mapper.applyAsDouble(t);
                        sumWithCompensation(a, val);
                        a[2] += val;},
            (a, b) -> { sumWithCompensation(a, b[0]);
                        a[2] += b[2];
                        return sumWithCompensation(a, b[1]); },
            a -> computeFinalSum(a),
            CH_NOID);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:Collectors.java

示例5: compute

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
public final void compute() {
    final ToDoubleFunction<? super V> transformer;
    final DoubleBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        double r = this.basis;
        for (int i = baseIndex, f, h; batch > 0 &&
                 (h = ((f = baseLimit) + i) >>> 1) > i;) {
            addToPendingCount(1);
            (rights = new MapReduceValuesToDoubleTask<K,V>
             (this, batch >>>= 1, baseLimit = h, f, tab,
              rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = advance()) != null; )
            r = reducer.applyAsDouble(r, transformer.applyAsDouble(p.val));
        result = r;
        CountedCompleter<?> c;
        for (c = firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceValuesToDoubleTask<K,V>
                t = (MapReduceValuesToDoubleTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsDouble(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:ConcurrentHashMap.java

示例6: newGauge

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
@Override
protected <T> io.micrometer.core.instrument.Gauge newGauge(Meter.Id id, T obj, ToDoubleFunction<T> f) {
    final WeakReference<T> ref = new WeakReference<>(obj);
    Gauge<Double> gauge = () -> {
        T obj2 = ref.get();
        return obj2 != null ? f.applyAsDouble(ref.get()) : Double.NaN;
    };
    registry.register(hierarchicalName(id), gauge);
    return new DropwizardGauge(id, gauge);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:11,代码来源:DropwizardMeterRegistry.java

示例7: newFunctionTimer

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
@Override
protected <T> FunctionTimer newFunctionTimer(Meter.Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnits) {
    DropwizardFunctionTimer ft = new DropwizardFunctionTimer<>(id, clock, obj, countFunction, totalTimeFunction,
        totalTimeFunctionUnits, getBaseTimeUnit());
    registry.register(hierarchicalName(id), ft.getDropwizardMeter());
    return ft;
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:8,代码来源:DropwizardMeterRegistry.java

示例8: applyDoubles

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
@Override()
public final Z applyDoubles(ToDoubleFunction<DataFrameValue<R,C>> mapper) {
    return forEachValue(value -> {
        final double result = mapper.applyAsDouble(value);
        value.setDouble(result);
    });
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:8,代码来源:XDataFrameVector.java

示例9: timer

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
/**
 * A timer that tracks monotonically increasing functions for count and totalTime.
 */
public <T> FunctionTimer timer(String name, Iterable<Tag> tags, T obj,
                               ToLongFunction<T> countFunction,
                               ToDoubleFunction<T> totalTimeFunction,
                               TimeUnit totalTimeFunctionUnits) {
    return globalRegistry.more().timer(name, tags, obj, countFunction, totalTimeFunction, totalTimeFunctionUnits);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:10,代码来源:Metrics.java

示例10: Builder

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
private Builder(String name, T obj,
                ToLongFunction<T> countFunction,
                ToDoubleFunction<T> totalTimeFunction,
                TimeUnit totalTimeFunctionUnits) {
    this.name = name;
    this.obj = obj;
    this.countFunction = countFunction;
    this.totalTimeFunction = totalTimeFunction;
    this.totalTimeFunctionUnits = totalTimeFunctionUnits;
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:11,代码来源:FunctionTimer.java

示例11: counter

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
private void counter(MeterRegistry registry, String name, String description, ToDoubleFunction<Statistics> f, String... extraTags) {
    FunctionCounter.builder(name, stats, f)
        .tags(tags)
        .tags(extraTags)
        .description(description)
        .register(registry);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:8,代码来源:HibernateMetrics.java

示例12: compute

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
public final void compute() {
    final ToDoubleFunction<? super K> transformer;
    final DoubleBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        double r = this.basis;
        for (int i = baseIndex, f, h; batch > 0 &&
                 (h = ((f = baseLimit) + i) >>> 1) > i;) {
            addToPendingCount(1);
            (rights = new MapReduceKeysToDoubleTask<K,V>
             (this, batch >>>= 1, baseLimit = h, f, tab,
              rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = advance()) != null; )
            r = reducer.applyAsDouble(r, transformer.applyAsDouble(p.key));
        result = r;
        CountedCompleter<?> c;
        for (c = firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceKeysToDoubleTask<K,V>
                t = (MapReduceKeysToDoubleTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsDouble(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:ConcurrentHashMap.java

示例13: buildStatusCounter

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
private void buildStatusCounter(MeterRegistry reg, String status, ToDoubleFunction<StatisticsHandler> consumer) {
    FunctionCounter.builder("jetty.responses", statisticsHandler, consumer)
        .tags(tags)
        .description("Number of requests with response status")
        .tags("status", status)
        .register(reg);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:8,代码来源:JettyStatisticsMetrics.java

示例14: toDouble

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
/**
 * Creates an DOUBLE mapper that wraps to function provided
 * @param function  the function to wrap
 * @param <I>       the input type
 * @return          the newly created mapper
 */
public static <I,O> Function1<I,Double> toDouble(ToDoubleFunction<I> function) {
    return new Function1<I,Double>(FunctionStyle.DOUBLE) {
        @Override
        public final double applyAsDouble(I value) {
            return function.applyAsDouble(value);
        }
    };
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:15,代码来源:Function1.java

示例15: StatsdFunctionTimer

import java.util.function.ToDoubleFunction; //导入依赖的package包/类
StatsdFunctionTimer(Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction,
                    TimeUnit totalTimeFunctionUnits, TimeUnit baseTimeUnit,
                    StatsdLineBuilder lineBuilder, Subscriber<String> publisher) {
    super(id, obj, countFunction, totalTimeFunction, totalTimeFunctionUnits, baseTimeUnit);
    this.lineBuilder = lineBuilder;
    this.publisher = publisher;
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:8,代码来源:StatsdFunctionTimer.java


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