update 简化 stream 代码写法 (java 16) xx.collect(Collectors.toList()) => xx.toList() ;

update 简化 instanceof 代码写法 (java 12) 直接在后面定义变量 ;
update 简化 switch 代码写法 (java 12) ;
This commit is contained in:
zlyx 2023-01-19 20:03:26 +08:00
parent afbc78b672
commit 57da2e33a6
11 changed files with 18 additions and 27 deletions

View File

@ -30,7 +30,7 @@ public class StreamUtils {
if (CollUtil.isEmpty(collection)) { if (CollUtil.isEmpty(collection)) {
return CollUtil.newArrayList(); return CollUtil.newArrayList();
} }
return collection.stream().filter(function).collect(Collectors.toList()); return collection.stream().filter(function).toList();
} }
/** /**
@ -70,7 +70,7 @@ public class StreamUtils {
if (CollUtil.isEmpty(collection)) { if (CollUtil.isEmpty(collection)) {
return CollUtil.newArrayList(); return CollUtil.newArrayList();
} }
return collection.stream().sorted(comparing).collect(Collectors.toList()); return collection.stream().sorted(comparing).toList();
} }
/** /**
@ -188,7 +188,7 @@ public class StreamUtils {
.stream() .stream()
.map(function) .map(function)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toList()); .toList();
} }
/** /**

View File

@ -55,9 +55,8 @@ public class DefaultExcelListener<T> extends AnalysisEventListener<T> implements
@Override @Override
public void onException(Exception exception, AnalysisContext context) throws Exception { public void onException(Exception exception, AnalysisContext context) throws Exception {
String errMsg = null; String errMsg = null;
if (exception instanceof ExcelDataConvertException) { if (exception instanceof ExcelDataConvertException excelDataConvertException) {
// 如果是某一个单元格的转换异常 能获取到具体行号 // 如果是某一个单元格的转换异常 能获取到具体行号
ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception;
Integer rowIndex = excelDataConvertException.getRowIndex(); Integer rowIndex = excelDataConvertException.getRowIndex();
Integer columnIndex = excelDataConvertException.getColumnIndex(); Integer columnIndex = excelDataConvertException.getColumnIndex();
errMsg = StrUtil.format("第{}行-第{}列-表头{}: 解析异常<br/>", errMsg = StrUtil.format("第{}行-第{}列-表头{}: 解析异常<br/>",
@ -66,8 +65,7 @@ public class DefaultExcelListener<T> extends AnalysisEventListener<T> implements
log.error(errMsg); log.error(errMsg);
} }
} }
if (exception instanceof ConstraintViolationException) { if (exception instanceof ConstraintViolationException constraintViolationException) {
ConstraintViolationException constraintViolationException = (ConstraintViolationException) exception;
Set<ConstraintViolation<?>> constraintViolations = constraintViolationException.getConstraintViolations(); Set<ConstraintViolation<?>> constraintViolations = constraintViolationException.getConstraintViolations();
String constraintViolationsMsg = StreamUtils.join(constraintViolations, ConstraintViolation::getMessage, ", "); String constraintViolationsMsg = StreamUtils.join(constraintViolations, ConstraintViolation::getMessage, ", ");
errMsg = StrUtil.format("第{}行数据校验异常: {}", context.readRowHolder().getRowIndex() + 1, constraintViolationsMsg); errMsg = StrUtil.format("第{}行数据校验异常: {}", context.readRowHolder().getRowIndex() + 1, constraintViolationsMsg);

View File

@ -78,9 +78,8 @@ public class RepeatSubmitAspect {
*/ */
@AfterReturning(pointcut = "@annotation(repeatSubmit)", returning = "jsonResult") @AfterReturning(pointcut = "@annotation(repeatSubmit)", returning = "jsonResult")
public void doAfterReturning(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Object jsonResult) { public void doAfterReturning(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Object jsonResult) {
if (jsonResult instanceof R) { if (jsonResult instanceof R r) {
try { try {
R<?> r = (R<?>) jsonResult;
// 成功则不删除redis数据 保证在有效时间内无法重复提交 // 成功则不删除redis数据 保证在有效时间内无法重复提交
if (r.getCode() == R.SUCCESS) { if (r.getCode() == R.SUCCESS) {
return; return;

View File

@ -25,8 +25,7 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
@Override @Override
public void insertFill(MetaObject metaObject) { public void insertFill(MetaObject metaObject) {
try { try {
if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) { if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity baseEntity) {
BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject();
Date current = ObjectUtil.isNotNull(baseEntity.getCreateTime()) Date current = ObjectUtil.isNotNull(baseEntity.getCreateTime())
? baseEntity.getCreateTime() : new Date(); ? baseEntity.getCreateTime() : new Date();
baseEntity.setCreateTime(current); baseEntity.setCreateTime(current);
@ -46,8 +45,7 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
@Override @Override
public void updateFill(MetaObject metaObject) { public void updateFill(MetaObject metaObject) {
try { try {
if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) { if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity baseEntity) {
BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject();
Date current = new Date(); Date current = new Date();
// 更新时间填充(不管为不为空) // 更新时间填充(不管为不为空)
baseEntity.setUpdateTime(current); baseEntity.setUpdateTime(current);

View File

@ -163,7 +163,7 @@ public class PlusDataPermissionHandler {
String methodName = sb.substring(index + 1, sb.length()); String methodName = sb.substring(index + 1, sb.length());
Class<?> clazz = ClassUtil.loadClass(clazzName); Class<?> clazz = ClassUtil.loadClass(clazzName);
List<Method> methods = Arrays.stream(ClassUtil.getDeclaredMethods(clazz)) List<Method> methods = Arrays.stream(ClassUtil.getDeclaredMethods(clazz))
.filter(method -> method.getName().equals(methodName)).collect(Collectors.toList()); .filter(method -> method.getName().equals(methodName)).toList();
DataPermission dataPermission; DataPermission dataPermission;
// 获取方法注解 // 获取方法注解
for (Method method : methods) { for (Method method : methods) {

View File

@ -39,8 +39,8 @@ public class DataPermissionHelper {
saStorage.set(DATA_PERMISSION_KEY, new HashMap<>()); saStorage.set(DATA_PERMISSION_KEY, new HashMap<>());
attribute = saStorage.get(DATA_PERMISSION_KEY); attribute = saStorage.get(DATA_PERMISSION_KEY);
} }
if (attribute instanceof Map) { if (attribute instanceof Map map) {
return (Map<String, Object>) attribute; return map;
} }
throw new NullPointerException("data permission context type exception"); throw new NullPointerException("data permission context type exception");
} }

View File

@ -68,8 +68,7 @@ public class PlusDataPermissionInterceptor extends JsqlParserSupport implements
SelectBody selectBody = select.getSelectBody(); SelectBody selectBody = select.getSelectBody();
if (selectBody instanceof PlainSelect) { if (selectBody instanceof PlainSelect) {
this.setWhere((PlainSelect) selectBody, (String) obj); this.setWhere((PlainSelect) selectBody, (String) obj);
} else if (selectBody instanceof SetOperationList) { } else if (selectBody instanceof SetOperationList setOperationList) {
SetOperationList setOperationList = (SetOperationList) selectBody;
List<SelectBody> selectBodyList = setOperationList.getSelects(); List<SelectBody> selectBodyList = setOperationList.getSelects();
selectBodyList.forEach(s -> this.setWhere((PlainSelect) s, (String) obj)); selectBodyList.forEach(s -> this.setWhere((PlainSelect) s, (String) obj));
} }

View File

@ -221,15 +221,12 @@ public class OssClient {
} }
builder.append("{\n\"Action\": "); builder.append("{\n\"Action\": ");
switch (policyType) { switch (policyType) {
case WRITE: case WRITE ->
builder.append("[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n"); builder.append("[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n");
break; case READ_WRITE ->
case READ_WRITE:
builder.append("[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:GetObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n"); builder.append("[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:GetObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n");
break; default ->
default:
builder.append("\"s3:GetObject\",\n"); builder.append("\"s3:GetObject\",\n");
break;
} }
builder.append("\"Effect\": \"Allow\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::"); builder.append("\"Effect\": \"Allow\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::");
builder.append(bucketName); builder.append(bucketName);

View File

@ -438,7 +438,7 @@ public class RedisUtils {
*/ */
public static Collection<String> keys(final String pattern) { public static Collection<String> keys(final String pattern) {
Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(pattern); Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(pattern);
return stream.collect(Collectors.toList()); return stream.toList();
} }
/** /**

View File

@ -94,7 +94,7 @@ public class CacheController {
if (isCacheNames(cacheName)) { if (isCacheNames(cacheName)) {
Set<Object> keys = CacheUtils.keys(cacheName); Set<Object> keys = CacheUtils.keys(cacheName);
if (CollUtil.isNotEmpty(keys)) { if (CollUtil.isNotEmpty(keys)) {
cacheKeys = keys.stream().map(Object::toString).collect(Collectors.toList()); cacheKeys = keys.stream().map(Object::toString).toList();
} }
} else { } else {
cacheKeys = RedisUtils.keys(cacheName + "*"); cacheKeys = RedisUtils.keys(cacheName + "*");

View File

@ -52,7 +52,7 @@ public class SysOssServiceImpl implements ISysOssService {
public TableDataInfo<SysOssVo> queryPageList(SysOssBo bo, PageQuery pageQuery) { public TableDataInfo<SysOssVo> queryPageList(SysOssBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<SysOss> lqw = buildQueryWrapper(bo); LambdaQueryWrapper<SysOss> lqw = buildQueryWrapper(bo);
Page<SysOssVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw); Page<SysOssVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
List<SysOssVo> filterResult = result.getRecords().stream().map(this::matchingUrl).collect(Collectors.toList()); List<SysOssVo> filterResult = result.getRecords().stream().map(this::matchingUrl).toList();
result.setRecords(filterResult); result.setRecords(filterResult);
return TableDataInfo.build(result); return TableDataInfo.build(result);
} }