当前位置: 首页>>代码示例>>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;未经允许,请勿转载。