ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject svn commit: r578730 - in /ant/core/trunk/src/main/org/apache/tools/ant/util: Base64Converter.java DateUtils.java LeadPipeInputStream.java LineTokenizer.java ReaderInputStream.java StringTokenizer.java UUEncoder.java
Date Mon, 24 Sep 2007 09:40:27 GMT
Author: peterreilly
Date: Mon Sep 24 02:40:26 2007
New Revision: 578730

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

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/util/Base64Converter.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/DateUtils.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/LeadPipeInputStream.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/LineTokenizer.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/ReaderInputStream.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/StringTokenizer.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/UUEncoder.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/Base64Converter.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/Base64Converter.java?rev=578730&r1=578729&r2=578730&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/Base64Converter.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/Base64Converter.java Mon Sep 24 02:40:26
2007
@@ -25,11 +25,16 @@
  **/
 public class Base64Converter {
 
+    private static final int BYTE      = 8;
+    private static final int WORD      = 16;
     private static final int BYTE_MASK = 0xFF;
     private static final int POS_0_MASK = 0x0000003F;
     private static final int POS_1_MASK = 0x00000FC0;
+    private static final int POS_1_SHIFT = 6;
     private static final int POS_2_MASK = 0x0003F000;
+    private static final int POS_2_SHIFT = 12;
     private static final int POS_3_MASK = 0x00FC0000;
+    private static final int POS_3_SHIFT = 18;
 
 
     private static final char[] ALPHABET = {
@@ -66,44 +71,48 @@
         int bits24;
         int bits6;
 
+        // CheckStyle:MagicNumber OFF
         char[] out = new char[((octetString.length - 1) / 3 + 1) * 4];
+        // CheckStyle:MagicNumber ON
         int outIndex = 0;
         int i = 0;
 
+        // CheckStyle:MagicNumber OFF
         while ((i + 3) <= octetString.length) {
+        // CheckStyle:MagicNumber ON
             // store the octets
-            bits24 = (octetString[i++] & BYTE_MASK) << 16;
-            bits24 |= (octetString[i++] & BYTE_MASK) << 8;
+            bits24 = (octetString[i++] & BYTE_MASK) << WORD;
+            bits24 |= (octetString[i++] & BYTE_MASK) << BYTE;
             bits24 |= octetString[i++];
 
-            bits6 = (bits24 & POS_3_MASK) >> 18;
+            bits6 = (bits24 & POS_3_MASK) >> POS_3_SHIFT;
             out[outIndex++] = ALPHABET[bits6];
-            bits6 = (bits24 & POS_2_MASK) >> 12;
+            bits6 = (bits24 & POS_2_MASK) >> POS_2_SHIFT;
             out[outIndex++] = ALPHABET[bits6];
-            bits6  = (bits24 & POS_1_MASK) >> 6;
+            bits6  = (bits24 & POS_1_MASK) >> POS_1_SHIFT;
             out[outIndex++] = ALPHABET[bits6];
             bits6 = (bits24 & POS_0_MASK);
             out[outIndex++] = ALPHABET[bits6];
         }
         if (octetString.length - i == 2) {
             // store the octets
-            bits24 = (octetString[i] & BYTE_MASK) << 16;
-            bits24 |= (octetString[i + 1] & BYTE_MASK) << 8;
-            bits6 = (bits24 & POS_3_MASK) >> 18;
+            bits24 = (octetString[i] & BYTE_MASK) << WORD;
+            bits24 |= (octetString[i + 1] & BYTE_MASK) << BYTE;
+            bits6 = (bits24 & POS_3_MASK) >> POS_3_SHIFT;
             out[outIndex++] = ALPHABET[bits6];
-            bits6 = (bits24 & POS_2_MASK) >> 12;
+            bits6 = (bits24 & POS_2_MASK) >> POS_2_SHIFT;
             out[outIndex++] = ALPHABET[bits6];
-            bits6 = (bits24 & POS_1_MASK) >> 6;
+            bits6 = (bits24 & POS_1_MASK) >> POS_1_SHIFT;
             out[outIndex++] = ALPHABET[bits6];
 
             // padding
             out[outIndex++] = '=';
         } else if (octetString.length - i == 1) {
             // store the octets
-            bits24 = (octetString[i] & BYTE_MASK) << 16;
-            bits6 = (bits24 & POS_3_MASK) >> 18;
+            bits24 = (octetString[i] & BYTE_MASK) << WORD;
+            bits6 = (bits24 & POS_3_MASK) >> POS_3_SHIFT;
             out[outIndex++] = ALPHABET[bits6];
-            bits6 = (bits24 & POS_2_MASK) >> 12;
+            bits6 = (bits24 & POS_2_MASK) >> POS_2_SHIFT;
             out[outIndex++] = ALPHABET[bits6];
 
             // padding

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/DateUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/DateUtils.java?rev=578730&r1=578729&r2=578730&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/DateUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/DateUtils.java Mon Sep 24 02:40:26 2007
@@ -37,6 +37,10 @@
  */
 public final class DateUtils {
 
+    private static final int ONE_SECOND = 1000;
+    private static final int ONE_MINUTE = 60;
+    private static final int ONE_HOUR = 60;
+    private static final int TEN = 10;
     /**
      * ISO8601-like pattern for date-time. It does not support timezone.
      *  <tt>yyyy-MM-ddTHH:mm:ss</tt>
@@ -125,9 +129,9 @@
      * @return the formatted text in minutes/seconds.
      */
     public static String formatElapsedTime(long millis) {
-        long seconds = millis / 1000;
-        long minutes = seconds / 60;
-        Object[] args = {new Long(minutes), new Long(seconds % 60)};
+        long seconds = millis / ONE_SECOND;
+        long minutes = seconds / ONE_MINUTE;
+        Object[] args = {new Long(minutes), new Long(seconds % ONE_MINUTE)};
         return MINUTE_SECONDS.format(args);
     }
 
@@ -179,6 +183,7 @@
      * @since 1.2, Ant 1.5
      */
     public static int getPhaseOfMoon(Calendar cal) {
+        // CheckStyle:MagicNumber OFF
         int dayOfTheYear = cal.get(Calendar.DAY_OF_YEAR);
         int yearInMetonicCycle = ((cal.get(Calendar.YEAR) - 1900) % 19) + 1;
         int epact = (11 * yearInMetonicCycle + 18) % 30;
@@ -186,6 +191,7 @@
             epact++;
         }
         return (((((dayOfTheYear + epact) * 6) + 11) % 177) / 22) & 7;
+        // CheckStyle:MagicNumber ON
     }
 
     /**
@@ -205,13 +211,13 @@
                                   cal.get(Calendar.MILLISECOND));
         StringBuffer tzMarker = new StringBuffer(offset < 0 ? "-" : "+");
         offset = Math.abs(offset);
-        int hours = offset / (60 * 60 * 1000);
-        int minutes = offset / (60 * 1000) - 60 * hours;
-        if (hours < 10) {
+        int hours = offset / (ONE_HOUR * ONE_MINUTE * ONE_SECOND);
+        int minutes = offset / (ONE_MINUTE * ONE_SECOND) - ONE_HOUR * hours;
+        if (hours < TEN) {
             tzMarker.append("0");
         }
         tzMarker.append(hours);
-        if (minutes < 10) {
+        if (minutes < TEN) {
             tzMarker.append("0");
         }
         tzMarker.append(minutes);

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/LeadPipeInputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/LeadPipeInputStream.java?rev=578730&r1=578729&r2=578730&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/LeadPipeInputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/LeadPipeInputStream.java Mon Sep 24
02:40:26 2007
@@ -32,6 +32,7 @@
  * @since Ant 1.6.2
  */
 public class LeadPipeInputStream extends PipedInputStream {
+    private static final int BYTE_MASK = 0xFF;
     private ProjectComponent managingPc;
 
     /**
@@ -88,7 +89,7 @@
             if ("write end dead".equalsIgnoreCase(eyeOhEx.getMessage())) {
                 if (super.in > 0 && super.out < super.buffer.length
                     && super.out > super.in) {
-                    result = super.buffer[super.out++] & 0xFF;
+                    result = super.buffer[super.out++] & BYTE_MASK;
                 }
             } else {
                 log("error at LeadPipeInputStream.read():  "

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/LineTokenizer.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/LineTokenizer.java?rev=578730&r1=578729&r2=578730&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/LineTokenizer.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/LineTokenizer.java Mon Sep 24 02:40:26
2007
@@ -29,8 +29,9 @@
  */
 public class LineTokenizer extends ProjectComponent
     implements Tokenizer {
+    private static final int NOT_A_CHAR = -2;
     private String  lineEnd = "";
-    private int     pushed = -2;
+    private int     pushed = NOT_A_CHAR;
     private boolean includeDelims = false;
 
     /**
@@ -54,9 +55,9 @@
      */
     public String getToken(Reader in) throws IOException {
         int ch = -1;
-        if (pushed != -2) {
+        if (pushed != NOT_A_CHAR) {
             ch = pushed;
-            pushed = -2;
+            pushed = NOT_A_CHAR;
         } else {
             ch = in.read();
         }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/ReaderInputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/ReaderInputStream.java?rev=578730&r1=578729&r2=578730&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/ReaderInputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/ReaderInputStream.java Mon Sep 24 02:40:26
2007
@@ -27,6 +27,7 @@
  *
  */
 public class ReaderInputStream extends InputStream {
+    private static final int BYTE_MASK = 0xFF;
 
     /** Source Reader */
     private Reader in;
@@ -90,7 +91,7 @@
                 result = buf[0];
             }
         }
-        return result & 0xFF;
+        return result & BYTE_MASK;
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/StringTokenizer.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/StringTokenizer.java?rev=578730&r1=578729&r2=578730&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/StringTokenizer.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/StringTokenizer.java Mon Sep 24 02:40:26
2007
@@ -31,8 +31,9 @@
  * @since Ant 1.7
  */
 public class StringTokenizer extends ProjectComponent implements Tokenizer {
+    private static final int NOT_A_CHAR = -2;
     private String intraString = "";
-    private int    pushed = -2;
+    private int    pushed = NOT_A_CHAR;
     private char[] delims = null;
     private boolean delimsAreTokens = false;
     private boolean suppressDelims = false;
@@ -83,9 +84,9 @@
      */
     public String getToken(Reader in) throws IOException {
         int ch = -1;
-        if (pushed != -2) {
+        if (pushed != NOT_A_CHAR) {
             ch = pushed;
-            pushed = -2;
+            pushed = NOT_A_CHAR;
         } else {
             ch = in.read();
         }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/UUEncoder.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/UUEncoder.java?rev=578730&r1=578729&r2=578730&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/UUEncoder.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/UUEncoder.java Mon Sep 24 02:40:26 2007
@@ -126,10 +126,12 @@
                 }
             }
 
+            // CheckStyle:MagicNumber OFF
             byte d1 = (byte) (((a >>> 2) & 0x3F) + ' ');
             byte d2 = (byte) ((((a << 4) & 0x30) | ((b >>> 4) & 0x0F))
+ ' ');
             byte d3 = (byte) ((((b << 2) & 0x3C) | ((c >>> 6) & 0x3))
+ ' ');
             byte d4 = (byte) ((c & 0x3F) + ' ');
+            // CheckStyle:MagicNumber ON
 
             out.write(d1);
             out.write(d2);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message