Consistent comma splitting without regex overhead

Issue: SPR-14635
(cherry picked from commit 03609c1)
This commit is contained in:
Juergen Hoeller
2016-08-30 23:56:58 +02:00
parent 3b91dec462
commit d8f7347000
10 changed files with 98 additions and 98 deletions

View File

@@ -228,10 +228,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])};
}
@@ -297,7 +297,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) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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