Created
July 11, 2022 01:25
-
-
Save friddle/bd57392e11d199be2901432c0405ef0f to your computer and use it in GitHub Desktop.
AlsoIf(Java函数式的判断后执行操作)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* AlsoIf.alsoIf(xxx,xxx,xx).alsoIf().get() | |
* 进行长条件判断.如果条件成立,则执行相应的操作.主要用于LambadaQuery上 | |
* java lambda for predicate and do things | |
*/ | |
@Slf4j | |
public class BizAlsoIf<R> { | |
R obj; | |
private BizAlsoIf(R objj){ | |
obj=objj; | |
} | |
public static<R> BizAlsoIf<R> alsoIf(R obj, boolean isIf, Consumer<R> consumer){ | |
BizAlsoIf<R> r=new BizAlsoIf<R>(obj); | |
return r.alsoIf(isIf,consumer); | |
} | |
public BizAlsoIf<R> alsoIf(boolean isIf, Consumer<R> consumer){ | |
try { | |
if(isIf){ | |
consumer.accept(obj); | |
} | |
return this; | |
} catch (Exception e) { | |
log.error("try method failed", e); | |
throw e; | |
} | |
} | |
public R get(){ | |
return obj; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment