commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r754653 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/Entities.java test/org/apache/commons/lang/EntitiesPerformanceTest.java
Date Sun, 15 Mar 2009 11:18:30 GMT
Author: sebb
Date: Sun Mar 15 11:18:30 2009
New Revision: 754653

URL: http://svn.apache.org/viewvc?rev=754653&view=rev
Log:
Don't expose static arrays to potential writes, even for testing
Add package protected read method instead

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/EntitiesPerformanceTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java?rev=754653&r1=754652&r2=754653&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java Sun Mar 15 11:18:30
2009
@@ -51,8 +51,7 @@
     private static final String[][] APOS_ARRAY = {{"apos", "39"}, // XML apostrophe
     };
 
-    // package scoped for testing
-    static final String[][] ISO8859_1_ARRAY = {{"nbsp", "160"}, // non-breaking space
+    private static final String[][] ISO8859_1_ARRAY = {{"nbsp", "160"}, // non-breaking space
         {"iexcl", "161"}, // inverted exclamation mark
         {"cent", "162"}, // cent sign
         {"pound", "163"}, // pound sign
@@ -150,9 +149,15 @@
         {"yuml", "255"}, // ΓΏ - lowercase y, umlaut
     };
 
-    // http://www.w3.org/TR/REC-html40/sgml/entities.html
     // package scoped for testing
-    static final String[][] HTML40_ARRAY = {
+    static int ISO8859_1_ARRAY_LENGTH = ISO8859_1_ARRAY.length;
+    
+    static String getISO8859_1(int i, int j) {
+        return ISO8859_1_ARRAY[i][j];
+    }
+
+    // http://www.w3.org/TR/REC-html40/sgml/entities.html
+    private static final String[][] HTML40_ARRAY = {
     // <!-- Latin Extended-B -->
         {"fnof", "402"}, // latin small f with hook = function= florin, U+0192 ISOtech -->
         // <!-- Greek -->
@@ -348,6 +353,13 @@
         // <!-- rsaquo is proposed but not yet ISO standardized -->
         {"euro", "8364"}, // -- euro sign, U+20AC NEW -->
     };
+    
+    // package scoped for testing
+    static int HTML40_ARRAY_LENGTH = HTML40_ARRAY.length;
+    
+    static String getHTML40(int i, int j) {
+        return HTML40_ARRAY[i][j];
+    }
 
     /**
      * <p>
@@ -438,9 +450,9 @@
     }
 
     static class PrimitiveEntityMap implements EntityMap {
-        private Map mapNameToValue = new HashMap();
+        private final Map mapNameToValue = new HashMap();
 
-        private IntHashMap mapValueToName = new IntHashMap();
+        private final IntHashMap mapValueToName = new IntHashMap();
 
         /**
          * {@inheritDoc}

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/EntitiesPerformanceTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/EntitiesPerformanceTest.java?rev=754653&r1=754652&r2=754653&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/EntitiesPerformanceTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/EntitiesPerformanceTest.java
Sun Mar 15 11:18:30 2009
@@ -62,13 +62,13 @@
     }
 
     private char html40value(int i) {
-        String entityValue = Entities.HTML40_ARRAY[i % Entities.HTML40_ARRAY.length][1];
+        String entityValue = Entities.getHTML40(i % Entities.HTML40_ARRAY_LENGTH, 1);
         char ch = (char) Integer.parseInt(entityValue);
         return ch;
     }
 
     private char isovalue(int i) {
-        String entityValue = Entities.ISO8859_1_ARRAY[i % Entities.ISO8859_1_ARRAY.length][1];
+        String entityValue = Entities.getISO8859_1(i % Entities.ISO8859_1_ARRAY_LENGTH, 1);
         char ch = (char) Integer.parseInt(entityValue);
         return ch;
     }



Mime
View raw message