From do-not-reply at jboss.org Wed Jan 4 14:28:56 2012 Content-Type: multipart/mixed; boundary="===============1464632510837674129==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: hornetq-commits at lists.jboss.org Subject: [hornetq-commits] JBoss hornetq SVN: r11966 - in branches/Branch_2_2_EAP: tests/src/org/hornetq/tests/unit/util and 1 other directory. Date: Wed, 04 Jan 2012 14:28:55 -0500 Message-ID: <201201041928.q04JStdK021544@svn01.web.mwc.hst.phx2.redhat.com> --===============1464632510837674129== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: clebert.suconic(a)jboss.com Date: 2012-01-04 14:28:55 -0500 (Wed, 04 Jan 2012) New Revision: 11966 Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/api/core/SimpleString.java branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/SimpleStri= ngTest.java Log: Back porting fixes on SimpleString & char (HORNETQ-822) Modified: branches/Branch_2_2_EAP/src/main/org/hornetq/api/core/SimpleStrin= g.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/Branch_2_2_EAP/src/main/org/hornetq/api/core/SimpleString.java= 2012-01-04 16:42:54 UTC (rev 11965) +++ branches/Branch_2_2_EAP/src/main/org/hornetq/api/core/SimpleString.java= 2012-01-04 19:28:55 UTC (rev 11966) @@ -25,7 +25,7 @@ * this minimises expensive copying between String objects. * * This object is used heavily throughout HornetQ for performance reasons. - * = + * * @author Tim Fox * */ @@ -116,7 +116,7 @@ } pos <<=3D 1; = - return (char)(data[pos] | data[pos + 1] << 8); + return (char)((data[pos] & 0xFF) | (data[pos + 1] << 8) & 0xFF00); } = public CharSequence subSequence(final int start, final int end) @@ -215,7 +215,7 @@ { return true; } - = + if (other instanceof SimpleString) { SimpleString s =3D (SimpleString)other; @@ -258,9 +258,8 @@ } = /** - * splits this SimpleString into an array of SimpleString using the cha= r param as the delimeter. - * - * i.e. "a.b" would return "a" and "b" if . was the delimeter + * Splits this SimpleString into an array of SimpleString using the cha= r param as the delimiter. + * i.e. "a.b" would return "a" and "b" if . was the delimiter * @param delim */ public SimpleString[] split(final char delim) @@ -272,11 +271,13 @@ else { List all =3D new ArrayList(); + + byte low =3D (byte)(delim & 0xFF); // low byte + byte high =3D (byte)(delim >> 8 & 0xFF); // high byte + int lasPos =3D 0; for (int i =3D 0; i < data.length; i +=3D 2) { - byte low =3D (byte)(delim & 0xFF); // low byte - byte high =3D (byte)(delim >> 8 & 0xFF); // high byte if (data[i] =3D=3D low && data[i + 1] =3D=3D high) { byte[] bytes =3D new byte[i - lasPos]; @@ -301,10 +302,11 @@ */ public boolean contains(final char c) { + final byte low =3D (byte)(c & 0xFF); // low byte + final byte high =3D (byte)(c >> 8 & 0xFF); // high byte + for (int i =3D 0; i < data.length; i +=3D 2) { - byte low =3D (byte)(c & 0xFF); // low byte - byte high =3D (byte)(c >> 8 & 0xFF); // high byte if (data[i] =3D=3D low && data[i + 1] =3D=3D high) { return true; @@ -314,10 +316,9 @@ } = /** - * concatanates a SimpleString and a String - * - * @param toAdd the String to concate with. - * @return the concatanated SimpleString + * Concatenates a SimpleString and a String + * @param toAdd the String to concatenate with. + * @return the concatenated SimpleString */ public SimpleString concat(final String toAdd) { @@ -325,10 +326,9 @@ } = /** - * concatanates 2 SimpleString's - * - * @param toAdd the SimpleString to concate with. - * @return the concatanated SimpleString + * Concatenates 2 SimpleString's + * @param toAdd the SimpleString to concatenate with. + * @return the concatenated SimpleString */ public SimpleString concat(final SimpleString toAdd) { @@ -339,10 +339,9 @@ } = /** - * concatanates a SimpleString and a char - * + * Concatenates a SimpleString and a char * @param c the char to concate with. - * @return the concatanated SimpleString + * @return the concatenated SimpleString */ public SimpleString concat(final char c) { @@ -390,7 +389,7 @@ } = /** - * = + * * @param srcBegin * @param srcEnd * @param dst Modified: branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/Sim= pleStringTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/SimpleStr= ingTest.java 2012-01-04 16:42:54 UTC (rev 11965) +++ branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/SimpleStr= ingTest.java 2012-01-04 19:28:55 UTC (rev 11966) @@ -23,14 +23,56 @@ import org.hornetq.utils.DataConstants; = /** - * = + * * A SimpleStringTest - * = + * * @author Tim Fox * */ public class SimpleStringTest extends UnitTestCase { + /** + * Converting back and forth between char and byte requires care as cha= r is unsigned. + * @see SimpleString#getChars(int, int, char[], int) + * @see SimpleString#charAt(int) + * @see SimpleString#split(char) + */ + public void testGetChar() + { + SimpleString p1 =3D new SimpleString("foo"); + SimpleString p2 =3D new SimpleString("bar"); + for (int i =3D 0; i < 1 << 16; i++) + { + String msg =3D "expecting " + i; + char c =3D (char)i; + SimpleString s =3D new SimpleString(String.valueOf(c)); + + char[] c1 =3D new char[1]; + s.getChars(0, 1, c1, 0); + assertEquals(msg, c, c1[0]); + assertEquals(msg, c, s.charAt(0)); + SimpleString s2 =3D s.concat(c); + assertEquals(msg, c, s2.charAt(1)); + + // test splitting with chars + SimpleString sSplit =3D new SimpleString("foo" + String.valueOf(c= ) + "bar"); + SimpleString[] chunks =3D sSplit.split(c); + SimpleString[] split1 =3D p1.split(c); + SimpleString[] split2 =3D p2.split(c); + assertEquals(split1.length + split2.length, chunks.length); + int j =3D 0; + + for (SimpleString iS : split1) + { + assertEquals(iS.toString(), iS, chunks[j++]); + } + for (SimpleString iS : split2) + { + assertEquals(iS.toString(), iS, chunks[j++]); + } + } + } + public void testString() throws Exception { final String str =3D "hello123ABC__524`16254`6125!%^$!%$!%$!%$!%!$%!= $$!\uA324"; --===============1464632510837674129==--