本文整理汇总了Java中java.util.function.Function.andThen方法的典型用法代码示例。如果您正苦于以下问题:Java Function.andThen方法的具体用法?Java Function.andThen怎么用?Java Function.andThen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.function.Function
的用法示例。
在下文中一共展示了Function.andThen方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queueMessage
import java.util.function.Function; //导入方法依赖的package包/类
@Override
public ArtemisMessage queueMessage(QMessageType t) {
requireNonNull(t, "message type");
Function<Boolean, ClientMessage> create = session::createMessage;
Function<Boolean, ArtemisMessage> builder =
create.andThen(ArtemisMessage::new); // (2)
switch (t) {
case Durable:
return builder.apply(true);
case NonDurable:
return builder.apply(false);
default: // (1)
throw new IllegalArgumentException("unsupported message type");
}
}
示例2: getTranslationToCanonical
import java.util.function.Function; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Function<BigDecimalAmount, BigDecimalAmount> getTranslationToCanonical() {
Function<BigDecimalAmount, BigDecimalAmount> result = Function.identity();
for (UnitCount unitCount : unitCounter.getBaseUnits()) {
BaseUnit unit = unitCount.getUnit();
int count = unitCount.getCount();
if (count > 0) {
for (int i = 0; i < count; i++) {
result = result.andThen(unit.getTranslationToCanonical());
}
} else if (count < 0) {
for (int i = 0; i > count; i--) {
result = result.andThen(unit.getTranslationFromCanonical());
}
}
}
return result;
}
示例3: getTranslationFromCanonical
import java.util.function.Function; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Function<BigDecimalAmount, BigDecimalAmount> getTranslationFromCanonical() {
Function<BigDecimalAmount, BigDecimalAmount> result = Function.identity();
for (UnitCount unitCount : unitCounter.getBaseUnits()) {
BaseUnit unit = unitCount.getUnit();
int count = unitCount.getCount();
if (count > 0) {
for (int i = 0; i < count; i++) {
result = result.andThen(unit.getTranslationFromCanonical());
}
} else if (count < 0) {
for (int i = 0; i > count; i--) {
result = result.andThen(unit.getTranslationToCanonical());
}
}
}
return result;
}
示例4: maybeStream
import java.util.function.Function; //导入方法依赖的package包/类
/**
* Wraps {@code function} that returns {@code Stream<T>} to one that returns
* {@code Stream<Maybe<T, E>>} with exceptions of type {@code E} wrapped.
*/
public static <F, T, E extends Throwable> Function<F, Stream<Maybe<T, E>>> maybeStream(
CheckedFunction<? super F, ? extends Stream<? extends T>, ? extends E> function,
Class<E> exceptionType) {
Function<F, Maybe<Stream<? extends T>, E>> wrapped = maybe(function, exceptionType);
return wrapped.andThen(Maybe::maybeStream);
}
示例5: asOperation
import java.util.function.Function; //导入方法依赖的package包/类
public T asOperation(Function<IntentContext, IntentContext>... functions) {
Function<IntentContext, IntentContext> next = s -> s;
for (Function<IntentContext, IntentContext> f : functions) {
next = next.andThen(f);
}
return (T) next.apply(new IntentContext<T>(intent, session, operation, client)).getOperation();
}
示例6: main
import java.util.function.Function; //导入方法依赖的package包/类
public static void main(String... args) {
Predicate<String> predicate = String::isEmpty;
//等价与 Predicate<String> predicate = s -> !s.isEmpty();
// predicate.negate();
// ps : and 和 or是按照其表达式在链中的位置 由左到右确定优先级
// a.or(b).and(c)可以看作(a || b) && c
// predicate.and()
// predicate.or()
// predicate.equals()
//编译错误 Lambda表达式引用的局部变量必须是final的
// Integer i = 1337;
// Runnable foo = () -> System.out.print(i);
// i = 2000;
//构造对象 只提供了两个参数 多个参数的可以自己写函数式接口
Supplier<Lambdaer> s = Lambdaer::new;
Lambdaer lambdaerOne = s.get();
Function<String, Lambdaer> lambda = Lambdaer::new;
Lambdaer guard = lambda.apply("guard");
BiFunction<String, String, Lambdaer> b = Lambdaer::new;
Lambdaer lambdaerTwo = b.apply("guardOne", "guardTwo");
//正序
List<Integer> str = Arrays.asList(3, 5, 0, 10, 1, 2);
Comparator<Integer> compare = Integer::compare;
str.sort(compare);
//逆序
str.sort(compare.reversed());
//链 优先顺序
// str.sort(compare.reversed().thenComparing());
// 等价于数学上的g(f(x))
Function<Integer, Integer> f = x -> x + 1;
Function<Integer, Integer> g = x -> x * 2;
Function<Integer, Integer> h = f.andThen(g);
int result = h.apply(1);
// 等价于数学上的f(g(x))
// Function<Integer, Integer> f = x -> x + 1;
// Function<Integer, Integer> g = x -> x * 2;
// Function<Integer, Integer> h = f.compose(g);
// int result = h.apply(1);
}
示例7: apply
import java.util.function.Function; //导入方法依赖的package包/类
/**
* When passed to ApplicableWrapper.then(), applies the given function to the wrapped value,
* returning a new ApplicableWrapper containing the result.
*/
public static <I, O> Function<I, ApplicableWrapper<O>> apply(Function<I, O> function) {
return function.andThen(ApplicableWrapper::new);
}