Consistent comma splitting without regex overhead
Issue: SPR-14635
This commit is contained in:
@@ -229,10 +229,10 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
|
||||
|
||||
public long[] getHeartbeat() {
|
||||
String rawValue = getFirstNativeHeader(STOMP_HEARTBEAT_HEADER);
|
||||
if (!StringUtils.hasText(rawValue)) {
|
||||
String[] rawValues = StringUtils.split(rawValue, ",");
|
||||
if (rawValues == null) {
|
||||
return Arrays.copyOf(DEFAULT_HEARTBEAT, 2);
|
||||
}
|
||||
String[] rawValues = StringUtils.commaDelimitedListToStringArray(rawValue);
|
||||
return new long[] {Long.valueOf(rawValues[0]), Long.valueOf(rawValues[1])};
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
|
||||
}
|
||||
|
||||
public void setHeartbeat(long cx, long cy) {
|
||||
setNativeHeader(STOMP_HEARTBEAT_HEADER, StringUtils.arrayToCommaDelimitedString(new Object[]{cx, cy}));
|
||||
setNativeHeader(STOMP_HEARTBEAT_HEADER, cx + "," + cy);
|
||||
}
|
||||
|
||||
public void setAck(String ack) {
|
||||
|
||||
@@ -223,9 +223,14 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
|
||||
* Applies to the CONNECT and CONNECTED frames.
|
||||
*/
|
||||
public void setHeartbeat(long[] heartbeat) {
|
||||
Assert.notNull(heartbeat);
|
||||
if (heartbeat == null || heartbeat.length != 2) {
|
||||
throw new IllegalArgumentException("Heart-beat array must be of length 2, not " +
|
||||
(heartbeat != null ? heartbeat.length : "null"));
|
||||
}
|
||||
String value = heartbeat[0] + "," + heartbeat[1];
|
||||
Assert.isTrue(heartbeat[0] >= 0 && heartbeat[1] >= 0, "Heart-beat values cannot be negative: " + value);
|
||||
if (heartbeat[0] < 0 || heartbeat[1] < 0) {
|
||||
throw new IllegalArgumentException("Heart-beat values cannot be negative: " + value);
|
||||
}
|
||||
set(HEARTBEAT, value);
|
||||
}
|
||||
|
||||
@@ -234,10 +239,10 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
|
||||
*/
|
||||
public long[] getHeartbeat() {
|
||||
String rawValue = getFirst(HEARTBEAT);
|
||||
if (!StringUtils.hasText(rawValue)) {
|
||||
String[] rawValues = StringUtils.split(rawValue, ",");
|
||||
if (rawValues == null) {
|
||||
return null;
|
||||
}
|
||||
String[] rawValues = StringUtils.commaDelimitedListToStringArray(rawValue);
|
||||
return new long[] {Long.valueOf(rawValues[0]), Long.valueOf(rawValues[1])};
|
||||
}
|
||||
|
||||
@@ -497,14 +502,8 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof StompHeaders)) {
|
||||
return false;
|
||||
}
|
||||
StompHeaders otherHeaders = (StompHeaders) other;
|
||||
return this.headers.equals(otherHeaders.headers);
|
||||
return (this == other || (other instanceof StompHeaders &&
|
||||
this.headers.equals(((StompHeaders) other).headers)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user