本文整理汇总了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);
}
示例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;
}
}));
}
}
示例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)));
}
}
示例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);
}
示例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;
}
}
}
}
示例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);
}
示例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;
}
示例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);
});
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
}
}
}
示例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);
}
示例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);
}
};
}
示例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;
}