本文整理匯總了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);
}