Format to 120 line length.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1606081 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2014-06-27 13:03:13 +00:00
parent cf832560dd
commit 7b33ab10de
1 changed files with 109 additions and 130 deletions

View File

@ -156,9 +156,7 @@ public class Conversion {
case 'F':
return 0xF;
default:
throw new IllegalArgumentException("Cannot interpret '"
+ hexDigit
+ "' as a hexadecimal digit");
throw new IllegalArgumentException("Cannot interpret '" + hexDigit + "' as a hexadecimal digit");
}
}
@ -216,9 +214,7 @@ public class Conversion {
case 'F':
return TTTT;
default:
throw new IllegalArgumentException("Cannot interpret '"
+ hexDigit
+ "' as a hexadecimal digit");
throw new IllegalArgumentException("Cannot interpret '" + hexDigit + "' as a hexadecimal digit");
}
}
@ -276,9 +272,7 @@ public class Conversion {
case 'F':
return TTTT;
default:
throw new IllegalArgumentException("Cannot interpret '"
+ hexDigit
+ "' as a hexadecimal digit");
throw new IllegalArgumentException("Cannot interpret '" + hexDigit + "' as a hexadecimal digit");
}
}
@ -579,17 +573,17 @@ public class Conversion {
* @throws NullPointerException if {@code src} is {@code null}
* @throws ArrayIndexOutOfBoundsException if {@code srcPos + nInts > src.length}
*/
public static long intArrayToLong(final int[] src, final int srcPos, final long dstInit, final int dstPos, final int nInts) {
public static long intArrayToLong(final int[] src, final int srcPos, final long dstInit, final int dstPos,
final int nInts) {
if ((src.length == 0 && srcPos == 0) || 0 == nInts) {
return dstInit;
}
if ((nInts - 1) * 32 + dstPos >= 64) {
throw new IllegalArgumentException(
"(nInts-1)*32+dstPos is greather or equal to than 64");
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++ ) {
for (int i = 0; i < nInts; i++) {
shift = i * 32 + dstPos;
final long bits = ((0xffffffffL & src[i + srcPos]) << shift);
final long mask = 0xffffffffL << shift;
@ -621,12 +615,11 @@ public class Conversion {
return dstInit;
}
if ((nShorts - 1) * 16 + dstPos >= 64) {
throw new IllegalArgumentException(
"(nShorts-1)*16+dstPos is greather or equal to than 64");
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++ ) {
for (int i = 0; i < nShorts; i++) {
shift = i * 16 + dstPos;
final long bits = (0xffffL & src[i + srcPos]) << shift;
final long mask = 0xffffL << shift;
@ -658,12 +651,11 @@ public class Conversion {
return dstInit;
}
if ((nShorts - 1) * 16 + dstPos >= 32) {
throw new IllegalArgumentException(
"(nShorts-1)*16+dstPos is greather or equal to than 32");
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++ ) {
for (int i = 0; i < nShorts; i++) {
shift = i * 16 + dstPos;
final int bits = (0xffff & src[i + srcPos]) << shift;
final int mask = 0xffff << shift;
@ -695,12 +687,11 @@ public class Conversion {
return dstInit;
}
if ((nBytes - 1) * 8 + dstPos >= 64) {
throw new IllegalArgumentException(
"(nBytes-1)*8+dstPos is greather or equal to than 64");
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++ ) {
for (int i = 0; i < nBytes; i++) {
shift = i * 8 + dstPos;
final long bits = (0xffL & src[i + srcPos]) << shift;
final long mask = 0xffL << shift;
@ -726,17 +717,17 @@ public class Conversion {
* @throws IllegalArgumentException if {@code (nBytes-1)*8+dstPos >= 32}
* @throws ArrayIndexOutOfBoundsException if {@code srcPos + nBytes > src.length}
*/
public static int byteArrayToInt(final byte[] src, final int srcPos, final int dstInit, final int dstPos, final int nBytes) {
public static int byteArrayToInt(final byte[] src, final int srcPos, final int dstInit, final int dstPos,
final int nBytes) {
if ((src.length == 0 && srcPos == 0) || 0 == nBytes) {
return dstInit;
}
if ((nBytes - 1) * 8 + dstPos >= 32) {
throw new IllegalArgumentException(
"(nBytes-1)*8+dstPos is greather or equal to than 32");
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++ ) {
for (int i = 0; i < nBytes; i++) {
shift = i * 8 + dstPos;
final int bits = (0xff & src[i + srcPos]) << shift;
final int mask = 0xff << shift;
@ -768,16 +759,15 @@ public class Conversion {
return dstInit;
}
if ((nBytes - 1) * 8 + dstPos >= 16) {
throw new IllegalArgumentException(
"(nBytes-1)*8+dstPos is greather or equal to than 16");
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++ ) {
for (int i = 0; i < nBytes; i++) {
shift = i * 8 + dstPos;
final int bits = (0xff & src[i + srcPos]) << shift;
final int mask = 0xff << shift;
out = (short)((out & ~mask) | bits);
out = (short) ((out & ~mask) | bits);
}
return out;
}
@ -797,17 +787,17 @@ public class Conversion {
* @return a long containing the selected bits
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 64}
*/
public static long hexToLong(final String src, final int srcPos, final long dstInit, final int dstPos, final int nHex) {
public static long hexToLong(final String src, final int srcPos, final long dstInit, final int dstPos,
final int nHex) {
if (0 == nHex) {
return dstInit;
}
if ((nHex - 1) * 4 + dstPos >= 64) {
throw new IllegalArgumentException(
"(nHexs-1)*4+dstPos is greather or equal to than 64");
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++ ) {
for (int i = 0; i < nHex; i++) {
shift = i * 4 + dstPos;
final long bits = (0xfL & hexDigitToInt(src.charAt(i + srcPos))) << shift;
final long mask = 0xfL << shift;
@ -836,12 +826,11 @@ public class Conversion {
return dstInit;
}
if ((nHex - 1) * 4 + dstPos >= 32) {
throw new IllegalArgumentException(
"(nHexs-1)*4+dstPos is greather or equal to than 32");
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++ ) {
for (int i = 0; i < nHex; i++) {
shift = i * 4 + dstPos;
final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
final int mask = 0xf << shift;
@ -865,21 +854,21 @@ public class Conversion {
* @return a short containing the selected bits
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 16}
*/
public static short hexToShort(final String src, final int srcPos, final short dstInit, final int dstPos, final int nHex) {
public static short hexToShort(final String src, final int srcPos, final short dstInit, final int dstPos,
final int nHex) {
if (0 == nHex) {
return dstInit;
}
if ((nHex - 1) * 4 + dstPos >= 16) {
throw new IllegalArgumentException(
"(nHexs-1)*4+dstPos is greather or equal to than 16");
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++ ) {
for (int i = 0; i < nHex; i++) {
shift = i * 4 + dstPos;
final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
final int mask = 0xf << shift;
out = (short)((out & ~mask) | bits);
out = (short) ((out & ~mask) | bits);
}
return out;
}
@ -899,21 +888,21 @@ public class Conversion {
* @return a byte containing the selected bits
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 8}
*/
public static byte hexToByte(final String src, final int srcPos, final byte dstInit, final int dstPos, final int nHex) {
public static byte hexToByte(final String src, final int srcPos, final byte dstInit, final int dstPos,
final int nHex) {
if (0 == nHex) {
return dstInit;
}
if ((nHex - 1) * 4 + dstPos >= 8) {
throw new IllegalArgumentException(
"(nHexs-1)*4+dstPos is greather or equal to than 8");
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++ ) {
for (int i = 0; i < nHex; i++) {
shift = i * 4 + dstPos;
final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
final int mask = 0xf << shift;
out = (byte)((out & ~mask) | bits);
out = (byte) ((out & ~mask) | bits);
}
return out;
}
@ -941,12 +930,11 @@ public class Conversion {
return dstInit;
}
if (nBools - 1 + dstPos >= 64) {
throw new IllegalArgumentException(
"nBools-1+dstPos is greather or equal to than 64");
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++ ) {
for (int i = 0; i < nBools; i++) {
shift = i + dstPos;
final long bits = (src[i + srcPos] ? 1L : 0) << shift;
final long mask = 0x1L << shift;
@ -972,17 +960,17 @@ public class Conversion {
* @throws IllegalArgumentException if {@code nBools-1+dstPos >= 32}
* @throws ArrayIndexOutOfBoundsException if {@code srcPos + nBools > src.length}
*/
public static int binaryToInt(final boolean[] src, final int srcPos, final int dstInit, final int dstPos, final int nBools) {
public static int binaryToInt(final boolean[] src, final int srcPos, final int dstInit, final int dstPos,
final int nBools) {
if ((src.length == 0 && srcPos == 0) || 0 == nBools) {
return dstInit;
}
if (nBools - 1 + dstPos >= 32) {
throw new IllegalArgumentException(
"nBools-1+dstPos is greather or equal to than 32");
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++ ) {
for (int i = 0; i < nBools; i++) {
shift = i + dstPos;
final int bits = (src[i + srcPos] ? 1 : 0) << shift;
final int mask = 0x1 << shift;
@ -1014,16 +1002,15 @@ public class Conversion {
return dstInit;
}
if (nBools - 1 + dstPos >= 16) {
throw new IllegalArgumentException(
"nBools-1+dstPos is greather or equal to than 16");
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++ ) {
for (int i = 0; i < nBools; i++) {
shift = i + dstPos;
final int bits = (src[i + srcPos] ? 1 : 0) << shift;
final int mask = 0x1 << shift;
out = (short)((out & ~mask) | bits);
out = (short) ((out & ~mask) | bits);
}
return out;
}
@ -1055,11 +1042,11 @@ public class Conversion {
}
byte out = dstInit;
int shift = 0;
for (int i = 0; i < nBools; i++ ) {
for (int i = 0; i < nBools; i++) {
shift = i + dstPos;
final int bits = (src[i + srcPos] ? 1 : 0) << shift;
final int mask = 0x1 << shift;
out = (byte)((out & ~mask) | bits);
out = (byte) ((out & ~mask) | bits);
}
return out;
}
@ -1081,18 +1068,18 @@ public class Conversion {
* @throws IllegalArgumentException if {@code (nInts-1)*32+srcPos >= 64}
* @throws ArrayIndexOutOfBoundsException if {@code dstPos + nInts > dst.length}
*/
public static int[] longToIntArray(final long src, final int srcPos, final int[] dst, final int dstPos, final int nInts) {
public static int[] longToIntArray(final long src, final int srcPos, final int[] dst, final int dstPos,
final int nInts) {
if (0 == nInts) {
return dst;
}
if ((nInts - 1) * 32 + srcPos >= 64) {
throw new IllegalArgumentException(
"(nInts-1)*32+srcPos is greather or equal to than 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++ ) {
for (int i = 0; i < nInts; i++) {
shift = i * 32 + srcPos;
dst[dstPos + i] = (int)(0xffffffff & (src >> shift));
dst[dstPos + i] = (int) (0xffffffff & (src >> shift));
}
return dst;
}
@ -1120,13 +1107,12 @@ public class Conversion {
return dst;
}
if ((nShorts - 1) * 16 + srcPos >= 64) {
throw new IllegalArgumentException(
"(nShorts-1)*16+srcPos is greather or equal to than 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++ ) {
for (int i = 0; i < nShorts; i++) {
shift = i * 16 + srcPos;
dst[dstPos + i] = (short)(0xffff & (src >> shift));
dst[dstPos + i] = (short) (0xffff & (src >> shift));
}
return dst;
}
@ -1154,13 +1140,12 @@ public class Conversion {
return dst;
}
if ((nShorts - 1) * 16 + srcPos >= 32) {
throw new IllegalArgumentException(
"(nShorts-1)*16+srcPos is greather or equal to than 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++ ) {
for (int i = 0; i < nShorts; i++) {
shift = i * 16 + srcPos;
dst[dstPos + i] = (short)(0xffff & (src >> shift));
dst[dstPos + i] = (short) (0xffff & (src >> shift));
}
return dst;
}
@ -1188,13 +1173,12 @@ public class Conversion {
return dst;
}
if ((nBytes - 1) * 8 + srcPos >= 64) {
throw new IllegalArgumentException(
"(nBytes-1)*8+srcPos is greather or equal to than 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++ ) {
for (int i = 0; i < nBytes; i++) {
shift = i * 8 + srcPos;
dst[dstPos + i] = (byte)(0xff & (src >> shift));
dst[dstPos + i] = (byte) (0xff & (src >> shift));
}
return dst;
}
@ -1216,18 +1200,18 @@ public class Conversion {
* @throws IllegalArgumentException if {@code (nBytes-1)*8+srcPos >= 32}
* @throws ArrayIndexOutOfBoundsException if {@code dstPos + nBytes > dst.length}
*/
public static byte[] intToByteArray(final int src, final int srcPos, final byte[] dst, final int dstPos, final int nBytes) {
public static byte[] intToByteArray(final int src, final int srcPos, final byte[] dst, final int dstPos,
final int nBytes) {
if (0 == nBytes) {
return dst;
}
if ((nBytes - 1) * 8 + srcPos >= 32) {
throw new IllegalArgumentException(
"(nBytes-1)*8+srcPos is greather or equal to than 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++ ) {
for (int i = 0; i < nBytes; i++) {
shift = i * 8 + srcPos;
dst[dstPos + i] = (byte)(0xff & (src >> shift));
dst[dstPos + i] = (byte) (0xff & (src >> shift));
}
return dst;
}
@ -1255,13 +1239,12 @@ public class Conversion {
return dst;
}
if ((nBytes - 1) * 8 + srcPos >= 16) {
throw new IllegalArgumentException(
"(nBytes-1)*8+srcPos is greather or equal to than 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++ ) {
for (int i = 0; i < nBytes; i++) {
shift = i * 8 + srcPos;
dst[dstPos + i] = (byte)(0xff & (src >> shift));
dst[dstPos + i] = (byte) (0xff & (src >> shift));
}
return dst;
}
@ -1282,20 +1265,20 @@ public class Conversion {
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 64}
* @throws StringIndexOutOfBoundsException if {@code dst.init.length() < dstPos}
*/
public static String longToHex(final long src, final int srcPos, final String dstInit, final int dstPos, final int nHexs) {
public static String longToHex(final long src, final int srcPos, final String dstInit, final int dstPos,
final int nHexs) {
if (0 == nHexs) {
return dstInit;
}
if ((nHexs - 1) * 4 + srcPos >= 64) {
throw new IllegalArgumentException(
"(nHexs-1)*4+srcPos is greather or equal to than 64");
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++ ) {
for (int i = 0; i < nHexs; i++) {
shift = i * 4 + srcPos;
final int bits = (int)(0xF & (src >> shift));
final int bits = (int) (0xF & (src >> shift));
if (dstPos + i == append) {
++append;
sb.append(intToHexDigit(bits));
@ -1322,18 +1305,18 @@ public class Conversion {
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 32}
* @throws StringIndexOutOfBoundsException if {@code dst.init.length() < dstPos}
*/
public static String intToHex(final int src, final int srcPos, final String dstInit, final int dstPos, final int nHexs) {
public static String intToHex(final int src, final int srcPos, final String dstInit, final int dstPos,
final int nHexs) {
if (0 == nHexs) {
return dstInit;
}
if ((nHexs - 1) * 4 + srcPos >= 32) {
throw new IllegalArgumentException(
"(nHexs-1)*4+srcPos is greather or equal to than 32");
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++ ) {
for (int i = 0; i < nHexs; i++) {
shift = i * 4 + srcPos;
final int bits = 0xF & (src >> shift);
if (dstPos + i == append) {
@ -1362,18 +1345,18 @@ public class Conversion {
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 16}
* @throws StringIndexOutOfBoundsException if {@code dst.init.length() < dstPos}
*/
public static String shortToHex(final short src, final int srcPos, final String dstInit, final int dstPos, final int nHexs) {
public static String shortToHex(final short src, final int srcPos, final String dstInit, final int dstPos,
final int nHexs) {
if (0 == nHexs) {
return dstInit;
}
if ((nHexs - 1) * 4 + srcPos >= 16) {
throw new IllegalArgumentException(
"(nHexs-1)*4+srcPos is greather or equal to than 16");
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++ ) {
for (int i = 0; i < nHexs; i++) {
shift = i * 4 + srcPos;
final int bits = 0xF & (src >> shift);
if (dstPos + i == append) {
@ -1402,18 +1385,18 @@ public class Conversion {
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 8}
* @throws StringIndexOutOfBoundsException if {@code dst.init.length() < dstPos}
*/
public static String byteToHex(final byte src, final int srcPos, final String dstInit, final int dstPos, final int nHexs) {
public static String byteToHex(final byte src, final int srcPos, final String dstInit, final int dstPos,
final int nHexs) {
if (0 == nHexs) {
return dstInit;
}
if ((nHexs - 1) * 4 + srcPos >= 8) {
throw new IllegalArgumentException(
"(nHexs-1)*4+srcPos is greather or equal to than 8");
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++ ) {
for (int i = 0; i < nHexs; i++) {
shift = i * 4 + srcPos;
final int bits = 0xF & (src >> shift);
if (dstPos + i == append) {
@ -1449,11 +1432,10 @@ public class Conversion {
return dst;
}
if (nBools - 1 + srcPos >= 64) {
throw new IllegalArgumentException(
"nBools-1+srcPos is greather or equal to than 64");
throw new IllegalArgumentException("nBools-1+srcPos is greather or equal to than 64");
}
int shift = 0;
for (int i = 0; i < nBools; i++ ) {
for (int i = 0; i < nBools; i++) {
shift = i + srcPos;
dst[dstPos + i] = ((0x1 & (src >> shift)) != 0);
}
@ -1483,11 +1465,10 @@ public class Conversion {
return dst;
}
if (nBools - 1 + srcPos >= 32) {
throw new IllegalArgumentException(
"nBools-1+srcPos is greather or equal to than 32");
throw new IllegalArgumentException("nBools-1+srcPos is greather or equal to than 32");
}
int shift = 0;
for (int i = 0; i < nBools; i++ ) {
for (int i = 0; i < nBools; i++) {
shift = i + srcPos;
dst[dstPos + i] = ((0x1 & (src >> shift)) != 0);
}
@ -1517,12 +1498,11 @@ public class Conversion {
return dst;
}
if (nBools - 1 + srcPos >= 16) {
throw new IllegalArgumentException(
"nBools-1+srcPos is greather or equal to than 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++ ) {
for (int i = 0; i < nBools; i++) {
shift = i + srcPos;
dst[dstPos + i] = ((0x1 & (src >> shift)) != 0);
}
@ -1555,7 +1535,7 @@ public class Conversion {
throw new IllegalArgumentException("nBools-1+srcPos is greather or equal to than 8");
}
int shift = 0;
for (int i = 0; i < nBools; i++ ) {
for (int i = 0; i < nBools; i++) {
shift = i + srcPos;
dst[dstPos + i] = ((0x1 & (src >> shift)) != 0);
}
@ -1609,7 +1589,6 @@ public class Conversion {
if (src.length - srcPos < 16) {
throw new IllegalArgumentException("Need at least 16 bytes for UUID");
}
return new UUID(byteArrayToLong(src, srcPos, 0, 0, 8), byteArrayToLong(
src, srcPos + 8, 0, 0, 8));
return new UUID(byteArrayToLong(src, srcPos, 0, 0, 8), byteArrayToLong(src, srcPos + 8, 0, 0, 8));
}
}