Use switch expression where feasible

See gh-38217
This commit is contained in:
Yanming Zhou 2023-11-06 11:05:13 +08:00 committed by Moritz Halbritter
parent a006b26437
commit d7ab153559
3 changed files with 23 additions and 24 deletions

View File

@ -173,22 +173,20 @@ public class Neo4jAutoConfiguration {
private TrustStrategy createTrustStrategy(Neo4jProperties.Security securityProperties, String propertyName,
Security.TrustStrategy strategy) {
switch (strategy) {
case TRUST_ALL_CERTIFICATES:
return TrustStrategy.trustAllCertificates();
case TRUST_SYSTEM_CA_SIGNED_CERTIFICATES:
return TrustStrategy.trustSystemCertificates();
case TRUST_CUSTOM_CA_SIGNED_CERTIFICATES:
return switch (strategy) {
case TRUST_ALL_CERTIFICATES -> TrustStrategy.trustAllCertificates();
case TRUST_SYSTEM_CA_SIGNED_CERTIFICATES -> TrustStrategy.trustSystemCertificates();
case TRUST_CUSTOM_CA_SIGNED_CERTIFICATES -> {
File certFile = securityProperties.getCertFile();
if (certFile == null || !certFile.isFile()) {
throw new InvalidConfigurationPropertyValueException(propertyName, strategy.name(),
"Configured trust strategy requires a certificate file.");
}
return TrustStrategy.trustCustomCertificateSignedBy(certFile);
default:
throw new InvalidConfigurationPropertyValueException(propertyName, strategy.name(),
"Unknown strategy.");
}
yield TrustStrategy.trustCustomCertificateSignedBy(certFile);
}
default -> throw new InvalidConfigurationPropertyValueException(propertyName, strategy.name(),
"Unknown strategy.");
};
}
}

View File

@ -27,12 +27,12 @@ public class MyReadinessStateExporter {
@EventListener
public void onStateChange(AvailabilityChangeEvent<ReadinessState> event) {
switch (event.getState()) {
case ACCEPTING_TRAFFIC:
case ACCEPTING_TRAFFIC -> {
// create file /tmp/healthy
break;
case REFUSING_TRAFFIC:
}
case REFUSING_TRAFFIC -> {
// remove file /tmp/healthy
break;
}
}
}

View File

@ -69,19 +69,20 @@ public class FilterAnnotations implements Iterable<TypeFilter> {
@SuppressWarnings("unchecked")
private TypeFilter createTypeFilter(FilterType filterType, Class<?> filterClass) {
switch (filterType) {
case ANNOTATION:
return switch (filterType) {
case ANNOTATION -> {
Assert.isAssignable(Annotation.class, filterClass,
"An error occurred while processing an ANNOTATION type filter: ");
return new AnnotationTypeFilter((Class<Annotation>) filterClass);
case ASSIGNABLE_TYPE:
return new AssignableTypeFilter(filterClass);
case CUSTOM:
yield new AnnotationTypeFilter((Class<Annotation>) filterClass);
}
case ASSIGNABLE_TYPE -> new AssignableTypeFilter(filterClass);
case CUSTOM -> {
Assert.isAssignable(TypeFilter.class, filterClass,
"An error occurred while processing a CUSTOM type filter: ");
return BeanUtils.instantiateClass(filterClass, TypeFilter.class);
}
throw new IllegalArgumentException("Filter type not supported with Class value: " + filterType);
yield BeanUtils.instantiateClass(filterClass, TypeFilter.class);
}
default -> throw new IllegalArgumentException("Filter type not supported with Class value: " + filterType);
};
}
private TypeFilter createTypeFilter(FilterType filterType, String pattern) {