Use switch expression where feasible

This commit is contained in:
Yanming Zhou
2023-11-01 10:49:43 +08:00
committed by Sam Brannen
parent 8ed04b5dd1
commit 490b5c77fc
28 changed files with 420 additions and 424 deletions

View File

@@ -94,20 +94,20 @@ public class LoadTimeWeavingConfiguration implements ImportAware, BeanClassLoade
if (this.enableLTW != null) {
AspectJWeaving aspectJWeaving = this.enableLTW.getEnum("aspectjWeaving");
switch (aspectJWeaving) {
case DISABLED:
case DISABLED -> {
// AJ weaving is disabled -> do nothing
break;
case AUTODETECT:
}
case AUTODETECT -> {
if (this.beanClassLoader.getResource(AspectJWeavingEnabler.ASPECTJ_AOP_XML_RESOURCE) == null) {
// No aop.xml present on the classpath -> treat as 'disabled'
break;
}
// aop.xml is present on the classpath -> enable
AspectJWeavingEnabler.enableAspectJWeaving(loadTimeWeaver, this.beanClassLoader);
break;
case ENABLED:
}
case ENABLED -> {
AspectJWeavingEnabler.enableAspectJWeaving(loadTimeWeaver, this.beanClassLoader);
break;
}
}
}

View File

@@ -277,13 +277,15 @@ public class DateFormatter implements Formatter<Date> {
private int getStylePatternForChar(int index) {
if (this.stylePattern != null && this.stylePattern.length() > index) {
switch (this.stylePattern.charAt(index)) {
case 'S': return DateFormat.SHORT;
case 'M': return DateFormat.MEDIUM;
case 'L': return DateFormat.LONG;
case 'F': return DateFormat.FULL;
case '-': return -1;
}
char ch = this.stylePattern.charAt(index);
return switch (ch) {
case 'S' -> DateFormat.SHORT;
case 'M' -> DateFormat.MEDIUM;
case 'L' -> DateFormat.LONG;
case 'F' -> DateFormat.FULL;
case '-' -> -1;
default -> throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'");
};
}
throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'");
}