← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5014: Tidied up use of constants

 

------------------------------------------------------------
revno: 5014
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: dhis2
timestamp: Sun 2011-10-23 21:18:55 +0100
message:
  Tidied up use of constants
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java	2011-10-23 13:33:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java	2011-10-23 20:18:55 +0000
@@ -37,7 +37,8 @@
     public static final String allowedChars = "0123456789" + "abcdefghijklmnopqrstuvwxyz"
         + "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
-    public static final int codeSize = 11;
+    public static final int NUMBER_OF_CODEPOINTS = allowedChars.length();
+    public static final int CODESIZE = 11;
 
     /**
      * Generates a pseudo random string using the allowed characters
@@ -49,10 +50,10 @@
         // Using the system default algorithm and seed
         SecureRandom sr = new SecureRandom();
 
-        char[] randomChars = new char[11];
-        for ( int i = 0; i < codeSize; ++i )
+        char[] randomChars = new char[CODESIZE];
+        for ( int i = 0; i < CODESIZE; ++i )
         {
-            randomChars[i] = allowedChars.charAt( sr.nextInt( 61 ) );
+            randomChars[i] = allowedChars.charAt( sr.nextInt( NUMBER_OF_CODEPOINTS ) );
         }
         return new String( randomChars );
     }