Apply "instanceof pattern matching" in remainder of spring-context-support module

See gh-30067
This commit is contained in:
Sam Brannen
2023-03-05 16:03:50 +01:00
parent 7766b518d3
commit 162c09d036
7 changed files with 25 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -93,8 +93,8 @@ public class CaffeineCache extends AbstractValueAdaptingCache {
@Override
@Nullable
protected Object lookup(Object key) {
if (this.cache instanceof LoadingCache) {
return ((LoadingCache<Object, Object>) this.cache).get(key);
if (this.cache instanceof LoadingCache<Object, Object> loadingCache) {
return loadingCache.get(key);
}
return this.cache.getIfPresent(key);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,8 +48,8 @@ public abstract class AbstractJCacheConfiguration extends AbstractCachingConfigu
protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) {
super.useCachingConfigurer(cachingConfigurerSupplier);
this.exceptionCacheResolver = cachingConfigurerSupplier.adapt(config -> {
if (config instanceof JCacheConfigurer) {
return ((JCacheConfigurer) config).exceptionCacheResolver();
if (config instanceof JCacheConfigurer jcacheConfigurer) {
return jcacheConfigurer.exceptionCacheResolver();
}
return null;
});

View File

@@ -1,10 +1,10 @@
/**
* Support package for declarative JSR-107 caching configuration. Used
* by the regular Spring's caching configuration when it detects the
* JSR-107 API and Spring's JCache implementation.
* Support package for declarative JSR-107 caching configuration. Used by Spring's
* caching configuration when it detects the JSR-107 API and Spring's JCache
* implementation.
*
* <p>Provide an extension of the {@code CachingConfigurer} that exposes
* the exception cache resolver to use, see {@code JCacheConfigurer}.
* <p>Provides an extension of the {@code CachingConfigurer} that exposes
* the exception cache resolver to use (see {@code JCacheConfigurer}).
*/
@NonNullApi
@NonNullFields

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,8 +42,8 @@ class DefaultCacheKeyInvocationContext<A extends Annotation> extends DefaultCach
public DefaultCacheKeyInvocationContext(AbstractJCacheKeyOperation<A> operation, Object target, Object[] args) {
super(operation, target, args);
this.keyParameters = operation.getKeyParameters(args);
if (operation instanceof CachePutOperation) {
this.valueParameter = ((CachePutOperation) operation).getValueParameter(args);
if (operation instanceof CachePutOperation cachePutOperation) {
this.valueParameter = cachePutOperation.getValueParameter(args);
}
else {
this.valueParameter = null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -71,11 +71,11 @@ public class AdaptableJobFactory implements JobFactory {
* @see DelegatingJob
*/
protected Job adaptJob(Object jobObject) throws Exception {
if (jobObject instanceof Job) {
return (Job) jobObject;
if (jobObject instanceof Job job) {
return job;
}
else if (jobObject instanceof Runnable) {
return new DelegatingJob((Runnable) jobObject);
else if (jobObject instanceof Runnable runnable) {
return new DelegatingJob(runnable);
}
else {
throw new IllegalArgumentException(

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -267,9 +267,9 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod
context.setResult(this.methodInvoker.invoke());
}
catch (InvocationTargetException ex) {
if (ex.getTargetException() instanceof JobExecutionException) {
if (ex.getTargetException() instanceof JobExecutionException jobExecutionException) {
// -> JobExecutionException, to be logged at info level by Quartz
throw (JobExecutionException) ex.getTargetException();
throw jobExecutionException;
}
else {
// -> "unhandled exception", to be logged at error level by Quartz

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -256,8 +256,8 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
throw tex;
}
}
if (ex instanceof SchedulerException) {
throw (SchedulerException) ex;
if (ex instanceof SchedulerException schedulerException) {
throw schedulerException;
}
if (ex instanceof Exception) {
throw new SchedulerException("Registration of jobs and triggers failed: " + ex.getMessage(), ex);