本文整理汇总了Java中java.util.function.ToLongFunction类的典型用法代码示例。如果您正苦于以下问题:Java ToLongFunction类的具体用法?Java ToLongFunction怎么用?Java ToLongFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ToLongFunction类属于java.util.function包,在下文中一共展示了ToLongFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: callLong
import java.util.function.ToLongFunction; //导入依赖的package包/类
private static <A extends Annotation, E extends Throwable> long callLong(
AnnotationInterceptor<A> annotationInterceptor,
int annotationId, A[] annotations, CallContext context, Arguments currentArguments,
ToLongFunction<Arguments> terminalInvokeFun) throws E {
A annotation = annotations[annotationId];
if (annotationId == annotations.length - 1) { // last annotation
return annotationInterceptor.onCall(annotation, context,
new SimpleLongInterceptionHandler(currentArguments, terminalInvokeFun));
} else {
return annotationInterceptor.onCall(annotation, context,
new SimpleLongInterceptionHandler(currentArguments,
(args) -> callLong(annotationInterceptor, annotationId + 1, annotations, context, args,
terminalInvokeFun)));
}
}
示例2: mapToLong
import java.util.function.ToLongFunction; //导入依赖的package包/类
@Override
public final LongStream mapToLong(ToLongFunction<? super P_OUT> mapper) {
Objects.requireNonNull(mapper);
return new LongPipeline.StatelessOp<P_OUT>(this, StreamShape.REFERENCE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override
Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) {
return new Sink.ChainedReference<P_OUT, Long>(sink) {
@Override
public void accept(P_OUT u) {
downstream.accept(mapper.applyAsLong(u));
}
};
}
};
}
示例3: testLongComparator
import java.util.function.ToLongFunction; //导入依赖的package包/类
public void testLongComparator() {
Thing[] things = new Thing[longValues.length];
for (int i=0; i<longValues.length; i++)
things[i] = new Thing(0, longValues[i], 0.0, null);
Comparator<Thing> comp = Comparator.comparingLong(new ToLongFunction<Thing>() {
@Override
public long applyAsLong(Thing thing) {
return thing.getLongField();
}
});
assertComparisons(things, comp, comparisons);
}
示例4: mapToLongs
import java.util.function.ToLongFunction; //导入依赖的package包/类
/**
* Maps the specified column to longs 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> mapToLongs(XDataFrame<R,C> frame, C colKey, ToLongFunction<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(Long.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 long value = mapper.applyAsLong(cursor);
targetValues.setLong(cursor.rowIndex, value);
}
return targetValues;
}
}));
}
}
示例5: testBinaryInputEstimation
import java.util.function.ToLongFunction; //导入依赖的package包/类
@Test
public void testBinaryInputEstimation() {
OptimizationContext optimizationContext = mock(OptimizationContext.class);
when(optimizationContext.getConfiguration()).thenReturn(new Configuration());
CardinalityEstimate inputEstimate1 = new CardinalityEstimate(50, 60, 0.8);
CardinalityEstimate inputEstimate2 = new CardinalityEstimate(10, 100, 0.4);
final ToLongFunction<long[]> singlePointEstimator =
inputEstimates -> (long) Math.ceil(0.8 * inputEstimates[0] * inputEstimates[1]);
CardinalityEstimator estimator = new DefaultCardinalityEstimator(
0.9,
2,
false,
singlePointEstimator
);
CardinalityEstimate estimate = estimator.estimate(optimizationContext, inputEstimate1, inputEstimate2);
Assert.assertEquals(0.9 * 0.4, estimate.getCorrectnessProbability(), 0.001);
Assert.assertEquals(singlePointEstimator.applyAsLong(new long[]{50, 10}), estimate.getLowerEstimate());
Assert.assertEquals(singlePointEstimator.applyAsLong(new long[]{60, 100}), estimate.getUpperEstimate());
}
示例6: shouldUseCallWrappedFunction
import java.util.function.ToLongFunction; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldUseCallWrappedFunction() {
// given
final ConcurrentMap<String, Long> cache = new ConcurrentHashMap<>();
final ToLongFunction<String> function = Mockito.mock(ToLongFunction.class);
final Function<String, String> keyFunction = Function.identity();
// when
final ConcurrentMapBasedToLongFunctionMemoizer<String, String> memoizer = new ConcurrentMapBasedToLongFunctionMemoizer<>(
cache, keyFunction, function);
// then
memoizer.applyAsLong("123");
Mockito.verify(function).applyAsLong("123");
}
示例7: newFunctionTimer
import java.util.function.ToLongFunction; //导入依赖的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: CumulativeFunctionTimer
import java.util.function.ToLongFunction; //导入依赖的package包/类
public CumulativeFunctionTimer(Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction,
TimeUnit totalTimeFunctionUnits, TimeUnit baseTimeUnit) {
this.id = id;
this.ref = new WeakReference<>(obj);
this.countFunction = countFunction;
this.totalTimeFunction = totalTimeFunction;
this.totalTimeFunctionUnits = totalTimeFunctionUnits;
this.baseTimeUnit = baseTimeUnit;
}
示例9: StepFunctionTimer
import java.util.function.ToLongFunction; //导入依赖的package包/类
public StepFunctionTimer(Id id, Clock clock, long stepMillis, T obj, ToLongFunction<T> countFunction,
ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnits, TimeUnit baseTimeUnit) {
this.id = id;
this.ref = new WeakReference<>(obj);
this.countFunction = countFunction;
this.totalTimeFunction = totalTimeFunction;
this.totalTimeFunctionUnits = totalTimeFunctionUnits;
this.baseTimeUnit = baseTimeUnit;
this.count = new StepLong(clock, stepMillis);
this.total = new StepDouble(clock, stepMillis);
}
示例10: timer
import java.util.function.ToLongFunction; //导入依赖的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);
}
示例11: Builder
import java.util.function.ToLongFunction; //导入依赖的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;
}
示例12: CompositeFunctionTimer
import java.util.function.ToLongFunction; //导入依赖的package包/类
CompositeFunctionTimer(Meter.Id id, T obj, ToLongFunction<T> countFunction,
ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnits) {
super(id);
this.ref = new WeakReference<>(obj);
this.countFunction = countFunction;
this.totalTimeFunction = totalTimeFunction;
this.totalTimeFunctionUnits = totalTimeFunctionUnits;
}
示例13: StatsdFunctionTimer
import java.util.function.ToLongFunction; //导入依赖的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;
}
示例14: newFunctionTimer
import java.util.function.ToLongFunction; //导入依赖的package包/类
@Override
protected <T> FunctionTimer newFunctionTimer(Meter.Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnits) {
StatsdFunctionTimer ft = new StatsdFunctionTimer<>(id, obj, countFunction, totalTimeFunction, totalTimeFunctionUnits,
getBaseTimeUnit(), lineBuilder(id), publisher);
pollableMeters.add(ft);
return ft;
}
示例15: newFunctionTimer
import java.util.function.ToLongFunction; //导入依赖的package包/类
@Override
protected <T> FunctionTimer newFunctionTimer(Meter.Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnits) {
MicrometerCollector collector = collectorByName(id, Collector.Type.SUMMARY);
FunctionTimer ft = new CumulativeFunctionTimer<>(id, obj, countFunction, totalTimeFunction, totalTimeFunctionUnits, getBaseTimeUnit());
List<String> tagValues = tagValues(id);
collector.add((conventionName, tagKeys) -> Stream.of(
new Collector.MetricFamilySamples.Sample(conventionName + "_count", tagKeys, tagValues, ft.count()),
new Collector.MetricFamilySamples.Sample(conventionName + "_sum", tagKeys, tagValues, ft.totalTime(TimeUnit.SECONDS))
));
return ft;
}