commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1715439 - in /commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines: InetAddressValidator.java checkdigit/IBANCheckDigit.java checkdigit/ISINCheckDigit.java checkdigit/SedolCheckDigit.java
Date Fri, 20 Nov 2015 22:45:25 GMT
Author: sebb
Date: Fri Nov 20 22:45:24 2015
New Revision: 1715439

URL: http://svn.apache.org/viewvc?rev=1715439&view=rev
Log:
Magic numbers

Modified:
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigit.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigit.java
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/SedolCheckDigit.java

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java?rev=1715439&r1=1715438&r2=1715439&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
Fri Nov 20 22:45:24 2015
@@ -163,7 +163,7 @@ public class InetAddressValidator implem
                     if (!inet6Address.endsWith(octet)) {
                         return false;
                     }
-                    if (index > octets.length - 1 || index > 6) {
+                    if (index > octets.length - 1 || index > 6) { // TODO magic number
(sort of)
                         // IPV4 occupies last two octets
                         return false;
                     }

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigit.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigit.java?rev=1715439&r1=1715438&r2=1715439&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigit.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigit.java
Fri Nov 20 22:45:24 2015
@@ -46,6 +46,8 @@ public final class IBANCheckDigit implem
 
     private static final long serialVersionUID = -3600191725934382801L;
 
+    private static final int MAX_ALPHANUMERIC_VALUE = 35; // Character.getNumericValue('Z')
+
     /** Singleton IBAN Number Check Digit instance */
     public static final CheckDigit IBAN_CHECK_DIGIT = new IBANCheckDigit();
 
@@ -67,7 +69,7 @@ public final class IBANCheckDigit implem
      * <code>false</code>
      */
     public boolean isValid(String code) {
-        if (code == null || code.length() < 5) {
+        if (code == null || code.length() < MIN_CODE_LEN) {
             return false;
         }
         String check = code.substring(2,4); // CHECKSTYLE IGNORE MagicNumber
@@ -118,7 +120,7 @@ public final class IBANCheckDigit implem
         long total = 0;
         for (int i = 0; i < reformattedCode.length(); i++) {
             int charValue = Character.getNumericValue(reformattedCode.charAt(i));
-            if (charValue < 0 || charValue > 35) {
+            if (charValue < 0 || charValue > MAX_ALPHANUMERIC_VALUE) {
                 throw new CheckDigitException("Invalid Character[" +
                         i + "] = '" + charValue + "'");
             }

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigit.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigit.java?rev=1715439&r1=1715438&r2=1715439&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigit.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigit.java
Fri Nov 20 22:45:24 2015
@@ -43,6 +43,8 @@ public final class ISINCheckDigit extend
 
     private static final long serialVersionUID = -1239211208101323599L;
 
+    private static final int MAX_ALPHANUMERIC_VALUE = 35; // Character.getNumericValue('Z')
+
     /** Singleton ISIN Check Digit instance */
     public static final CheckDigit ISIN_CHECK_DIGIT = new ISINCheckDigit();
 
@@ -75,7 +77,7 @@ public final class ISINCheckDigit extend
         }
         for (int i = 0; i < code.length(); i++) {
             int charValue = Character.getNumericValue(code.charAt(i));
-            if (charValue < 0 || charValue > 35) {
+            if (charValue < 0 || charValue > MAX_ALPHANUMERIC_VALUE) {
                 throw new CheckDigitException("Invalid Character[" +
                         (i + 1) + "] = '" + charValue + "'");
             }

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/SedolCheckDigit.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/SedolCheckDigit.java?rev=1715439&r1=1715438&r2=1715439&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/SedolCheckDigit.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/SedolCheckDigit.java
Fri Nov 20 22:45:24 2015
@@ -43,6 +43,8 @@ public final class SedolCheckDigit exten
 
     private static final long serialVersionUID = -8976881621148878443L;
 
+    private static final int MAX_ALPHANUMERIC_VALUE = 35; // Character.getNumericValue('Z')
+
     /** Singleton SEDOL check digit instance */
     public static final CheckDigit SEDOL_CHECK_DIGIT = new SedolCheckDigit();
 
@@ -66,7 +68,7 @@ public final class SedolCheckDigit exten
      * for the specified code
      */
     protected int calculateModulus(String code, boolean includesCheckDigit) throws CheckDigitException
{
-        if (code.length() > 7) {
+        if (code.length() > POSITION_WEIGHT.length) {
             throw new CheckDigitException("Invalid Code Length = " + code.length());
         }
         return super.calculateModulus(code, includesCheckDigit);
@@ -98,7 +100,7 @@ public final class SedolCheckDigit exten
             throws CheckDigitException {
         int charValue = Character.getNumericValue(character);
         // the check digit is only allowed to reach 9
-        final int charMax = rightPos == 1 ? 9 : 35;
+        final int charMax = rightPos == 1 ? 9 : MAX_ALPHANUMERIC_VALUE; // CHECKSTYLE IGNORE
MagicNumber
         if (charValue < 0 || charValue > charMax) {
             throw new CheckDigitException("Invalid Character[" +
                     leftPos + "," + rightPos + "] = '" + charValue + "' out of range 0 to
" + charMax);



Mime
View raw message