package com.guahao.dap.mi.access.external.base;
import lombok.Data;
/**
* @author
* @version V1.0
* @since 2022/3/22 16:28
*/
@Data
public class Head {
private String eyes;
private String mouth;
private String noise;
}
package com.guahao.dap.mi.access.external.base;
import lombok.Data;
/**
* @author
* @version V1.0
* @since 2022/3/22 15:50
*/
@Data
public class Result {
private String statusCode;
/**
* /状态描述信息
*/
private String desc;
}
package com.guahao.dap.mi.access.external.base;
import org.apache.cxf.jaxws.javaee.CString;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* @author
* @version V1.0
* @since 2022/3/22 15:27
*/
@FunctionalInterface
public interface ThrowExceptionFunction<T extends Object> {
//定义三个消费接口(只有入参,没有出参)
void doAction(Consumer<? super T> action1,Consumer<? super T> action2,Consumer<? super T> action3);
}
package com.guahao.dap.mi.access.external.base;
/**
* @author
* @version V1.0
* @since 2022/3/22 15:30
*/
public class VUtils {
public static ThrowExceptionFunction getResult(Head b) {
return (co1,co2,co3) -> {
if(b.getMouth()!=null){
co1.accept("mouth");
}else if(b.getEyes()!=null){
co2.accept("eyes");
}else {
co3.accept("else");
}
};
}
}
package com.guahao.dap.mi.access.external.base;
/**
* @author
* @version V1.0
* @since 2021/10/27 15:56
*/
public class Test {
@org.junit.Test
public void test() {
Head head = new Head();
head.setEyes("111");
Result result = new Result();
VUtils.getResult(head).doAction(a -> {
result.setDesc("有嘴"+a);
},a -> {
result.setDesc("有眼睛"+a);
},a -> {
result.setDesc("其他"+a);
});
System.out.println(result);
}
}
|