下面列出了怎么用java.util.function.ToIntBiFunction的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public FunctionWrapper[] getFunction(CommandContext cmdCtx, String str) throws CommandSyntaxException {
Collection<CustomFunction> customFuncList = ArgumentTag.a(cmdCtx, str);
FunctionWrapper[] result = new FunctionWrapper[customFuncList.size()];
CustomFunctionData customFunctionData = getCLW(cmdCtx).getServer().getFunctionData();
CommandListenerWrapper commandListenerWrapper = getCLW(cmdCtx).a().b(2);
int count = 0;
for (CustomFunction customFunction : customFuncList) {
@SuppressWarnings("deprecation")
NamespacedKey minecraftKey = new NamespacedKey(customFunction.a().b(), customFunction.a().getKey());
ToIntBiFunction<CustomFunction, CommandListenerWrapper> obj = customFunctionData::a;
FunctionWrapper wrapper = new FunctionWrapper(minecraftKey, obj, customFunction, commandListenerWrapper,
e -> getCLW(cmdCtx).a(((CraftEntity) e).getHandle()));
result[count] = wrapper;
count++;
}
return result;
}
@Override
public FunctionWrapper[] getFunction(CommandContext cmdCtx, String str) throws CommandSyntaxException {
Collection<CustomFunction> customFuncList = ArgumentTag.a(cmdCtx, str);
FunctionWrapper[] result = new FunctionWrapper[customFuncList.size()];
CustomFunctionData customFunctionData = getCLW(cmdCtx).getServer().getFunctionData();
CommandListenerWrapper commandListenerWrapper = getCLW(cmdCtx).a().b(2);
int count = 0;
for(CustomFunction customFunction : customFuncList) {
@SuppressWarnings("deprecation")
NamespacedKey minecraftKey = new NamespacedKey(customFunction.a().b(), customFunction.a().getKey());
ToIntBiFunction<CustomFunction, CommandListenerWrapper> obj = customFunctionData::a;
FunctionWrapper wrapper = new FunctionWrapper(minecraftKey, obj, customFunction, commandListenerWrapper, e -> {
return getCLW(cmdCtx).a(((CraftEntity) e).getHandle());
});
result[count] = wrapper;
count++;
}
return result;
}
@Override
public FunctionWrapper[] getFunction(CommandContext cmdCtx, String str) throws CommandSyntaxException {
Collection<CustomFunction> customFuncList = ArgumentTag.a(cmdCtx, str);
FunctionWrapper[] result = new FunctionWrapper[customFuncList.size()];
CustomFunctionData customFunctionData = getCLW(cmdCtx).getServer().getFunctionData();
CommandListenerWrapper commandListenerWrapper = getCLW(cmdCtx).a().b(2);
int count = 0;
for(CustomFunction customFunction : customFuncList) {
@SuppressWarnings("deprecation")
NamespacedKey minecraftKey = new NamespacedKey(customFunction.a().b(), customFunction.a().getKey());
ToIntBiFunction<CustomFunction, CommandListenerWrapper> obj = customFunctionData::a;
FunctionWrapper wrapper = new FunctionWrapper(minecraftKey, obj, customFunction, commandListenerWrapper, e -> getCLW(cmdCtx).a(((CraftEntity) e).getHandle()));
result[count] = wrapper;
count++;
}
return result;
}
@Override
public FunctionWrapper[] getFunction(CommandContext cmdCtx, String str) throws CommandSyntaxException {
Collection<CustomFunction> customFuncList = ArgumentTag.a(cmdCtx, str);
FunctionWrapper[] result = new FunctionWrapper[customFuncList.size()];
CustomFunctionData customFunctionData = getCLW(cmdCtx).getServer().getFunctionData();
CommandListenerWrapper commandListenerWrapper = getCLW(cmdCtx).a().b(2);
int count = 0;
for(CustomFunction customFunction : customFuncList) {
@SuppressWarnings("deprecation")
NamespacedKey minecraftKey = new NamespacedKey(customFunction.a().getNamespace(), customFunction.a().getKey());
ToIntBiFunction<CustomFunction, CommandListenerWrapper> obj = customFunctionData::a;
FunctionWrapper wrapper = new FunctionWrapper(minecraftKey, obj, customFunction, commandListenerWrapper, e -> {
return (Object) getCLW(cmdCtx).a(((CraftEntity) e).getHandle());
});
result[count] = wrapper;
count++;
}
return result;
}
@Override
public FunctionWrapper[] getFunction(CommandContext cmdCtx, String str) throws CommandSyntaxException {
Collection<CustomFunction> customFuncList = ArgumentTag.a(cmdCtx, str);
FunctionWrapper[] result = new FunctionWrapper[customFuncList.size()];
CustomFunctionData customFunctionData = getCLW(cmdCtx).getServer().getFunctionData();
CommandListenerWrapper commandListenerWrapper = getCLW(cmdCtx).a().b(2);
int count = 0;
for(CustomFunction customFunction : customFuncList) {
@SuppressWarnings("deprecation")
NamespacedKey minecraftKey = new NamespacedKey(customFunction.a().b(), customFunction.a().getKey());
ToIntBiFunction<CustomFunction, CommandListenerWrapper> obj = customFunctionData::a;
FunctionWrapper wrapper = new FunctionWrapper(minecraftKey, obj, customFunction, commandListenerWrapper, e ->
getCLW(cmdCtx).a(((CraftEntity) e).getHandle()));
result[count] = wrapper;
count++;
}
return result;
}
@Override
public FunctionWrapper[] getFunction(CommandContext cmdCtx, String str) throws CommandSyntaxException {
Collection<CustomFunction> customFuncList = ArgumentTag.a(cmdCtx, str);
FunctionWrapper[] result = new FunctionWrapper[customFuncList.size()];
CustomFunctionData customFunctionData = getCLW(cmdCtx).getServer().getFunctionData();
CommandListenerWrapper commandListenerWrapper = getCLW(cmdCtx).a().b(2);
int count = 0;
for(CustomFunction customFunction : customFuncList) {
@SuppressWarnings("deprecation")
NamespacedKey minecraftKey = new NamespacedKey(customFunction.a().b(), customFunction.a().getKey());
ToIntBiFunction<CustomFunction, CommandListenerWrapper> obj = customFunctionData::a;
FunctionWrapper wrapper = new FunctionWrapper(minecraftKey, obj, customFunction, commandListenerWrapper, e -> {
return (Object) getCLW(cmdCtx).a(((CraftEntity) e).getHandle());
});
result[count] = wrapper;
count++;
}
return result;
}
private static Optional<ZonedDateTime> dateTimeFromTemporal( TemporalAccessor ta ) {
ToIntBiFunction<ChronoField, Integer> getField = ( field, orElse ) ->
ta.isSupported( field ) ? ta.get( field ) : orElse;
ZoneId zone = Optional.<ZoneId>ofNullable( ta.query( offset() ) )
.orElse( Optional.ofNullable( ta.query( zoneId() ) )
.orElse( ZoneOffset.UTC ) );
int year = getField.applyAsInt( ChronoField.YEAR, THIS_YEAR );
int month = getField.applyAsInt( ChronoField.MONTH_OF_YEAR, 1 );
int day = getField.applyAsInt( ChronoField.DAY_OF_MONTH, 1 );
int hour = getField.applyAsInt( ChronoField.HOUR_OF_DAY, 0 );
int minute = getField.applyAsInt( ChronoField.MINUTE_OF_HOUR, 0 );
int second = getField.applyAsInt( ChronoField.SECOND_OF_MINUTE, 0 );
int nanos = getField.applyAsInt( ChronoField.NANO_OF_SECOND, 0 );
ZonedDateTime dateTime = ZonedDateTime.of( year, month, day, hour, minute, second, nanos, zone );
return Optional.of( dateTime );
}
@Override
public FunctionWrapper[] getFunction(CommandContext cmdCtx, String str) throws CommandSyntaxException {
Collection<CustomFunction> customFuncList = ArgumentTag.a(cmdCtx, str);
FunctionWrapper[] result = new FunctionWrapper[customFuncList.size()];
CustomFunctionData customFunctionData = getCLW(cmdCtx).getServer().getFunctionData();
CommandListenerWrapper commandListenerWrapper = getCLW(cmdCtx).a().b(2);
int count = 0;
for (CustomFunction customFunction : customFuncList) {
@SuppressWarnings("deprecation")
NamespacedKey minecraftKey = new NamespacedKey(customFunction.a().getNamespace(),
customFunction.a().getKey());
ToIntBiFunction<CustomFunction, CommandListenerWrapper> obj = customFunctionData::a;
FunctionWrapper wrapper = new FunctionWrapper(minecraftKey, obj, customFunction, commandListenerWrapper,
e -> {
return (Object) getCLW(cmdCtx).a(((CraftEntity) e).getHandle());
});
result[count] = wrapper;
count++;
}
return result;
}
@Override
public FunctionWrapper[] getFunction(CommandContext cmdCtx, String str) throws CommandSyntaxException {
Collection<CustomFunction> customFuncList = ArgumentTag.a(cmdCtx, str);
FunctionWrapper[] result = new FunctionWrapper[customFuncList.size()];
CustomFunctionData customFunctionData = getCLW(cmdCtx).getServer().getFunctionData();
CommandListenerWrapper commandListenerWrapper = getCLW(cmdCtx).a().b(2);
int count = 0;
for (CustomFunction customFunction : customFuncList) {
@SuppressWarnings("deprecation")
NamespacedKey minecraftKey = new NamespacedKey(customFunction.a().getNamespace(),
customFunction.a().getKey());
ToIntBiFunction<CustomFunction, CommandListenerWrapper> obj = customFunctionData::a;
FunctionWrapper wrapper = new FunctionWrapper(minecraftKey, obj, customFunction, commandListenerWrapper,
e -> {
return (Object) getCLW(cmdCtx).a(((CraftEntity) e).getHandle());
});
result[count] = wrapper;
count++;
}
return result;
}
/**
* Creates a FunctionWrapper
* @param minecraftKey the MinecraftKey which is used to reference this function
* @param invoker a method which, when invoked, runs the function
* @param customFunction an NMS CustomFunction that contains the information about the function
* @param clwArgB the instance of the CommandListenerWrapper which executed this command
* @param mapper a function that maps a Bukkit Entity to a Minecraft Entity
*/
@SuppressWarnings("unchecked")
public FunctionWrapper(NamespacedKey minecraftKey, @SuppressWarnings("rawtypes") ToIntBiFunction invoker, Object customFunction, Object clwArgB, Function<Entity, Object> mapper) {
this.minecraftKey = minecraftKey;
this.functionExecutor = invoker;
this.customFunction = customFunction;
this.commandListenerWrapper = clwArgB;
this.mapper = mapper;
}
/**
* Returns a {@link BiCollector} that produces the sum of an integer-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, Integer> summingInt(
ToIntBiFunction<? super K, ? super V> mapper) {
requireNonNull(mapper);
return new BiCollector<K, V, Integer>() {
@Override
public <E> Collector<E, ?, Integer> splitting(
Function<E, K> toKey, Function<E, V> toValue) {
return Collectors.summingInt(e -> mapper.applyAsInt(toKey.apply(e), toValue.apply(e)));
}
};
}
/**
* Returns a {@link BiCollector} that produces the arithmetic mean of an integer-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> averagingInt(
ToIntBiFunction<? 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.averagingInt(e -> mapper.applyAsInt(toKey.apply(e), toValue.apply(e)));
}
};
}
/**
* Returns a {@link BiCollector} which applies an {@code int}-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, IntSummaryStatistics> summarizingInt(
ToIntBiFunction<? super K, ? super V> mapper) {
requireNonNull(mapper);
return new BiCollector<K, V, IntSummaryStatistics>() {
@Override
public <E> Collector<E, ?, IntSummaryStatistics> splitting(
Function<E, K> toKey, Function<E, V> toValue) {
return Collectors.summarizingInt(e -> mapper.applyAsInt(toKey.apply(e), toValue.apply(e)));
}
};
}
/**
* <b>warning:</b> the container must be thread-safed.
*
* @param queueAdder return the change size occurred.
*/
public <E1, C1> SimpleBufferTriggerBuilder<E1, C1> setContainerEx(
Supplier<? extends C1> factory, ToIntBiFunction<? super C1, ? super E1> queueAdder) {
checkNotNull(factory);
checkNotNull(queueAdder);
SimpleBufferTriggerBuilder<E1, C1> thisBuilder = (SimpleBufferTriggerBuilder<E1, C1>) this;
thisBuilder.bufferFactory = (Supplier<C1>) factory;
thisBuilder.queueAdder = (ToIntBiFunction<C1, E1>) queueAdder;
return thisBuilder;
}
/**
* @param queueAdder return the change size occurred.
*/
@CheckReturnValue
public GenericSimpleBufferTriggerBuilder<E, C> setContainerEx(Supplier<? extends C> factory,
ToIntBiFunction<? super C, ? super E> queueAdder) {
builder.setContainerEx(factory, queueAdder);
return this;
}
public PartitionedFeatureVectors(int numPartitions,
ExecutorService executor,
ToIntBiFunction<String,float[]> partitioner) {
Preconditions.checkArgument(numPartitions > 0);
Objects.requireNonNull(executor);
Objects.requireNonNull(partitioner);
partitions = new FeatureVectorsPartition[numPartitions];
for (int i = 0; i < numPartitions; i++) {
partitions[i] = new FeatureVectorsPartition();
}
partitionMap = ObjectIntHashMap.newMap();
partitionMapLock = new AutoReadWriteLock();
this.partitioner = partitioner;
this.executor = executor;
}
/**
* Transforms the entries in the stream to integers by applying a mapper function to each key and value.
*
* @param mapper a mapper function whose return values are included in the new stream
* @return a stream containing the integer values returned from the mapper function
*/
public IntStream mapToInt(ToIntBiFunction<? super K, ? super V> mapper) {
return underlying.mapToInt(e -> mapper.applyAsInt(e.getKey(), e.getValue()));
}