Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3147817640 for ; Mon, 6 Apr 2015 19:21:52 +0000 (UTC) Received: (qmail 23392 invoked by uid 500); 6 Apr 2015 19:21:52 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 23322 invoked by uid 500); 6 Apr 2015 19:21:52 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 23313 invoked by uid 99); 6 Apr 2015 19:21:51 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Apr 2015 19:21:51 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id D7909AC0456 for ; Mon, 6 Apr 2015 19:21:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1671661 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/Conversion.java Date: Mon, 06 Apr 2015 19:21:51 -0000 To: commits@commons.apache.org From: britter@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150406192151.D7909AC0456@hades.apache.org> Author: britter Date: Mon Apr 6 19:21:51 2015 New Revision: 1671661 URL: http://svn.apache.org/r1671661 Log: Scope of local variabel shift can be narrower Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/Conversion.java Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/Conversion.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/Conversion.java?rev=1671661&r1=1671660&r2=1671661&view=diff ============================================================================== --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/Conversion.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/Conversion.java Mon Apr 6 19:21:51 2015 @@ -582,9 +582,8 @@ public class Conversion { throw new IllegalArgumentException("(nInts-1)*32+dstPos is greather or equal to than 64"); } long out = dstInit; - int shift = 0; for (int i = 0; i < nInts; i++) { - shift = i * 32 + dstPos; + final int shift = i * 32 + dstPos; final long bits = (0xffffffffL & src[i + srcPos]) << shift; final long mask = 0xffffffffL << shift; out = (out & ~mask) | bits; @@ -618,9 +617,8 @@ public class Conversion { throw new IllegalArgumentException("(nShorts-1)*16+dstPos is greather or equal to than 64"); } long out = dstInit; - int shift = 0; for (int i = 0; i < nShorts; i++) { - shift = i * 16 + dstPos; + final int shift = i * 16 + dstPos; final long bits = (0xffffL & src[i + srcPos]) << shift; final long mask = 0xffffL << shift; out = (out & ~mask) | bits; @@ -654,9 +652,8 @@ public class Conversion { throw new IllegalArgumentException("(nShorts-1)*16+dstPos is greather or equal to than 32"); } int out = dstInit; - int shift = 0; for (int i = 0; i < nShorts; i++) { - shift = i * 16 + dstPos; + final int shift = i * 16 + dstPos; final int bits = (0xffff & src[i + srcPos]) << shift; final int mask = 0xffff << shift; out = (out & ~mask) | bits; @@ -690,9 +687,8 @@ public class Conversion { throw new IllegalArgumentException("(nBytes-1)*8+dstPos is greather or equal to than 64"); } long out = dstInit; - int shift = 0; for (int i = 0; i < nBytes; i++) { - shift = i * 8 + dstPos; + final int shift = i * 8 + dstPos; final long bits = (0xffL & src[i + srcPos]) << shift; final long mask = 0xffL << shift; out = (out & ~mask) | bits; @@ -726,9 +722,8 @@ public class Conversion { throw new IllegalArgumentException("(nBytes-1)*8+dstPos is greather or equal to than 32"); } int out = dstInit; - int shift = 0; for (int i = 0; i < nBytes; i++) { - shift = i * 8 + dstPos; + final int shift = i * 8 + dstPos; final int bits = (0xff & src[i + srcPos]) << shift; final int mask = 0xff << shift; out = (out & ~mask) | bits; @@ -762,9 +757,8 @@ public class Conversion { throw new IllegalArgumentException("(nBytes-1)*8+dstPos is greather or equal to than 16"); } short out = dstInit; - int shift = 0; for (int i = 0; i < nBytes; i++) { - shift = i * 8 + dstPos; + final int shift = i * 8 + dstPos; final int bits = (0xff & src[i + srcPos]) << shift; final int mask = 0xff << shift; out = (short) ((out & ~mask) | bits); @@ -796,9 +790,8 @@ public class Conversion { throw new IllegalArgumentException("(nHexs-1)*4+dstPos is greather or equal to than 64"); } long out = dstInit; - int shift = 0; for (int i = 0; i < nHex; i++) { - shift = i * 4 + dstPos; + final int shift = i * 4 + dstPos; final long bits = (0xfL & hexDigitToInt(src.charAt(i + srcPos))) << shift; final long mask = 0xfL << shift; out = (out & ~mask) | bits; @@ -829,9 +822,8 @@ public class Conversion { throw new IllegalArgumentException("(nHexs-1)*4+dstPos is greather or equal to than 32"); } int out = dstInit; - int shift = 0; for (int i = 0; i < nHex; i++) { - shift = i * 4 + dstPos; + final int shift = i * 4 + dstPos; final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift; final int mask = 0xf << shift; out = (out & ~mask) | bits; @@ -863,9 +855,8 @@ public class Conversion { throw new IllegalArgumentException("(nHexs-1)*4+dstPos is greather or equal to than 16"); } short out = dstInit; - int shift = 0; for (int i = 0; i < nHex; i++) { - shift = i * 4 + dstPos; + final int shift = i * 4 + dstPos; final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift; final int mask = 0xf << shift; out = (short) ((out & ~mask) | bits); @@ -897,9 +888,8 @@ public class Conversion { throw new IllegalArgumentException("(nHexs-1)*4+dstPos is greather or equal to than 8"); } byte out = dstInit; - int shift = 0; for (int i = 0; i < nHex; i++) { - shift = i * 4 + dstPos; + final int shift = i * 4 + dstPos; final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift; final int mask = 0xf << shift; out = (byte) ((out & ~mask) | bits); @@ -933,9 +923,8 @@ public class Conversion { throw new IllegalArgumentException("nBools-1+dstPos is greather or equal to than 64"); } long out = dstInit; - int shift = 0; for (int i = 0; i < nBools; i++) { - shift = i + dstPos; + final int shift = i + dstPos; final long bits = (src[i + srcPos] ? 1L : 0) << shift; final long mask = 0x1L << shift; out = (out & ~mask) | bits; @@ -969,9 +958,8 @@ public class Conversion { throw new IllegalArgumentException("nBools-1+dstPos is greather or equal to than 32"); } int out = dstInit; - int shift = 0; for (int i = 0; i < nBools; i++) { - shift = i + dstPos; + final int shift = i + dstPos; final int bits = (src[i + srcPos] ? 1 : 0) << shift; final int mask = 0x1 << shift; out = (out & ~mask) | bits; @@ -1005,9 +993,8 @@ public class Conversion { throw new IllegalArgumentException("nBools-1+dstPos is greather or equal to than 16"); } short out = dstInit; - int shift = 0; for (int i = 0; i < nBools; i++) { - shift = i + dstPos; + final int shift = i + dstPos; final int bits = (src[i + srcPos] ? 1 : 0) << shift; final int mask = 0x1 << shift; out = (short) ((out & ~mask) | bits); @@ -1041,9 +1028,8 @@ public class Conversion { throw new IllegalArgumentException("nBools-1+dstPos is greather or equal to than 8"); } byte out = dstInit; - int shift = 0; for (int i = 0; i < nBools; i++) { - shift = i + dstPos; + final int shift = i + dstPos; final int bits = (src[i + srcPos] ? 1 : 0) << shift; final int mask = 0x1 << shift; out = (byte) ((out & ~mask) | bits); @@ -1076,9 +1062,8 @@ public class Conversion { if ((nInts - 1) * 32 + srcPos >= 64) { throw new IllegalArgumentException("(nInts-1)*32+srcPos is greather or equal to than 64"); } - int shift = 0; for (int i = 0; i < nInts; i++) { - shift = i * 32 + srcPos; + final int shift = i * 32 + srcPos; dst[dstPos + i] = (int) (0xffffffff & (src >> shift)); } return dst; @@ -1109,9 +1094,8 @@ public class Conversion { if ((nShorts - 1) * 16 + srcPos >= 64) { throw new IllegalArgumentException("(nShorts-1)*16+srcPos is greather or equal to than 64"); } - int shift = 0; for (int i = 0; i < nShorts; i++) { - shift = i * 16 + srcPos; + final int shift = i * 16 + srcPos; dst[dstPos + i] = (short) (0xffff & (src >> shift)); } return dst; @@ -1142,9 +1126,8 @@ public class Conversion { if ((nShorts - 1) * 16 + srcPos >= 32) { throw new IllegalArgumentException("(nShorts-1)*16+srcPos is greather or equal to than 32"); } - int shift = 0; for (int i = 0; i < nShorts; i++) { - shift = i * 16 + srcPos; + final int shift = i * 16 + srcPos; dst[dstPos + i] = (short) (0xffff & (src >> shift)); } return dst; @@ -1175,9 +1158,8 @@ public class Conversion { if ((nBytes - 1) * 8 + srcPos >= 64) { throw new IllegalArgumentException("(nBytes-1)*8+srcPos is greather or equal to than 64"); } - int shift = 0; for (int i = 0; i < nBytes; i++) { - shift = i * 8 + srcPos; + final int shift = i * 8 + srcPos; dst[dstPos + i] = (byte) (0xff & (src >> shift)); } return dst; @@ -1208,9 +1190,8 @@ public class Conversion { if ((nBytes - 1) * 8 + srcPos >= 32) { throw new IllegalArgumentException("(nBytes-1)*8+srcPos is greather or equal to than 32"); } - int shift = 0; for (int i = 0; i < nBytes; i++) { - shift = i * 8 + srcPos; + final int shift = i * 8 + srcPos; dst[dstPos + i] = (byte) (0xff & (src >> shift)); } return dst; @@ -1241,9 +1222,8 @@ public class Conversion { if ((nBytes - 1) * 8 + srcPos >= 16) { throw new IllegalArgumentException("(nBytes-1)*8+srcPos is greather or equal to than 16"); } - int shift = 0; for (int i = 0; i < nBytes; i++) { - shift = i * 8 + srcPos; + final int shift = i * 8 + srcPos; dst[dstPos + i] = (byte) (0xff & (src >> shift)); } return dst; @@ -1274,10 +1254,9 @@ public class Conversion { throw new IllegalArgumentException("(nHexs-1)*4+srcPos is greather or equal to than 64"); } final StringBuilder sb = new StringBuilder(dstInit); - int shift = 0; int append = sb.length(); for (int i = 0; i < nHexs; i++) { - shift = i * 4 + srcPos; + final int shift = i * 4 + srcPos; final int bits = (int) (0xF & (src >> shift)); if (dstPos + i == append) { ++append; @@ -1314,10 +1293,9 @@ public class Conversion { throw new IllegalArgumentException("(nHexs-1)*4+srcPos is greather or equal to than 32"); } final StringBuilder sb = new StringBuilder(dstInit); - int shift = 0; int append = sb.length(); for (int i = 0; i < nHexs; i++) { - shift = i * 4 + srcPos; + final int shift = i * 4 + srcPos; final int bits = 0xF & (src >> shift); if (dstPos + i == append) { ++append; @@ -1354,10 +1332,9 @@ public class Conversion { throw new IllegalArgumentException("(nHexs-1)*4+srcPos is greather or equal to than 16"); } final StringBuilder sb = new StringBuilder(dstInit); - int shift = 0; int append = sb.length(); for (int i = 0; i < nHexs; i++) { - shift = i * 4 + srcPos; + final int shift = i * 4 + srcPos; final int bits = 0xF & (src >> shift); if (dstPos + i == append) { ++append; @@ -1394,10 +1371,9 @@ public class Conversion { throw new IllegalArgumentException("(nHexs-1)*4+srcPos is greather or equal to than 8"); } final StringBuilder sb = new StringBuilder(dstInit); - int shift = 0; int append = sb.length(); for (int i = 0; i < nHexs; i++) { - shift = i * 4 + srcPos; + final int shift = i * 4 + srcPos; final int bits = 0xF & (src >> shift); if (dstPos + i == append) { ++append; @@ -1434,9 +1410,8 @@ public class Conversion { if (nBools - 1 + srcPos >= 64) { throw new IllegalArgumentException("nBools-1+srcPos is greather or equal to than 64"); } - int shift = 0; for (int i = 0; i < nBools; i++) { - shift = i + srcPos; + final int shift = i + srcPos; dst[dstPos + i] = (0x1 & (src >> shift)) != 0; } return dst; @@ -1467,9 +1442,8 @@ public class Conversion { if (nBools - 1 + srcPos >= 32) { throw new IllegalArgumentException("nBools-1+srcPos is greather or equal to than 32"); } - int shift = 0; for (int i = 0; i < nBools; i++) { - shift = i + srcPos; + final int shift = i + srcPos; dst[dstPos + i] = (0x1 & (src >> shift)) != 0; } return dst; @@ -1500,10 +1474,9 @@ public class Conversion { if (nBools - 1 + srcPos >= 16) { throw new IllegalArgumentException("nBools-1+srcPos is greather or equal to than 16"); } - int shift = 0; assert (nBools - 1) < 16 - srcPos; for (int i = 0; i < nBools; i++) { - shift = i + srcPos; + final int shift = i + srcPos; dst[dstPos + i] = (0x1 & (src >> shift)) != 0; } return dst; @@ -1534,9 +1507,8 @@ public class Conversion { if (nBools - 1 + srcPos >= 8) { throw new IllegalArgumentException("nBools-1+srcPos is greather or equal to than 8"); } - int shift = 0; for (int i = 0; i < nBools; i++) { - shift = i + srcPos; + final int shift = i + srcPos; dst[dstPos + i] = (0x1 & (src >> shift)) != 0; } return dst;