mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-24 20:57:21 +08:00
style: 优化 == 及 != 表达式格式
1.将 null 或常量值调整到符号左侧 2.将无特殊意义的方法判空写法改为表达式判断写法
This commit is contained in:
@@ -46,7 +46,7 @@ public class ExceptionUtils {
|
||||
* 异常
|
||||
*/
|
||||
public static void printException(Runnable runnable, Throwable throwable) {
|
||||
if (throwable == null && runnable instanceof Future<?>) {
|
||||
if (null == throwable && runnable instanceof Future<?>) {
|
||||
try {
|
||||
Future<?> future = (Future<?>)runnable;
|
||||
if (future.isDone()) {
|
||||
@@ -60,7 +60,7 @@ public class ExceptionUtils {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
if (throwable != null) {
|
||||
if (null != throwable) {
|
||||
log.error(throwable.getMessage(), throwable);
|
||||
}
|
||||
}
|
||||
@@ -135,9 +135,9 @@ public class ExceptionUtils {
|
||||
public static <T> T exToDefault(ExSupplier<T> exSupplier, T defaultValue, Consumer<Exception> exConsumer) {
|
||||
try {
|
||||
return exSupplier.get();
|
||||
} catch (Exception ex) {
|
||||
if (exConsumer != null) {
|
||||
exConsumer.accept(ex);
|
||||
} catch (Exception e) {
|
||||
if (null != exConsumer) {
|
||||
exConsumer.accept(e);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
@@ -91,7 +91,7 @@ public class IpUtils {
|
||||
}
|
||||
Ip2regionSearcher ip2regionSearcher = SpringUtil.getBean(Ip2regionSearcher.class);
|
||||
IpInfo ipInfo = ip2regionSearcher.memorySearch(ip);
|
||||
if (ipInfo != null) {
|
||||
if (null != ipInfo) {
|
||||
return ipInfo.getAddress();
|
||||
}
|
||||
return null;
|
||||
|
@@ -65,7 +65,7 @@ public class ServletUtils {
|
||||
* @return 浏览器及其版本信息
|
||||
*/
|
||||
public static String getBrowser(HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
if (null == request) {
|
||||
return null;
|
||||
}
|
||||
UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
||||
|
@@ -54,7 +54,7 @@ public class LoginHelper {
|
||||
* 登录用户信息
|
||||
*/
|
||||
public static void login(LoginUser loginUser) {
|
||||
if (loginUser == null) {
|
||||
if (null == loginUser) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class LoginHelper {
|
||||
loginUser.setLocation(IpUtils.getCityInfo(loginUser.getClientIp()));
|
||||
loginUser.setBrowser(ServletUtils.getBrowser(request));
|
||||
LogContext logContext = LogContextHolder.get();
|
||||
loginUser.setLoginTime(logContext != null ? logContext.getCreateTime() : LocalDateTime.now());
|
||||
loginUser.setLoginTime(null != logContext ? logContext.getCreateTime() : LocalDateTime.now());
|
||||
|
||||
// 登录保存用户信息
|
||||
StpUtil.login(loginUser.getId());
|
||||
@@ -79,7 +79,7 @@ public class LoginHelper {
|
||||
*/
|
||||
public static LoginUser getLoginUser() {
|
||||
LoginUser loginUser = (LoginUser)SaHolder.getStorage().get(CacheConsts.LOGIN_USER_KEY);
|
||||
if (loginUser != null) {
|
||||
if (null != loginUser) {
|
||||
return loginUser;
|
||||
}
|
||||
loginUser = (LoginUser)StpUtil.getTokenSession().get(CacheConsts.LOGIN_USER_KEY);
|
||||
|
@@ -60,7 +60,7 @@ public class QueryHelper {
|
||||
public static <Q, R> QueryWrapper<R> build(Q query) {
|
||||
QueryWrapper<R> queryWrapper = new QueryWrapper<>();
|
||||
// 没有查询条件,直接返回
|
||||
if (query == null) {
|
||||
if (null == query) {
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class QueryHelper {
|
||||
field.setAccessible(true);
|
||||
// 没有 @Query,直接返回
|
||||
Query queryAnnotation = field.getAnnotation(Query.class);
|
||||
if (queryAnnotation == null) {
|
||||
if (null == queryAnnotation) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -47,7 +47,7 @@ public class Validator {
|
||||
* 异常类型
|
||||
*/
|
||||
protected static void throwIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
||||
throwIf(obj == null, message, exceptionType);
|
||||
throwIf(null == obj, message, exceptionType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +61,7 @@ public class Validator {
|
||||
* 异常类型
|
||||
*/
|
||||
protected static void throwIfNotNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
||||
throwIf(obj != null, message, exceptionType);
|
||||
throwIf(null != obj, message, exceptionType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +219,7 @@ public class Validator {
|
||||
*/
|
||||
protected static void throwIf(BooleanSupplier conditionSupplier, String message,
|
||||
Class<? extends RuntimeException> exceptionType) {
|
||||
if (conditionSupplier != null && conditionSupplier.getAsBoolean()) {
|
||||
if (null != conditionSupplier && conditionSupplier.getAsBoolean()) {
|
||||
log.error(message);
|
||||
throw ReflectUtil.newInstance(exceptionType, message);
|
||||
}
|
||||
|
Reference in New Issue
Block a user