Commit 224980aa1a13e562cbf477c10666940e448f1717
1 parent
495ef72a
feat: 使用 jdk instanceof 新特性
Showing
7 changed files
with
12 additions
and
20 deletions
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/mq/rabbitmq/TenantRabbitMQInitializer.java
| ... | ... | @@ -13,11 +13,10 @@ public class TenantRabbitMQInitializer implements BeanPostProcessor { |
| 13 | 13 | |
| 14 | 14 | @Override |
| 15 | 15 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { |
| 16 | - if (bean instanceof RabbitTemplate) { | |
| 17 | - RabbitTemplate rabbitTemplate = (RabbitTemplate) bean; | |
| 16 | + if (bean instanceof RabbitTemplate rabbitTemplate) { | |
| 18 | 17 | rabbitTemplate.addBeforePublishPostProcessors(new TenantRabbitMQMessagePostProcessor()); |
| 19 | 18 | } |
| 20 | 19 | return bean; |
| 21 | 20 | } |
| 22 | 21 | |
| 23 | -} | |
| 24 | 22 | \ No newline at end of file |
| 23 | +} | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/mq/rocketmq/TenantRocketMQInitializer.java
| ... | ... | @@ -18,11 +18,9 @@ public class TenantRocketMQInitializer implements BeanPostProcessor { |
| 18 | 18 | |
| 19 | 19 | @Override |
| 20 | 20 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { |
| 21 | - if (bean instanceof DefaultRocketMQListenerContainer) { | |
| 22 | - DefaultRocketMQListenerContainer container = (DefaultRocketMQListenerContainer) bean; | |
| 21 | + if (bean instanceof DefaultRocketMQListenerContainer container) { | |
| 23 | 22 | initTenantConsumer(container.getConsumer()); |
| 24 | - } else if (bean instanceof RocketMQTemplate) { | |
| 25 | - RocketMQTemplate template = (RocketMQTemplate) bean; | |
| 23 | + } else if (bean instanceof RocketMQTemplate template) { | |
| 26 | 24 | initTenantProducer(template.getProducer()); |
| 27 | 25 | } |
| 28 | 26 | return bean; |
| ... | ... | @@ -50,4 +48,4 @@ public class TenantRocketMQInitializer implements BeanPostProcessor { |
| 50 | 48 | consumerImpl.registerConsumeMessageHook(new TenantRocketMQConsumeMessageHook()); |
| 51 | 49 | } |
| 52 | 50 | |
| 53 | -} | |
| 54 | 51 | \ No newline at end of file |
| 52 | +} | ... | ... |
yudao-framework/yudao-spring-boot-starter-job/src/main/java/cn/iocoder/yudao/framework/quartz/config/YudaoAsyncAutoConfiguration.java
| ... | ... | @@ -23,15 +23,13 @@ public class YudaoAsyncAutoConfiguration { |
| 23 | 23 | @Override |
| 24 | 24 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { |
| 25 | 25 | // 处理 ThreadPoolTaskExecutor |
| 26 | - if (bean instanceof ThreadPoolTaskExecutor) { | |
| 27 | - ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean; | |
| 26 | + if (bean instanceof ThreadPoolTaskExecutor executor) { | |
| 28 | 27 | executor.setTaskDecorator(TtlRunnable::get); |
| 29 | 28 | return executor; |
| 30 | 29 | } |
| 31 | 30 | // 处理 SimpleAsyncTaskExecutor |
| 32 | 31 | // 参考 https://t.zsxq.com/CBoks 增加 |
| 33 | - if (bean instanceof SimpleAsyncTaskExecutor) { | |
| 34 | - SimpleAsyncTaskExecutor executor = (SimpleAsyncTaskExecutor) bean; | |
| 32 | + if (bean instanceof SimpleAsyncTaskExecutor executor) { | |
| 35 | 33 | executor.setTaskDecorator(TtlRunnable::get); |
| 36 | 34 | return executor; |
| 37 | 35 | } | ... | ... |
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/handler/DefaultDBFieldHandler.java
| ... | ... | @@ -19,8 +19,7 @@ public class DefaultDBFieldHandler implements MetaObjectHandler { |
| 19 | 19 | |
| 20 | 20 | @Override |
| 21 | 21 | public void insertFill(MetaObject metaObject) { |
| 22 | - if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof BaseDO) { | |
| 23 | - BaseDO baseDO = (BaseDO) metaObject.getOriginalObject(); | |
| 22 | + if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof BaseDO baseDO) { | |
| 24 | 23 | |
| 25 | 24 | LocalDateTime current = LocalDateTime.now(); |
| 26 | 25 | // 创建时间为空,则以当前时间为插入时间 | ... | ... |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
| ... | ... | @@ -184,8 +184,7 @@ public class GlobalExceptionHandler { |
| 184 | 184 | @ExceptionHandler(HttpMessageNotReadableException.class) |
| 185 | 185 | public CommonResult<?> methodArgumentTypeInvalidFormatExceptionHandler(HttpMessageNotReadableException ex) { |
| 186 | 186 | log.warn("[methodArgumentTypeInvalidFormatExceptionHandler]", ex); |
| 187 | - if (ex.getCause() instanceof InvalidFormatException) { | |
| 188 | - InvalidFormatException invalidFormatException = (InvalidFormatException) ex.getCause(); | |
| 187 | + if (ex.getCause() instanceof InvalidFormatException invalidFormatException) { | |
| 189 | 188 | return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数类型错误:%s", invalidFormatException.getValue())); |
| 190 | 189 | } |
| 191 | 190 | if (StrUtil.startWith(ex.getMessage(), "Required request body is missing")) { | ... | ... |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java
| ... | ... | @@ -146,10 +146,9 @@ public class WebFrameworkUtils { |
| 146 | 146 | |
| 147 | 147 | public static HttpServletRequest getRequest() { |
| 148 | 148 | RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); |
| 149 | - if (!(requestAttributes instanceof ServletRequestAttributes)) { | |
| 149 | + if (!(requestAttributes instanceof ServletRequestAttributes servletRequestAttributes)) { | |
| 150 | 150 | return null; |
| 151 | 151 | } |
| 152 | - ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes; | |
| 153 | 152 | return servletRequestAttributes.getRequest(); |
| 154 | 153 | } |
| 155 | 154 | ... | ... |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/framework/justauth/core/AuthRequestFactory.java
| ... | ... | @@ -77,8 +77,8 @@ public class AuthRequestFactory { |
| 77 | 77 | extendList = extend.getConfig() |
| 78 | 78 | .keySet() |
| 79 | 79 | .stream() |
| 80 | - .filter(x -> names.contains(x.toUpperCase())) | |
| 81 | 80 | .map(String::toUpperCase) |
| 81 | + .filter(names::contains) | |
| 82 | 82 | .collect(Collectors.toList()); |
| 83 | 83 | } |
| 84 | 84 | |
| ... | ... | @@ -318,4 +318,4 @@ public class AuthRequestFactory { |
| 318 | 318 | .proxy(new Proxy(Proxy.Type.valueOf(proxyConfig.getType()), new InetSocketAddress(proxyConfig.getHostname(), proxyConfig.getPort()))) |
| 319 | 319 | .build()); |
| 320 | 320 | } |
| 321 | -} | |
| 322 | 321 | \ No newline at end of file |
| 322 | +} | ... | ... |