diff --git a/src/main/java/org/apache/commons/lang3/Conversion.java b/src/main/java/org/apache/commons/lang3/Conversion.java index c282d3ac3..10f2daef5 100644 --- a/src/main/java/org/apache/commons/lang3/Conversion.java +++ b/src/main/java/org/apache/commons/lang3/Conversion.java @@ -582,9 +582,8 @@ public static long intArrayToLong(final int[] src, final int srcPos, final long 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 static long shortArrayToLong(final short[] src, final int srcPos, final l 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 static int shortArrayToInt(final short[] src, final int srcPos, final int 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 static long byteArrayToLong(final byte[] src, final int srcPos, final lon 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 static int byteArrayToInt(final byte[] src, final int srcPos, final int d 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 static short byteArrayToShort(final byte[] src, final int srcPos, final s 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 static long hexToLong(final String src, final int srcPos, final long dstI 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 static int hexToInt(final String src, final int srcPos, final int dstInit 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 static short hexToShort(final String src, final int srcPos, final short d 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 static byte hexToByte(final String src, final int srcPos, final byte dstI 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 static long binaryToLong(final boolean[] src, final int srcPos, final lon 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 static int binaryToInt(final boolean[] src, final int srcPos, final int d 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 static short binaryToShort(final boolean[] src, final int srcPos, final s 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 static byte binaryToByte(final boolean[] src, final int srcPos, final byt 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 static int[] longToIntArray(final long src, final int srcPos, final int[] 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 static short[] longToShortArray(final long src, final int srcPos, final s 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 static short[] intToShortArray(final int src, final int srcPos, final sho 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 static byte[] longToByteArray(final long src, final int srcPos, final byt 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 static byte[] intToByteArray(final int src, final int srcPos, final byte[ 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 static byte[] shortToByteArray(final short src, final int srcPos, final b 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 static String longToHex(final long src, final int srcPos, final String ds 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 static String intToHex(final int src, final int srcPos, final String dstI 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 static String shortToHex(final short src, final int srcPos, final String 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 static String byteToHex(final byte src, final int srcPos, final String ds 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 static boolean[] longToBinary(final long src, final int srcPos, final boo 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 static boolean[] intToBinary(final int src, final int srcPos, final boole 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 static boolean[] shortToBinary(final short src, final int srcPos, final b 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 static boolean[] byteToBinary(final byte src, final int srcPos, final boo 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;