On 18/10/2009, [email protected] <[email protected]> wrote:
> Author: bayard
> Date: Sun Oct 18 20:14:30 2009
> New Revision: 826514
>
> URL: http://svn.apache.org/viewvc?rev=826514&view=rev
> Log:
> Sebb pointed out that the implementation for LANG-507 was not thread safe.
> Rewriting to pass parameters in to the constructor, but doing so in an
> experimental way - comments very much desired on whether this makes for a
> nice API or not
>
> Modified:
>
> commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnicodeUnescaper.java
>
> commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java
>
> Modified:
> commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnicodeUnescaper.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnicodeUnescaper.java?rev=826514&r1=826513&r2=826514&view=diff
>
> ==============================================================================
> ---
> commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnicodeUnescaper.java
> (original)
> +++
> commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnicodeUnescaper.java
> Sun Oct 18 20:14:30 2009
> @@ -19,6 +19,9 @@
> import java.io.IOException;
> import java.io.Writer;
>
> +import java.util.EnumSet;
> +import java.util.Arrays;
> +
> /**
> * Translates escaped unicode values of the form \\u+\d\d\d\d back to
> * unicode.
> @@ -26,13 +29,18 @@
> */
> public class UnicodeUnescaper extends CharSequenceTranslator {
>
> - private boolean escapingPlus = false;
> + public static enum PARAM { escapePlus };
> +
> + private EnumSet<PARAM> params;
This is not final, so its value is not necessarily published to other
threads - i.e. the class is still not thread-safe.
> - public void setEscapingPlus(boolean b) {
> - this.escapingPlus = b;
> + public UnicodeUnescaper(PARAM... params) {
> + if(params.length > 0) {
> + this.params = EnumSet.copyOf(Arrays.asList(params));
> + }
> }
> - public boolean isEscapingPlus() {
> - return this.escapingPlus;
> +
> + public boolean isSet(PARAM p) {
> + return (params == null) ? false : params.contains(p);
> }
>
> /**
> @@ -50,7 +58,7 @@
> }
>
> // consume + symbol in \\u+0045
> - if(isEscapingPlus()) {
> + if(isSet(PARAM.escapePlus)) {
> if( (index + i < input.length()) && (input.charAt(index
> + i) == '+') ) {
> i++;
> }
>
> Modified:
> commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java?rev=826514&r1=826513&r2=826514&view=diff
>
> ==============================================================================
> ---
> commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java
> (original)
> +++
> commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java
> Sun Oct 18 20:14:30 2009
> @@ -36,7 +36,7 @@
> // expected
> }
>
> - uu.setEscapingPlus(true);
> + uu = new UnicodeUnescaper(UnicodeUnescaper.PARAM.escapePlus);
> assertEquals("Failed to unescape unicode characters with 'u+'
> notation", "G", uu.translate(input));
> }
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]