Skip to content

Commit

Permalink
Use switch expression where feasible
Browse files Browse the repository at this point in the history
  • Loading branch information
quaff committed Nov 6, 2023
1 parent 4bc63b5 commit 7892478
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,20 @@ private Config.TrustStrategy mapTrustStrategy(Neo4jProperties.Security securityP

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.");
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,20 @@ private List<TypeFilter> createTypeFilters(Filter[] filters) {

@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) {
Expand Down

0 comments on commit 7892478

Please sign in to comment.