當前位置: 首頁>>代碼示例>>Java>>正文


Java Function.andThen方法代碼示例

本文整理匯總了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");
    }
}
 
開發者ID:openmicroscopy,項目名稱:omero-ms-queue,代碼行數:17,代碼來源:ArtemisQConnector.java

示例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;
}
 
開發者ID:pedro-borges,項目名稱:Unified-World-Units,代碼行數:25,代碼來源:CompositeUnit.java

示例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;
}
 
開發者ID:pedro-borges,項目名稱:Unified-World-Units,代碼行數:25,代碼來源:CompositeUnit.java

示例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);
}
 
開發者ID:google,項目名稱:mug,代碼行數:11,代碼來源:Maybe.java

示例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();
}
 
開發者ID:fabric8io,項目名稱:kubernetes-alexa,代碼行數:9,代碼來源:IntentContext.java

示例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);
    }
 
開發者ID:daishicheng,項目名稱:outcomes,代碼行數:52,代碼來源:Main.java

示例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);
}
 
開發者ID:unruly,項目名稱:control,代碼行數:8,代碼來源:ApplicableWrapper.java


注:本文中的java.util.function.Function.andThen方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。