下面列出了怎么用java.util.function.ToLongBiFunction的API类实例代码及写法,或者点击链接到github查看源代码。
protected InternalEngine createEngine(
IndexSettings indexSettings,
Store store,
Path translogPath,
MergePolicy mergePolicy,
@Nullable IndexWriterFactory indexWriterFactory,
@Nullable BiFunction<Long, Long, LocalCheckpointTracker> localCheckpointTrackerSupplier,
@Nullable LongSupplier globalCheckpointSupplier,
@Nullable ToLongBiFunction<Engine, Engine.Operation> seqNoForOperation) throws IOException {
return createEngine(
indexSettings,
store,
translogPath,
mergePolicy,
indexWriterFactory,
localCheckpointTrackerSupplier,
seqNoForOperation,
globalCheckpointSupplier);
}
protected InternalEngine createEngine(@Nullable IndexWriterFactory indexWriterFactory,
@Nullable BiFunction<Long, Long, LocalCheckpointTracker> localCheckpointTrackerSupplier,
@Nullable ToLongBiFunction<Engine, Engine.Operation> seqNoForOperation,
EngineConfig config) throws IOException {
final Store store = config.getStore();
final Directory directory = store.directory();
if (Lucene.indexExists(directory) == false) {
store.createEmpty();
final String translogUuid = Translog.createEmptyTranslog(config.getTranslogConfig().getTranslogPath(),
SequenceNumbers.NO_OPS_PERFORMED, shardId, primaryTerm.get());
store.associateIndexWithNewTranslog(translogUuid);
}
InternalEngine internalEngine = createInternalEngine(indexWriterFactory, localCheckpointTrackerSupplier, seqNoForOperation, config);
internalEngine.recoverFromTranslog(translogHandler, Long.MAX_VALUE);
return internalEngine;
}
/**
* Returns a {@link BiCollector} that produces the sum of a long-valued
* function applied to the input pair. If no input entries are present,
* the result is 0.
*
* @since 3.2
*/
public static <K, V> BiCollector<K, V, Long> summingLong(
ToLongBiFunction<? super K, ? super V> mapper) {
requireNonNull(mapper);
return new BiCollector<K, V, Long>() {
@Override
public <E> Collector<E, ?, Long> splitting(
Function<E, K> toKey, Function<E, V> toValue) {
return Collectors.summingLong(e -> mapper.applyAsLong(toKey.apply(e), toValue.apply(e)));
}
};
}
/**
* Returns a {@link BiCollector} that produces the arithmetic mean of a long-valued
* function applied to the input pair. If no input entries are present,
* the result is 0.
*
* @since 3.2
*/
public static <K, V> BiCollector<K, V, Double> averagingLong(
ToLongBiFunction<? super K, ? super V> mapper) {
requireNonNull(mapper);
return new BiCollector<K, V, Double>() {
@Override
public <E> Collector<E, ?, Double> splitting(
Function<E, K> toKey, Function<E, V> toValue) {
return Collectors.averagingLong(e -> mapper.applyAsLong(toKey.apply(e), toValue.apply(e)));
}
};
}
/**
* Returns a {@link BiCollector} which applies an {@code long}-producing
* mapping function to each input pair, and returns summary statistics
* for the resulting values.
*
*
* @since 3.2
*/
public static <K, V> BiCollector<K, V, LongSummaryStatistics> summarizingLong(
ToLongBiFunction<? super K, ? super V> mapper) {
requireNonNull(mapper);
return new BiCollector<K, V, LongSummaryStatistics>() {
@Override
public <E> Collector<E, ?, LongSummaryStatistics> splitting(
Function<E, K> toKey, Function<E, V> toValue) {
return Collectors.summarizingLong(e -> mapper.applyAsLong(toKey.apply(e), toValue.apply(e)));
}
};
}
public DefaultCardinalityEstimator(double certaintyProb,
int numInputs,
boolean isAllowMoreInputs,
ToLongBiFunction<long[], Configuration> singlePointEstimator) {
this.certaintyProb = certaintyProb;
this.numInputs = numInputs;
this.singlePointEstimator = singlePointEstimator;
this.isAllowMoreInputs = isAllowMoreInputs;
}
public DefaultLoadEstimator(int numInputs,
int numOutputs,
double correctnessProbability,
CardinalityEstimate nullCardinalityReplacement,
ToLongBiFunction<long[], long[]> singlePointFunction) {
this(
numInputs, numOutputs, correctnessProbability, nullCardinalityReplacement,
(context, inputEstimates, outputEstimates) -> singlePointFunction.applyAsLong(inputEstimates, outputEstimates)
);
}
public IntervalLoadEstimator(int numInputs,
int numOutputs,
double correctnessProbability,
ToLongBiFunction<long[], long[]> lowerBoundEstimator,
ToLongBiFunction<long[], long[]> upperBoundEstimator) {
this(numInputs, numOutputs, correctnessProbability, null, lowerBoundEstimator, upperBoundEstimator);
}
public IntervalLoadEstimator(int numInputs,
int numOutputs,
double correctnessProbablity,
CardinalityEstimate nullCardinalityReplacement,
ToLongBiFunction<long[], long[]> lowerBoundEstimator,
ToLongBiFunction<long[], long[]> upperBoundEstimator) {
super(nullCardinalityReplacement);
this.numInputs = numInputs;
this.numOutputs = numOutputs;
this.correctnessProbablity = correctnessProbablity;
this.lowerBoundEstimator = lowerBoundEstimator;
this.upperBoundEstimator = upperBoundEstimator;
}
protected InternalEngine createEngine(
Store store,
Path translogPath,
BiFunction<Long, Long, LocalCheckpointTracker> localCheckpointTrackerSupplier,
ToLongBiFunction<Engine, Engine.Operation> seqNoForOperation) throws IOException {
return createEngine(
defaultSettings, store, translogPath, newMergePolicy(), null, localCheckpointTrackerSupplier, null, seqNoForOperation);
}
protected InternalEngine createEngine(
IndexSettings indexSettings,
Store store,
Path translogPath,
MergePolicy mergePolicy,
@Nullable IndexWriterFactory indexWriterFactory,
@Nullable BiFunction<Long, Long, LocalCheckpointTracker> localCheckpointTrackerSupplier,
@Nullable ToLongBiFunction<Engine, Engine.Operation> seqNoForOperation,
@Nullable LongSupplier globalCheckpointSupplier) throws IOException {
EngineConfig config = config(indexSettings, store, translogPath, mergePolicy, null, globalCheckpointSupplier);
return createEngine(indexWriterFactory, localCheckpointTrackerSupplier, seqNoForOperation, config);
}
public DefaultLoadEstimator(int numInputs,
int numOutputs,
double correctnessProbability,
ToLongBiFunction<long[], long[]> singlePointFunction) {
this(numInputs, numOutputs, correctnessProbability, null, singlePointFunction);
}
/**
* Utility to create new instances: Rounds the results of a given estimation function.
*/
@SuppressWarnings("unused")
public static ToLongBiFunction<long[], long[]> rounded(ToDoubleBiFunction<long[], long[]> f) {
return (inputCards, outputCards) -> Math.round(f.applyAsDouble(inputCards, outputCards));
}
/**
* Utility to create new instances: Rounds the results of a given estimation function.
*/
@SuppressWarnings("unused")
public static ToLongBiFunction<long[], long[]> rounded(ToDoubleBiFunction<long[], long[]> f) {
return (inputCards, outputCards) -> Math.round(f.applyAsDouble(inputCards, outputCards));
}