Use enhanced switch expressions where feasible
Closes gh-28014
This commit is contained in:
@@ -101,24 +101,22 @@ public class AspectMetadata implements Serializable {
|
||||
this.ajType = ajType;
|
||||
|
||||
switch (this.ajType.getPerClause().getKind()) {
|
||||
case SINGLETON:
|
||||
case SINGLETON -> {
|
||||
this.perClausePointcut = Pointcut.TRUE;
|
||||
return;
|
||||
case PERTARGET:
|
||||
case PERTHIS:
|
||||
}
|
||||
case PERTARGET, PERTHIS -> {
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setLocation(aspectClass.getName());
|
||||
ajexp.setExpression(findPerClause(aspectClass));
|
||||
ajexp.setPointcutDeclarationScope(aspectClass);
|
||||
this.perClausePointcut = ajexp;
|
||||
return;
|
||||
case PERTYPEWITHIN:
|
||||
}
|
||||
case PERTYPEWITHIN -> {
|
||||
// Works with a type pattern
|
||||
this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass)));
|
||||
return;
|
||||
default:
|
||||
throw new AopConfigException(
|
||||
"PerClause " + ajType.getPerClause().getKind() + " not supported by Spring AOP for " + aspectClass);
|
||||
}
|
||||
default -> throw new AopConfigException(
|
||||
"PerClause " + ajType.getPerClause().getKind() + " not supported by Spring AOP for " + aspectClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -220,21 +220,18 @@ final class InstantiationModelAwarePointcutAdvisorImpl
|
||||
}
|
||||
else {
|
||||
switch (aspectJAnnotation.getAnnotationType()) {
|
||||
case AtPointcut:
|
||||
case AtAround:
|
||||
case AtPointcut, AtAround -> {
|
||||
this.isBeforeAdvice = false;
|
||||
this.isAfterAdvice = false;
|
||||
break;
|
||||
case AtBefore:
|
||||
}
|
||||
case AtBefore -> {
|
||||
this.isBeforeAdvice = true;
|
||||
this.isAfterAdvice = false;
|
||||
break;
|
||||
case AtAfter:
|
||||
case AtAfterReturning:
|
||||
case AtAfterThrowing:
|
||||
}
|
||||
case AtAfter, AtAfterReturning, AtAfterThrowing -> {
|
||||
this.isBeforeAdvice = false;
|
||||
this.isAfterAdvice = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,42 +261,36 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
AbstractAspectJAdvice springAdvice;
|
||||
|
||||
switch (aspectJAnnotation.getAnnotationType()) {
|
||||
case AtPointcut:
|
||||
case AtPointcut -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Processing pointcut '" + candidateAdviceMethod.getName() + "'");
|
||||
}
|
||||
return null;
|
||||
case AtAround:
|
||||
springAdvice = new AspectJAroundAdvice(
|
||||
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||
break;
|
||||
case AtBefore:
|
||||
springAdvice = new AspectJMethodBeforeAdvice(
|
||||
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||
break;
|
||||
case AtAfter:
|
||||
springAdvice = new AspectJAfterAdvice(
|
||||
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||
break;
|
||||
case AtAfterReturning:
|
||||
}
|
||||
case AtAround -> springAdvice = new AspectJAroundAdvice(
|
||||
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||
case AtBefore -> springAdvice = new AspectJMethodBeforeAdvice(
|
||||
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||
case AtAfter -> springAdvice = new AspectJAfterAdvice(
|
||||
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||
case AtAfterReturning -> {
|
||||
springAdvice = new AspectJAfterReturningAdvice(
|
||||
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||
AfterReturning afterReturningAnnotation = (AfterReturning) aspectJAnnotation.getAnnotation();
|
||||
if (StringUtils.hasText(afterReturningAnnotation.returning())) {
|
||||
springAdvice.setReturningName(afterReturningAnnotation.returning());
|
||||
}
|
||||
break;
|
||||
case AtAfterThrowing:
|
||||
}
|
||||
case AtAfterThrowing -> {
|
||||
springAdvice = new AspectJAfterThrowingAdvice(
|
||||
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||
AfterThrowing afterThrowingAnnotation = (AfterThrowing) aspectJAnnotation.getAnnotation();
|
||||
if (StringUtils.hasText(afterThrowingAnnotation.throwing())) {
|
||||
springAdvice.setThrowingName(afterThrowingAnnotation.throwing());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException(
|
||||
"Unsupported advice type on method: " + candidateAdviceMethod);
|
||||
}
|
||||
default -> throw new UnsupportedOperationException(
|
||||
"Unsupported advice type on method: " + candidateAdviceMethod);
|
||||
}
|
||||
|
||||
// Now to configure the advice...
|
||||
|
||||
@@ -61,18 +61,14 @@ public class AbstractPropertyAccessorBenchmark {
|
||||
this.propertyAccessor = new BeanWrapperImpl(this.target);
|
||||
}
|
||||
switch (this.customEditor) {
|
||||
case "stringTrimmer":
|
||||
this.propertyAccessor.registerCustomEditor(String.class, new StringTrimmerEditor(false));
|
||||
break;
|
||||
case "numberOnPath":
|
||||
this.propertyAccessor.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
|
||||
break;
|
||||
case "numberOnNestedPath":
|
||||
this.propertyAccessor.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
|
||||
break;
|
||||
case "numberOnType":
|
||||
this.propertyAccessor.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
|
||||
break;
|
||||
case "stringTrimmer" -> this.propertyAccessor.registerCustomEditor(String.class,
|
||||
new StringTrimmerEditor(false));
|
||||
case "numberOnPath" -> this.propertyAccessor.registerCustomEditor(int.class, "array.somePath",
|
||||
new CustomNumberEditor(Integer.class, false));
|
||||
case "numberOnNestedPath" -> this.propertyAccessor.registerCustomEditor(int.class, "array[0].somePath",
|
||||
new CustomNumberEditor(Integer.class, false));
|
||||
case "numberOnType" -> this.propertyAccessor.registerCustomEditor(int.class,
|
||||
new CustomNumberEditor(Integer.class, false));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -333,20 +333,18 @@ public class MimeMessageHelper {
|
||||
*/
|
||||
protected void createMimeMultiparts(MimeMessage mimeMessage, int multipartMode) throws MessagingException {
|
||||
switch (multipartMode) {
|
||||
case MULTIPART_MODE_NO:
|
||||
setMimeMultiparts(null, null);
|
||||
break;
|
||||
case MULTIPART_MODE_MIXED:
|
||||
case MULTIPART_MODE_NO -> setMimeMultiparts(null, null);
|
||||
case MULTIPART_MODE_MIXED -> {
|
||||
MimeMultipart mixedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_MIXED);
|
||||
mimeMessage.setContent(mixedMultipart);
|
||||
setMimeMultiparts(mixedMultipart, mixedMultipart);
|
||||
break;
|
||||
case MULTIPART_MODE_RELATED:
|
||||
}
|
||||
case MULTIPART_MODE_RELATED -> {
|
||||
MimeMultipart relatedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_RELATED);
|
||||
mimeMessage.setContent(relatedMultipart);
|
||||
setMimeMultiparts(relatedMultipart, relatedMultipart);
|
||||
break;
|
||||
case MULTIPART_MODE_MIXED_RELATED:
|
||||
}
|
||||
case MULTIPART_MODE_MIXED_RELATED -> {
|
||||
MimeMultipart rootMixedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_MIXED);
|
||||
mimeMessage.setContent(rootMixedMultipart);
|
||||
MimeMultipart nestedRelatedMultipart = new MimeMultipart(MULTIPART_SUBTYPE_RELATED);
|
||||
@@ -354,9 +352,9 @@ public class MimeMessageHelper {
|
||||
relatedBodyPart.setContent(nestedRelatedMultipart);
|
||||
rootMixedMultipart.addBodyPart(relatedBodyPart);
|
||||
setMimeMultiparts(rootMixedMultipart, nestedRelatedMultipart);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Only multipart modes MIXED_RELATED, RELATED and NO supported");
|
||||
}
|
||||
default -> throw new IllegalArgumentException(
|
||||
"Only multipart modes MIXED_RELATED, RELATED and NO supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,14 +68,10 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
|
||||
*/
|
||||
@Override
|
||||
public String[] selectImports(AdviceMode adviceMode) {
|
||||
switch (adviceMode) {
|
||||
case PROXY:
|
||||
return getProxyImports();
|
||||
case ASPECTJ:
|
||||
return getAspectJImports();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch (adviceMode) {
|
||||
case PROXY -> getProxyImports();
|
||||
case ASPECTJ -> getAspectJImports();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,38 +78,32 @@ public abstract class TypeFilterUtils {
|
||||
|
||||
for (Class<?> filterClass : filterAttributes.getClassArray("classes")) {
|
||||
switch (filterType) {
|
||||
case ANNOTATION:
|
||||
case ANNOTATION -> {
|
||||
Assert.isAssignable(Annotation.class, filterClass,
|
||||
"@ComponentScan ANNOTATION type filter requires an annotation type");
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<Annotation> annotationType = (Class<Annotation>) filterClass;
|
||||
typeFilters.add(new AnnotationTypeFilter(annotationType));
|
||||
break;
|
||||
case ASSIGNABLE_TYPE:
|
||||
typeFilters.add(new AssignableTypeFilter(filterClass));
|
||||
break;
|
||||
case CUSTOM:
|
||||
}
|
||||
case ASSIGNABLE_TYPE -> typeFilters.add(new AssignableTypeFilter(filterClass));
|
||||
case CUSTOM -> {
|
||||
Assert.isAssignable(TypeFilter.class, filterClass,
|
||||
"@ComponentScan CUSTOM type filter requires a TypeFilter implementation");
|
||||
TypeFilter filter = ParserStrategyUtils.instantiateClass(filterClass, TypeFilter.class,
|
||||
environment, resourceLoader, registry);
|
||||
typeFilters.add(filter);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Filter type not supported with Class value: " + filterType);
|
||||
}
|
||||
default -> throw new IllegalArgumentException(
|
||||
"Filter type not supported with Class value: " + filterType);
|
||||
}
|
||||
}
|
||||
|
||||
for (String expression : filterAttributes.getStringArray("pattern")) {
|
||||
switch (filterType) {
|
||||
case ASPECTJ:
|
||||
typeFilters.add(new AspectJTypeFilter(expression, resourceLoader.getClassLoader()));
|
||||
break;
|
||||
case REGEX:
|
||||
typeFilters.add(new RegexPatternTypeFilter(Pattern.compile(expression)));
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Filter type not supported with String pattern: " + filterType);
|
||||
case ASPECTJ -> typeFilters.add(new AspectJTypeFilter(expression, resourceLoader.getClassLoader()));
|
||||
case REGEX -> typeFilters.add(new RegexPatternTypeFilter(Pattern.compile(expression)));
|
||||
default -> throw new IllegalArgumentException(
|
||||
"Filter type not supported with String pattern: " + filterType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -209,11 +209,11 @@ public class DateTimeFormatterRegistrar implements FormatterRegistrar {
|
||||
}
|
||||
|
||||
private DateTimeFormatter getFallbackFormatter(Type type) {
|
||||
switch (type) {
|
||||
case DATE: return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
|
||||
case TIME: return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
|
||||
default: return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
|
||||
}
|
||||
return switch (type) {
|
||||
case DATE -> DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
|
||||
case TIME -> DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
|
||||
case DATE_TIME -> DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.scheduling.annotation;
|
||||
|
||||
import org.springframework.context.annotation.AdviceMode;
|
||||
import org.springframework.context.annotation.AdviceModeImportSelector;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
/**
|
||||
* Selects which implementation of {@link AbstractAsyncConfiguration} should
|
||||
@@ -43,16 +43,12 @@ public class AsyncConfigurationSelector extends AdviceModeImportSelector<EnableA
|
||||
* respectively.
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
@NonNull
|
||||
public String[] selectImports(AdviceMode adviceMode) {
|
||||
switch (adviceMode) {
|
||||
case PROXY:
|
||||
return new String[] {ProxyAsyncConfiguration.class.getName()};
|
||||
case ASPECTJ:
|
||||
return new String[] {ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch (adviceMode) {
|
||||
case PROXY -> new String[]{ProxyAsyncConfiguration.class.getName()};
|
||||
case ASPECTJ -> new String[]{ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME};
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -163,22 +163,13 @@ public final class TypePath {
|
||||
int length = getLength();
|
||||
StringBuilder result = new StringBuilder(length * 2);
|
||||
for (int i = 0; i < length; ++i) {
|
||||
switch (getStep(i)) {
|
||||
case ARRAY_ELEMENT:
|
||||
result.append('[');
|
||||
break;
|
||||
case INNER_TYPE:
|
||||
result.append('.');
|
||||
break;
|
||||
case WILDCARD_BOUND:
|
||||
result.append('*');
|
||||
break;
|
||||
case TYPE_ARGUMENT:
|
||||
result.append(getStepArgument(i)).append(';');
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
switch (getStep(i)) {
|
||||
case ARRAY_ELEMENT -> result.append('[');
|
||||
case INNER_TYPE -> result.append('.');
|
||||
case WILDCARD_BOUND -> result.append('*');
|
||||
case TYPE_ARGUMENT -> result.append(getStepArgument(i)).append(';');
|
||||
default -> throw new AssertionError();
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@@ -95,19 +95,13 @@ abstract class AnnotationsScanner {
|
||||
private static <C, R> R processClass(C context, Class<?> source,
|
||||
SearchStrategy searchStrategy, AnnotationsProcessor<C, R> processor) {
|
||||
|
||||
switch (searchStrategy) {
|
||||
case DIRECT:
|
||||
return processElement(context, source, processor);
|
||||
case INHERITED_ANNOTATIONS:
|
||||
return processClassInheritedAnnotations(context, source, searchStrategy, processor);
|
||||
case SUPERCLASS:
|
||||
return processClassHierarchy(context, source, processor, false, false);
|
||||
case TYPE_HIERARCHY:
|
||||
return processClassHierarchy(context, source, processor, true, false);
|
||||
case TYPE_HIERARCHY_AND_ENCLOSING_CLASSES:
|
||||
return processClassHierarchy(context, source, processor, true, true);
|
||||
}
|
||||
throw new IllegalStateException("Unsupported search strategy " + searchStrategy);
|
||||
return switch (searchStrategy) {
|
||||
case DIRECT -> processElement(context, source, processor);
|
||||
case INHERITED_ANNOTATIONS -> processClassInheritedAnnotations(context, source, searchStrategy, processor);
|
||||
case SUPERCLASS -> processClassHierarchy(context, source, processor, false, false);
|
||||
case TYPE_HIERARCHY -> processClassHierarchy(context, source, processor, true, false);
|
||||
case TYPE_HIERARCHY_AND_ENCLOSING_CLASSES -> processClassHierarchy(context, source, processor, true, true);
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -238,19 +232,14 @@ abstract class AnnotationsScanner {
|
||||
private static <C, R> R processMethod(C context, Method source,
|
||||
SearchStrategy searchStrategy, AnnotationsProcessor<C, R> processor) {
|
||||
|
||||
switch (searchStrategy) {
|
||||
case DIRECT:
|
||||
case INHERITED_ANNOTATIONS:
|
||||
return processMethodInheritedAnnotations(context, source, processor);
|
||||
case SUPERCLASS:
|
||||
return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(),
|
||||
processor, source, false);
|
||||
case TYPE_HIERARCHY:
|
||||
case TYPE_HIERARCHY_AND_ENCLOSING_CLASSES:
|
||||
return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(),
|
||||
processor, source, true);
|
||||
}
|
||||
throw new IllegalStateException("Unsupported search strategy " + searchStrategy);
|
||||
return switch (searchStrategy) {
|
||||
case DIRECT, INHERITED_ANNOTATIONS -> processMethodInheritedAnnotations(context, source, processor);
|
||||
case SUPERCLASS -> processMethodHierarchy(context, new int[]{0}, source.getDeclaringClass(),
|
||||
processor, source, false);
|
||||
case TYPE_HIERARCHY, TYPE_HIERARCHY_AND_ENCLOSING_CLASSES -> processMethodHierarchy(context, new int[]{0},
|
||||
source.getDeclaringClass(),
|
||||
processor, source, true);
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -70,25 +70,23 @@ final class ProfilesParser {
|
||||
continue;
|
||||
}
|
||||
switch (token) {
|
||||
case "(":
|
||||
case "(" -> {
|
||||
Profiles contents = parseTokens(expression, tokens, Context.BRACKET);
|
||||
if (context == Context.INVERT) {
|
||||
return contents;
|
||||
}
|
||||
elements.add(contents);
|
||||
break;
|
||||
case "&":
|
||||
}
|
||||
case "&" -> {
|
||||
assertWellFormed(expression, operator == null || operator == Operator.AND);
|
||||
operator = Operator.AND;
|
||||
break;
|
||||
case "|":
|
||||
}
|
||||
case "|" -> {
|
||||
assertWellFormed(expression, operator == null || operator == Operator.OR);
|
||||
operator = Operator.OR;
|
||||
break;
|
||||
case "!":
|
||||
elements.add(not(parseTokens(expression, tokens, Context.INVERT)));
|
||||
break;
|
||||
case ")":
|
||||
}
|
||||
case "!" -> elements.add(not(parseTokens(expression, tokens, Context.INVERT)));
|
||||
case ")" -> {
|
||||
Profiles merged = merge(expression, elements, operator);
|
||||
if (context == Context.BRACKET) {
|
||||
return merged;
|
||||
@@ -96,13 +94,14 @@ final class ProfilesParser {
|
||||
elements.clear();
|
||||
elements.add(merged);
|
||||
operator = null;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default -> {
|
||||
Profiles value = equals(token);
|
||||
if (context == Context.INVERT) {
|
||||
return value;
|
||||
}
|
||||
elements.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return merge(expression, elements, operator);
|
||||
|
||||
@@ -608,14 +608,11 @@ public abstract class DataBufferUtils {
|
||||
|
||||
private static NestedMatcher createMatcher(byte[] delimiter) {
|
||||
Assert.isTrue(delimiter.length > 0, "Delimiter must not be empty");
|
||||
switch (delimiter.length) {
|
||||
case 1:
|
||||
return (delimiter[0] == 10 ? SingleByteMatcher.NEWLINE_MATCHER : new SingleByteMatcher(delimiter));
|
||||
case 2:
|
||||
return new TwoByteMatcher(delimiter);
|
||||
default:
|
||||
return new KnuthMorrisPrattMatcher(delimiter);
|
||||
}
|
||||
return switch (delimiter.length) {
|
||||
case 1 -> (delimiter[0] == 10 ? SingleByteMatcher.NEWLINE_MATCHER : new SingleByteMatcher(delimiter));
|
||||
case 2 -> new TwoByteMatcher(delimiter);
|
||||
default -> new KnuthMorrisPrattMatcher(delimiter);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -56,16 +56,12 @@ public class ListenableFutureCallbackRegistry<T> {
|
||||
Assert.notNull(callback, "'callback' must not be null");
|
||||
synchronized (this.mutex) {
|
||||
switch (this.state) {
|
||||
case NEW:
|
||||
case NEW -> {
|
||||
this.successCallbacks.add(callback);
|
||||
this.failureCallbacks.add(callback);
|
||||
break;
|
||||
case SUCCESS:
|
||||
notifySuccess(callback);
|
||||
break;
|
||||
case FAILURE:
|
||||
notifyFailure(callback);
|
||||
break;
|
||||
}
|
||||
case SUCCESS -> notifySuccess(callback);
|
||||
case FAILURE -> notifyFailure(callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,12 +95,8 @@ public class ListenableFutureCallbackRegistry<T> {
|
||||
Assert.notNull(callback, "'callback' must not be null");
|
||||
synchronized (this.mutex) {
|
||||
switch (this.state) {
|
||||
case NEW:
|
||||
this.successCallbacks.add(callback);
|
||||
break;
|
||||
case SUCCESS:
|
||||
notifySuccess(callback);
|
||||
break;
|
||||
case NEW -> this.successCallbacks.add(callback);
|
||||
case SUCCESS -> notifySuccess(callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,12 +110,8 @@ public class ListenableFutureCallbackRegistry<T> {
|
||||
Assert.notNull(callback, "'callback' must not be null");
|
||||
synchronized (this.mutex) {
|
||||
switch (this.state) {
|
||||
case NEW:
|
||||
this.failureCallbacks.add(callback);
|
||||
break;
|
||||
case FAILURE:
|
||||
notifyFailure(callback);
|
||||
break;
|
||||
case NEW -> this.failureCallbacks.add(callback);
|
||||
case FAILURE -> notifyFailure(callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,10 +287,8 @@ public enum SpelMessage {
|
||||
public String formatMessage(Object... inserts) {
|
||||
StringBuilder formattedMessage = new StringBuilder();
|
||||
formattedMessage.append("EL").append(this.code);
|
||||
switch (this.kind) {
|
||||
case ERROR:
|
||||
formattedMessage.append('E');
|
||||
break;
|
||||
if (this.kind == Kind.ERROR) {
|
||||
formattedMessage.append('E');
|
||||
}
|
||||
formattedMessage.append(": ");
|
||||
formattedMessage.append(MessageFormat.format(this.message, inserts));
|
||||
|
||||
@@ -115,21 +115,12 @@ public class OpDivide extends Operator {
|
||||
cf.exitCompilationScope();
|
||||
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, targetDesc);
|
||||
switch (targetDesc) {
|
||||
case 'I':
|
||||
mv.visitInsn(IDIV);
|
||||
break;
|
||||
case 'J':
|
||||
mv.visitInsn(LDIV);
|
||||
break;
|
||||
case 'F':
|
||||
mv.visitInsn(FDIV);
|
||||
break;
|
||||
case 'D':
|
||||
mv.visitInsn(DDIV);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
case 'I' -> mv.visitInsn(IDIV);
|
||||
case 'J' -> mv.visitInsn(LDIV);
|
||||
case 'F' -> mv.visitInsn(FDIV);
|
||||
case 'D' -> mv.visitInsn(DDIV);
|
||||
default -> throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
}
|
||||
}
|
||||
cf.pushDescriptor(this.exitTypeDescriptor);
|
||||
|
||||
@@ -184,40 +184,22 @@ public class OpMinus extends Operator {
|
||||
cf.exitCompilationScope();
|
||||
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, targetDesc);
|
||||
switch (targetDesc) {
|
||||
case 'I':
|
||||
mv.visitInsn(ISUB);
|
||||
break;
|
||||
case 'J':
|
||||
mv.visitInsn(LSUB);
|
||||
break;
|
||||
case 'F':
|
||||
mv.visitInsn(FSUB);
|
||||
break;
|
||||
case 'D':
|
||||
mv.visitInsn(DSUB);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
case 'I' -> mv.visitInsn(ISUB);
|
||||
case 'J' -> mv.visitInsn(LSUB);
|
||||
case 'F' -> mv.visitInsn(FSUB);
|
||||
case 'D' -> mv.visitInsn(DSUB);
|
||||
default -> throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (targetDesc) {
|
||||
case 'I':
|
||||
mv.visitInsn(INEG);
|
||||
break;
|
||||
case 'J':
|
||||
mv.visitInsn(LNEG);
|
||||
break;
|
||||
case 'F':
|
||||
mv.visitInsn(FNEG);
|
||||
break;
|
||||
case 'D':
|
||||
mv.visitInsn(DNEG);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
case 'I' -> mv.visitInsn(INEG);
|
||||
case 'J' -> mv.visitInsn(LNEG);
|
||||
case 'F' -> mv.visitInsn(FNEG);
|
||||
case 'D' -> mv.visitInsn(DNEG);
|
||||
default -> throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
}
|
||||
}
|
||||
cf.pushDescriptor(this.exitTypeDescriptor);
|
||||
|
||||
@@ -112,21 +112,12 @@ public class OpModulus extends Operator {
|
||||
cf.exitCompilationScope();
|
||||
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, targetDesc);
|
||||
switch (targetDesc) {
|
||||
case 'I':
|
||||
mv.visitInsn(IREM);
|
||||
break;
|
||||
case 'J':
|
||||
mv.visitInsn(LREM);
|
||||
break;
|
||||
case 'F':
|
||||
mv.visitInsn(FREM);
|
||||
break;
|
||||
case 'D':
|
||||
mv.visitInsn(DREM);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
case 'I' -> mv.visitInsn(IREM);
|
||||
case 'J' -> mv.visitInsn(LREM);
|
||||
case 'F' -> mv.visitInsn(FREM);
|
||||
case 'D' -> mv.visitInsn(DREM);
|
||||
default -> throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
}
|
||||
}
|
||||
cf.pushDescriptor(this.exitTypeDescriptor);
|
||||
|
||||
@@ -140,21 +140,12 @@ public class OpMultiply extends Operator {
|
||||
cf.exitCompilationScope();
|
||||
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, targetDesc);
|
||||
switch (targetDesc) {
|
||||
case 'I':
|
||||
mv.visitInsn(IMUL);
|
||||
break;
|
||||
case 'J':
|
||||
mv.visitInsn(LMUL);
|
||||
break;
|
||||
case 'F':
|
||||
mv.visitInsn(FMUL);
|
||||
break;
|
||||
case 'D':
|
||||
mv.visitInsn(DMUL);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
case 'I' -> mv.visitInsn(IMUL);
|
||||
case 'J' -> mv.visitInsn(LMUL);
|
||||
case 'F' -> mv.visitInsn(FMUL);
|
||||
case 'D' -> mv.visitInsn(DMUL);
|
||||
default -> throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
}
|
||||
}
|
||||
cf.pushDescriptor(this.exitTypeDescriptor);
|
||||
|
||||
@@ -226,21 +226,12 @@ public class OpPlus extends Operator {
|
||||
cf.exitCompilationScope();
|
||||
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, targetDesc);
|
||||
switch (targetDesc) {
|
||||
case 'I':
|
||||
mv.visitInsn(IADD);
|
||||
break;
|
||||
case 'J':
|
||||
mv.visitInsn(LADD);
|
||||
break;
|
||||
case 'F':
|
||||
mv.visitInsn(FADD);
|
||||
break;
|
||||
case 'D':
|
||||
mv.visitInsn(DADD);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
case 'I' -> mv.visitInsn(IADD);
|
||||
case 'J' -> mv.visitInsn(LADD);
|
||||
case 'F' -> mv.visitInsn(FADD);
|
||||
case 'D' -> mv.visitInsn(DADD);
|
||||
default -> throw new IllegalStateException(
|
||||
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,12 +209,12 @@ public class Selection extends SpelNodeImpl {
|
||||
}
|
||||
|
||||
private String prefix() {
|
||||
switch (this.variant) {
|
||||
case ALL: return "?[";
|
||||
case FIRST: return "^[";
|
||||
case LAST: return "$[";
|
||||
}
|
||||
return "";
|
||||
return switch (this.variant) {
|
||||
case ALL -> "?[";
|
||||
case FIRST -> "^[";
|
||||
case LAST -> "$[";
|
||||
default -> "";
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -84,22 +84,19 @@ final class LogAdapter {
|
||||
* @param name the logger name
|
||||
*/
|
||||
public static Log createLog(String name) {
|
||||
switch (logApi) {
|
||||
case LOG4J:
|
||||
return Log4jAdapter.createLog(name);
|
||||
case SLF4J_LAL:
|
||||
return Slf4jAdapter.createLocationAwareLog(name);
|
||||
case SLF4J:
|
||||
return Slf4jAdapter.createLog(name);
|
||||
default:
|
||||
// Defensively use lazy-initializing adapter class here as well since the
|
||||
// java.logging module is not present by default on JDK 9. We are requiring
|
||||
// its presence if neither Log4j nor SLF4J is available; however, in the
|
||||
// case of Log4j or SLF4J, we are trying to prevent early initialization
|
||||
// of the JavaUtilLog adapter - e.g. by a JVM in debug mode - when eagerly
|
||||
// trying to parse the bytecode for all the cases of this switch clause.
|
||||
return JavaUtilAdapter.createLog(name);
|
||||
}
|
||||
return switch (logApi) {
|
||||
case LOG4J -> Log4jAdapter.createLog(name);
|
||||
case SLF4J_LAL -> Slf4jAdapter.createLocationAwareLog(name);
|
||||
case SLF4J -> Slf4jAdapter.createLog(name);
|
||||
default ->
|
||||
// Defensively use lazy-initializing adapter class here as well since the
|
||||
// java.logging module is not present by default on JDK 9. We are requiring
|
||||
// its presence if neither Log4j nor SLF4J is available; however, in the
|
||||
// case of Log4j or SLF4J, we are trying to prevent early initialization
|
||||
// of the JavaUtilLog adapter - e.g. by a JVM in debug mode - when eagerly
|
||||
// trying to parse the bytecode for all the cases of this switch clause.
|
||||
JavaUtilAdapter.createLog(name);
|
||||
};
|
||||
}
|
||||
|
||||
private static boolean isPresent(String className) {
|
||||
|
||||
@@ -155,14 +155,11 @@ public class MarshallingMessageConverter implements MessageConverter, Initializi
|
||||
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
|
||||
Assert.state(this.marshaller != null, "No Marshaller set");
|
||||
try {
|
||||
switch (this.targetType) {
|
||||
case TEXT:
|
||||
return marshalToTextMessage(object, session, this.marshaller);
|
||||
case BYTES:
|
||||
return marshalToBytesMessage(object, session, this.marshaller);
|
||||
default:
|
||||
return marshalToMessage(object, session, this.marshaller, this.targetType);
|
||||
}
|
||||
return switch (this.targetType) {
|
||||
case TEXT -> marshalToTextMessage(object, session, this.marshaller);
|
||||
case BYTES -> marshalToBytesMessage(object, session, this.marshaller);
|
||||
default -> marshalToMessage(object, session, this.marshaller, this.targetType);
|
||||
};
|
||||
}
|
||||
catch (XmlMappingException | IOException ex) {
|
||||
throw new MessageConversionException("Could not marshal [" + object + "]", ex);
|
||||
|
||||
@@ -145,18 +145,15 @@ public class DefaultSubscriptionRegistryBenchmark {
|
||||
@Setup(Level.Trial)
|
||||
public void doSetup(ServerState serverState) {
|
||||
switch (this.contention) {
|
||||
case "noSubscribers":
|
||||
case "noSubscribers" -> {
|
||||
this.destination = "someDestination_withNoSubscribers_" + serverState.uniqueIdGenerator.incrementAndGet();
|
||||
break;
|
||||
case "sameDestination":
|
||||
this.destination = serverState.destinationIds[0];
|
||||
break;
|
||||
case "none":
|
||||
}
|
||||
case "sameDestination" -> this.destination = serverState.destinationIds[0];
|
||||
case "none" -> {
|
||||
int uniqueNumber = serverState.uniqueIdGenerator.getAndIncrement();
|
||||
this.destination = serverState.destinationIds[uniqueNumber % serverState.destinationIds.length];
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
default -> throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,20 +192,16 @@ public class RSocketFrameTypeMessageCondition extends AbstractMessageCondition<R
|
||||
* @since 5.2.2
|
||||
*/
|
||||
public static RSocketFrameTypeMessageCondition getCondition(int cardinalityIn, int cardinalityOut) {
|
||||
switch (cardinalityIn) {
|
||||
case 0:
|
||||
case 1:
|
||||
switch (cardinalityOut) {
|
||||
case 0: return REQUEST_FNF_OR_RESPONSE_CONDITION;
|
||||
case 1: return REQUEST_RESPONSE_CONDITION;
|
||||
case 2: return REQUEST_STREAM_CONDITION;
|
||||
default: throw new IllegalStateException("Invalid cardinality: " + cardinalityOut);
|
||||
}
|
||||
case 2:
|
||||
return REQUEST_CHANNEL_CONDITION;
|
||||
default:
|
||||
throw new IllegalStateException("Invalid cardinality: " + cardinalityIn);
|
||||
}
|
||||
return switch (cardinalityIn) {
|
||||
case 0, 1 -> switch (cardinalityOut) {
|
||||
case 0 -> REQUEST_FNF_OR_RESPONSE_CONDITION;
|
||||
case 1 -> REQUEST_RESPONSE_CONDITION;
|
||||
case 2 -> REQUEST_STREAM_CONDITION;
|
||||
default -> throw new IllegalStateException("Invalid cardinality: " + cardinalityOut);
|
||||
};
|
||||
case 2 -> REQUEST_CHANNEL_CONDITION;
|
||||
default -> throw new IllegalStateException("Invalid cardinality: " + cardinalityIn);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -266,13 +266,14 @@ public abstract class SharedEntityManagerCreator {
|
||||
this.targetFactory, this.properties, this.synchronizedWithTransaction);
|
||||
|
||||
switch (method.getName()) {
|
||||
case "getTargetEntityManager":
|
||||
case "getTargetEntityManager" -> {
|
||||
// Handle EntityManagerProxy interface.
|
||||
if (target == null) {
|
||||
throw new IllegalStateException("No transactional EntityManager available");
|
||||
}
|
||||
return target;
|
||||
case "unwrap":
|
||||
}
|
||||
case "unwrap" -> {
|
||||
Class<?> targetClass = (Class<?>) args[0];
|
||||
if (targetClass == null) {
|
||||
return (target != null ? target : proxy);
|
||||
@@ -281,8 +282,8 @@ public abstract class SharedEntityManagerCreator {
|
||||
if (target == null) {
|
||||
throw new IllegalStateException("No transactional EntityManager available");
|
||||
}
|
||||
// Still perform unwrap call on target EntityManager.
|
||||
break;
|
||||
}
|
||||
// Still perform unwrap call on target EntityManager.
|
||||
}
|
||||
|
||||
if (transactionRequiringMethods.contains(method.getName())) {
|
||||
|
||||
@@ -94,19 +94,19 @@ public class EclipseLinkJpaVendorAdapter extends AbstractJpaVendorAdapter {
|
||||
*/
|
||||
@Nullable
|
||||
protected String determineTargetDatabaseName(Database database) {
|
||||
switch (database) {
|
||||
case DB2: return TargetDatabase.DB2;
|
||||
case DERBY: return TargetDatabase.Derby;
|
||||
case HANA: return TargetDatabase.HANA;
|
||||
case HSQL: return TargetDatabase.HSQL;
|
||||
case INFORMIX: return TargetDatabase.Informix;
|
||||
case MYSQL: return TargetDatabase.MySQL;
|
||||
case ORACLE: return TargetDatabase.Oracle;
|
||||
case POSTGRESQL: return TargetDatabase.PostgreSQL;
|
||||
case SQL_SERVER: return TargetDatabase.SQLServer;
|
||||
case SYBASE: return TargetDatabase.Sybase;
|
||||
default: return null;
|
||||
}
|
||||
return switch (database) {
|
||||
case DB2 -> TargetDatabase.DB2;
|
||||
case DERBY -> TargetDatabase.Derby;
|
||||
case HANA -> TargetDatabase.HANA;
|
||||
case HSQL -> TargetDatabase.HSQL;
|
||||
case INFORMIX -> TargetDatabase.Informix;
|
||||
case MYSQL -> TargetDatabase.MySQL;
|
||||
case ORACLE -> TargetDatabase.Oracle;
|
||||
case POSTGRESQL -> TargetDatabase.PostgreSQL;
|
||||
case SQL_SERVER -> TargetDatabase.SQLServer;
|
||||
case SYBASE -> TargetDatabase.Sybase;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -169,20 +169,20 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter {
|
||||
*/
|
||||
@Nullable
|
||||
protected Class<?> determineDatabaseDialectClass(Database database) {
|
||||
switch (database) {
|
||||
case DB2: return DB2Dialect.class;
|
||||
case DERBY: return DerbyTenSevenDialect.class;
|
||||
case H2: return H2Dialect.class;
|
||||
case HANA: return HANAColumnStoreDialect.class;
|
||||
case HSQL: return HSQLDialect.class;
|
||||
case INFORMIX: return Informix10Dialect.class;
|
||||
case MYSQL: return MySQL57Dialect.class;
|
||||
case ORACLE: return Oracle12cDialect.class;
|
||||
case POSTGRESQL: return PostgreSQL95Dialect.class;
|
||||
case SQL_SERVER: return SQLServer2012Dialect.class;
|
||||
case SYBASE: return SybaseDialect.class;
|
||||
default: return null;
|
||||
}
|
||||
return switch (database) {
|
||||
case DB2 -> DB2Dialect.class;
|
||||
case DERBY -> DerbyTenSevenDialect.class;
|
||||
case H2 -> H2Dialect.class;
|
||||
case HANA -> HANAColumnStoreDialect.class;
|
||||
case HSQL -> HSQLDialect.class;
|
||||
case INFORMIX -> Informix10Dialect.class;
|
||||
case MYSQL -> MySQL57Dialect.class;
|
||||
case ORACLE -> Oracle12cDialect.class;
|
||||
case POSTGRESQL -> PostgreSQL95Dialect.class;
|
||||
case SQL_SERVER -> SQLServer2012Dialect.class;
|
||||
case SYBASE -> SybaseDialect.class;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -415,17 +415,13 @@ public class R2dbcTransactionManager extends AbstractReactiveTransactionManager
|
||||
*/
|
||||
@Nullable
|
||||
protected IsolationLevel resolveIsolationLevel(int isolationLevel) {
|
||||
switch (isolationLevel) {
|
||||
case TransactionDefinition.ISOLATION_READ_COMMITTED:
|
||||
return IsolationLevel.READ_COMMITTED;
|
||||
case TransactionDefinition.ISOLATION_READ_UNCOMMITTED:
|
||||
return IsolationLevel.READ_UNCOMMITTED;
|
||||
case TransactionDefinition.ISOLATION_REPEATABLE_READ:
|
||||
return IsolationLevel.REPEATABLE_READ;
|
||||
case TransactionDefinition.ISOLATION_SERIALIZABLE:
|
||||
return IsolationLevel.SERIALIZABLE;
|
||||
}
|
||||
return null;
|
||||
return switch (isolationLevel) {
|
||||
case TransactionDefinition.ISOLATION_READ_COMMITTED -> IsolationLevel.READ_COMMITTED;
|
||||
case TransactionDefinition.ISOLATION_READ_UNCOMMITTED -> IsolationLevel.READ_UNCOMMITTED;
|
||||
case TransactionDefinition.ISOLATION_REPEATABLE_READ -> IsolationLevel.REPEATABLE_READ;
|
||||
case TransactionDefinition.ISOLATION_SERIALIZABLE -> IsolationLevel.SERIALIZABLE;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -154,20 +154,11 @@ public class MockPageContext extends PageContext {
|
||||
public void setAttribute(String name, @Nullable Object value, int scope) {
|
||||
Assert.notNull(name, "Attribute name must not be null");
|
||||
switch (scope) {
|
||||
case PAGE_SCOPE:
|
||||
setAttribute(name, value);
|
||||
break;
|
||||
case REQUEST_SCOPE:
|
||||
this.request.setAttribute(name, value);
|
||||
break;
|
||||
case SESSION_SCOPE:
|
||||
this.request.getSession().setAttribute(name, value);
|
||||
break;
|
||||
case APPLICATION_SCOPE:
|
||||
this.servletContext.setAttribute(name, value);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid scope: " + scope);
|
||||
case PAGE_SCOPE -> setAttribute(name, value);
|
||||
case REQUEST_SCOPE -> this.request.setAttribute(name, value);
|
||||
case SESSION_SCOPE -> this.request.getSession().setAttribute(name, value);
|
||||
case APPLICATION_SCOPE -> this.servletContext.setAttribute(name, value);
|
||||
default -> throw new IllegalArgumentException("Invalid scope: " + scope);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,20 +217,11 @@ public class MockPageContext extends PageContext {
|
||||
public void removeAttribute(String name, int scope) {
|
||||
Assert.notNull(name, "Attribute name must not be null");
|
||||
switch (scope) {
|
||||
case PAGE_SCOPE:
|
||||
this.attributes.remove(name);
|
||||
break;
|
||||
case REQUEST_SCOPE:
|
||||
this.request.removeAttribute(name);
|
||||
break;
|
||||
case SESSION_SCOPE:
|
||||
this.request.getSession().removeAttribute(name);
|
||||
break;
|
||||
case APPLICATION_SCOPE:
|
||||
this.servletContext.removeAttribute(name);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid scope: " + scope);
|
||||
case PAGE_SCOPE -> this.attributes.remove(name);
|
||||
case REQUEST_SCOPE -> this.request.removeAttribute(name);
|
||||
case SESSION_SCOPE -> this.request.getSession().removeAttribute(name);
|
||||
case APPLICATION_SCOPE -> this.servletContext.removeAttribute(name);
|
||||
default -> throw new IllegalArgumentException("Invalid scope: " + scope);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,16 +49,12 @@ public class HeuristicCompletionException extends TransactionException {
|
||||
|
||||
|
||||
public static String getStateString(int state) {
|
||||
switch (state) {
|
||||
case STATE_COMMITTED:
|
||||
return "committed";
|
||||
case STATE_ROLLED_BACK:
|
||||
return "rolled back";
|
||||
case STATE_MIXED:
|
||||
return "mixed";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
return switch (state) {
|
||||
case STATE_COMMITTED -> "committed";
|
||||
case STATE_ROLLED_BACK -> "rolled back";
|
||||
case STATE_MIXED -> "mixed";
|
||||
default -> "unknown";
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -171,14 +171,9 @@ public class SpringJtaSynchronizationAdapter implements Synchronization {
|
||||
}
|
||||
// Call afterCompletion with the appropriate status indication.
|
||||
switch (status) {
|
||||
case Status.STATUS_COMMITTED:
|
||||
this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_COMMITTED);
|
||||
break;
|
||||
case Status.STATUS_ROLLEDBACK:
|
||||
this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||
break;
|
||||
default:
|
||||
this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
|
||||
case Status.STATUS_COMMITTED -> this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_COMMITTED);
|
||||
case Status.STATUS_ROLLEDBACK -> this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||
default -> this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,18 +154,10 @@ final class Jackson2Tokenizer {
|
||||
|
||||
private void updateDepth(JsonToken token) {
|
||||
switch (token) {
|
||||
case START_OBJECT:
|
||||
this.objectDepth++;
|
||||
break;
|
||||
case END_OBJECT:
|
||||
this.objectDepth--;
|
||||
break;
|
||||
case START_ARRAY:
|
||||
this.arrayDepth++;
|
||||
break;
|
||||
case END_ARRAY:
|
||||
this.arrayDepth--;
|
||||
break;
|
||||
case START_OBJECT -> this.objectDepth++;
|
||||
case END_OBJECT -> this.objectDepth--;
|
||||
case START_ARRAY -> this.arrayDepth++;
|
||||
case END_ARRAY -> this.arrayDepth--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -164,12 +164,9 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
|
||||
String message = getErrorMessage(statusCode.value(), statusText, body, charset);
|
||||
|
||||
switch (statusCode.series()) {
|
||||
case CLIENT_ERROR:
|
||||
throw HttpClientErrorException.create(message, statusCode, statusText, headers, body, charset);
|
||||
case SERVER_ERROR:
|
||||
throw HttpServerErrorException.create(message, statusCode, statusText, headers, body, charset);
|
||||
default:
|
||||
throw new UnknownHttpStatusCodeException(message, statusCode.value(), statusText, headers, body, charset);
|
||||
case CLIENT_ERROR -> throw HttpClientErrorException.create(message, statusCode, statusText, headers, body, charset);
|
||||
case SERVER_ERROR -> throw HttpServerErrorException.create(message, statusCode, statusText, headers, body, charset);
|
||||
default -> throw new UnknownHttpStatusCodeException(message, statusCode.value(), statusText, headers, body, charset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,20 +154,11 @@ public class MockPageContext extends PageContext {
|
||||
public void setAttribute(String name, @Nullable Object value, int scope) {
|
||||
Assert.notNull(name, "Attribute name must not be null");
|
||||
switch (scope) {
|
||||
case PAGE_SCOPE:
|
||||
setAttribute(name, value);
|
||||
break;
|
||||
case REQUEST_SCOPE:
|
||||
this.request.setAttribute(name, value);
|
||||
break;
|
||||
case SESSION_SCOPE:
|
||||
this.request.getSession().setAttribute(name, value);
|
||||
break;
|
||||
case APPLICATION_SCOPE:
|
||||
this.servletContext.setAttribute(name, value);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid scope: " + scope);
|
||||
case PAGE_SCOPE -> setAttribute(name, value);
|
||||
case REQUEST_SCOPE -> this.request.setAttribute(name, value);
|
||||
case SESSION_SCOPE -> this.request.getSession().setAttribute(name, value);
|
||||
case APPLICATION_SCOPE -> this.servletContext.setAttribute(name, value);
|
||||
default -> throw new IllegalArgumentException("Invalid scope: " + scope);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,20 +217,11 @@ public class MockPageContext extends PageContext {
|
||||
public void removeAttribute(String name, int scope) {
|
||||
Assert.notNull(name, "Attribute name must not be null");
|
||||
switch (scope) {
|
||||
case PAGE_SCOPE:
|
||||
this.attributes.remove(name);
|
||||
break;
|
||||
case REQUEST_SCOPE:
|
||||
this.request.removeAttribute(name);
|
||||
break;
|
||||
case SESSION_SCOPE:
|
||||
this.request.getSession().removeAttribute(name);
|
||||
break;
|
||||
case APPLICATION_SCOPE:
|
||||
this.servletContext.removeAttribute(name);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid scope: " + scope);
|
||||
case PAGE_SCOPE -> this.attributes.remove(name);
|
||||
case REQUEST_SCOPE -> this.request.removeAttribute(name);
|
||||
case SESSION_SCOPE -> this.request.getSession().removeAttribute(name);
|
||||
case APPLICATION_SCOPE -> this.servletContext.removeAttribute(name);
|
||||
default -> throw new IllegalArgumentException("Invalid scope: " + scope);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,24 +82,23 @@ class ViewControllerBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
String name = element.getLocalName();
|
||||
switch (name) {
|
||||
case "view-controller":
|
||||
case "view-controller" -> {
|
||||
if (element.hasAttribute("view-name")) {
|
||||
controller.getPropertyValues().add("viewName", element.getAttribute("view-name"));
|
||||
}
|
||||
if (statusCode != null) {
|
||||
controller.getPropertyValues().add("statusCode", statusCode);
|
||||
}
|
||||
break;
|
||||
case "redirect-view-controller":
|
||||
controller.getPropertyValues().add("view", getRedirectView(element, statusCode, source));
|
||||
break;
|
||||
case "status-controller":
|
||||
}
|
||||
case "redirect-view-controller" -> controller.getPropertyValues()
|
||||
.add("view", getRedirectView(element, statusCode, source));
|
||||
case "status-controller" -> {
|
||||
controller.getPropertyValues().add("statusCode", statusCode);
|
||||
controller.getPropertyValues().add("statusOnly", true);
|
||||
break;
|
||||
default:
|
||||
// Should never happen...
|
||||
throw new IllegalStateException("Unexpected tag name: " + name);
|
||||
}
|
||||
default ->
|
||||
// Should never happen...
|
||||
throw new IllegalStateException("Unexpected tag name: " + name);
|
||||
}
|
||||
|
||||
Map<String, BeanDefinition> urlMap = (Map<String, BeanDefinition>) hm.getPropertyValues().get("urlMap");
|
||||
|
||||
@@ -210,12 +210,12 @@ public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorat
|
||||
}
|
||||
else if (getBufferSize() > getBufferSizeLimit()) {
|
||||
switch (this.overflowStrategy) {
|
||||
case TERMINATE:
|
||||
case TERMINATE -> {
|
||||
String format = "Buffer size %d bytes for session '%s' exceeds the allowed limit %d";
|
||||
String reason = String.format(format, getBufferSize(), getId(), getBufferSizeLimit());
|
||||
limitExceeded(reason);
|
||||
break;
|
||||
case DROP:
|
||||
}
|
||||
case DROP -> {
|
||||
int i = 0;
|
||||
while (getBufferSize() > getBufferSizeLimit()) {
|
||||
WebSocketMessage<?> message = this.buffer.poll();
|
||||
@@ -228,10 +228,7 @@ public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorat
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Dropped " + i + " messages, buffer size: " + getBufferSize());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Should never happen..
|
||||
throw new IllegalStateException("Unexpected OverflowStrategy: " + this.overflowStrategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,17 +407,14 @@ public abstract class AbstractSockJsSession implements SockJsSession {
|
||||
}
|
||||
|
||||
private static List<String> getUndelivered(String[] messages, int i) {
|
||||
switch (messages.length - i) {
|
||||
case 0:
|
||||
return Collections.emptyList();
|
||||
case 1:
|
||||
return (messages[i].trim().isEmpty() ?
|
||||
Collections.emptyList() : Collections.singletonList(messages[i]));
|
||||
default:
|
||||
return Arrays.stream(Arrays.copyOfRange(messages, i, messages.length))
|
||||
.filter(message -> !message.trim().isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return switch (messages.length - i) {
|
||||
case 0 -> Collections.emptyList();
|
||||
case 1 -> (messages[i].trim().isEmpty() ?
|
||||
Collections.<String>emptyList() : Collections.singletonList(messages[i]));
|
||||
default -> Arrays.stream(Arrays.copyOfRange(messages, i, messages.length))
|
||||
.filter(message -> !message.trim().isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user