package com.yang.demo.mapdemo;
import com.sun.org.apache.xpath.internal.operations.Bool;
import java.util.*;
import java.util.function.Function;
/**
* @author <a href="mailto:1595550476@qq.com">KawYang</a>
* Created by MacBook Pro on 2021/05/08.
*/
public class MapDemo {
static Function<Integer, Boolean> Fn1 = e -> e < 25;
static Function<Integer, Boolean> Fn2 = e -> e > 24 && e < 30;
static Function<Integer, Boolean> Fn3 = e -> e > 29 && e < 40;
static Map<Function<Integer, Boolean>, String> map =new HashMap<Function<Integer, Boolean>, String>(){
{
put(Fn1, "Fn1");
put(Fn2, "Fn2");
}
};
static List<Function<Integer, Boolean>> list = new ArrayList<Function<Integer, Boolean>>(){
{
add(Fn1);
add(Fn2);
}
};
public static void main(String[] args) {
Optional<Function<Integer, Boolean>> x = map.keySet().stream().filter(e -> e.apply(28))
.findFirst();
Function<Integer, Boolean> stringStringFunction = x.orElse(Fn3);
list.forEach(e->System.out.println(e.apply(25)));
}
}
terminal
/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/bin/java -...
false
true