Use enhanced switch expressions where feasible
Closes gh-28014
This commit is contained in:
@@ -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