Code clean-up for CheckStyle.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1393626 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
28476afb7d
commit
ca9cbf976e
|
@ -20,6 +20,7 @@ package org.apache.commons.lang3;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Static methods to convert a type into another, with endianness and bit ordering awareness.
|
* Static methods to convert a type into another, with endianness and bit ordering awareness.
|
||||||
|
@ -267,7 +268,7 @@ public class Conversion {
|
||||||
* @param src the boolean array to convert
|
* @param src the boolean array to convert
|
||||||
* @return a hexadecimal digit representing the selected bits
|
* @return a hexadecimal digit representing the selected bits
|
||||||
* @throws IllegalArgumentException if {@code src} is empty
|
* @throws IllegalArgumentException if {@code src} is empty
|
||||||
* @throws NullPointerException if {@code src} is {@code null}
|
* @throws NullPointerException if {@code src} is {@code null}
|
||||||
*/
|
*/
|
||||||
public static char boolsToHexDigit(boolean[] src) {
|
public static char boolsToHexDigit(boolean[] src) {
|
||||||
return boolsToHexDigit(src, 0);
|
return boolsToHexDigit(src, 0);
|
||||||
|
@ -285,45 +286,70 @@ public class Conversion {
|
||||||
* @param srcPos the position of the lsb to start the conversion
|
* @param srcPos the position of the lsb to start the conversion
|
||||||
* @return a hexadecimal digit representing the selected bits
|
* @return a hexadecimal digit representing the selected bits
|
||||||
* @throws IllegalArgumentException if {@code src} is empty
|
* @throws IllegalArgumentException if {@code src} is empty
|
||||||
* @throws NullPointerException if {@code src} is {@code null}
|
* @throws NullPointerException if {@code src} is {@code null}
|
||||||
*/
|
*/
|
||||||
public static char boolsToHexDigit(boolean[] src, int srcPos) {
|
public static char boolsToHexDigit(boolean[] src, int srcPos) {
|
||||||
if (src.length == 0)
|
if (src.length == 0) {
|
||||||
throw new IllegalArgumentException("Cannot convert empty array.");
|
throw new IllegalArgumentException("Cannot convert empty array.");
|
||||||
|
}
|
||||||
if (src.length > srcPos + 3 && src[srcPos + 3]) {
|
if (src.length > srcPos + 3 && src[srcPos + 3]) {
|
||||||
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
||||||
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
||||||
if (src[srcPos]) return 'f';
|
if (src[srcPos]) {
|
||||||
else return 'e';
|
return 'f';
|
||||||
|
} else {
|
||||||
|
return 'e';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src[srcPos]) return 'd';
|
if (src[srcPos]) {
|
||||||
else return 'c';
|
return 'd';
|
||||||
|
} else {
|
||||||
|
return 'c';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
||||||
if (src[srcPos]) return 'b';
|
if (src[srcPos]) {
|
||||||
else return 'a';
|
return 'b';
|
||||||
|
} else {
|
||||||
|
return 'a';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src[srcPos]) return '9';
|
if (src[srcPos]) {
|
||||||
else return '8';
|
return '9';
|
||||||
|
} else {
|
||||||
|
return '8';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
||||||
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
||||||
if (src[srcPos]) return '7';
|
if (src[srcPos]) {
|
||||||
else return '6';
|
return '7';
|
||||||
|
} else {
|
||||||
|
return '6';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src[srcPos]) return '5';
|
if (src[srcPos]) {
|
||||||
else return '4';
|
return '5';
|
||||||
|
} else {
|
||||||
|
return '4';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
||||||
if (src[srcPos]) return '3';
|
if (src[srcPos]) {
|
||||||
else return '2';
|
return '3';
|
||||||
|
} else {
|
||||||
|
return '2';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src[srcPos]) return '1';
|
if (src[srcPos]) {
|
||||||
else return '0';
|
return '1';
|
||||||
|
} else {
|
||||||
|
return '0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,8 +365,9 @@ public class Conversion {
|
||||||
*
|
*
|
||||||
* @param src the boolean array to convert
|
* @param src the boolean array to convert
|
||||||
* @return a hexadecimal digit representing the selected bits
|
* @return a hexadecimal digit representing the selected bits
|
||||||
* @throws IllegalArgumentException if {@code src} is empty, {@code src.length < 4} or {@code src.length > 8}
|
* @throws IllegalArgumentException if {@code src} is empty, {@code src.length < 4} or
|
||||||
* @throws NullPointerException if {@code src} is {@code null}
|
* {@code src.length > 8}
|
||||||
|
* @throws NullPointerException if {@code src} is {@code null}
|
||||||
*/
|
*/
|
||||||
public static char boolsToHexDigitM0_4bits(boolean[] src) {
|
public static char boolsToHexDigitM0_4bits(boolean[] src) {
|
||||||
return boolsToHexDigitM0_4bits(src, 0);
|
return boolsToHexDigitM0_4bits(src, 0);
|
||||||
|
@ -358,51 +385,78 @@ public class Conversion {
|
||||||
* @param src the boolean array to convert
|
* @param src the boolean array to convert
|
||||||
* @param srcPos the position of the lsb to start the conversion
|
* @param srcPos the position of the lsb to start the conversion
|
||||||
* @return a hexadecimal digit representing the selected bits
|
* @return a hexadecimal digit representing the selected bits
|
||||||
* @throws IllegalArgumentException if {@code src} is empty, {@code src.length > 8} or {@code src.length - srcPos < 4}
|
* @throws IllegalArgumentException if {@code src} is empty, {@code src.length > 8} or
|
||||||
* @throws NullPointerException if {@code src} is {@code null}
|
* {@code src.length - srcPos < 4}
|
||||||
|
* @throws NullPointerException if {@code src} is {@code null}
|
||||||
*/
|
*/
|
||||||
public static char boolsToHexDigitM0_4bits(boolean[] src, int srcPos) {
|
public static char boolsToHexDigitM0_4bits(boolean[] src, int srcPos) {
|
||||||
if (src.length > 8)
|
if (src.length > 8) {
|
||||||
throw new IllegalArgumentException("src.length>8: src.length=" + src.length);
|
throw new IllegalArgumentException("src.length>8: src.length=" + src.length);
|
||||||
if (src.length - srcPos < 4)
|
}
|
||||||
|
if (src.length - srcPos < 4) {
|
||||||
throw new IllegalArgumentException("src.length-srcPos<4: src.length="
|
throw new IllegalArgumentException("src.length-srcPos<4: src.length="
|
||||||
+ src.length
|
+ src.length
|
||||||
+ ", srcPos="
|
+ ", srcPos="
|
||||||
+ srcPos);
|
+ srcPos);
|
||||||
|
}
|
||||||
if (src[srcPos + 3]) {
|
if (src[srcPos + 3]) {
|
||||||
if (src[srcPos + 2]) {
|
if (src[srcPos + 2]) {
|
||||||
if (src[srcPos + 1]) {
|
if (src[srcPos + 1]) {
|
||||||
if (src[srcPos]) return 'f';
|
if (src[srcPos]) {
|
||||||
else return '7';
|
return 'f';
|
||||||
|
} else {
|
||||||
|
return '7';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src[srcPos]) return 'b';
|
if (src[srcPos]) {
|
||||||
else return '3';
|
return 'b';
|
||||||
|
} else {
|
||||||
|
return '3';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src[srcPos + 1]) {
|
if (src[srcPos + 1]) {
|
||||||
if (src[srcPos]) return 'd';
|
if (src[srcPos]) {
|
||||||
else return '5';
|
return 'd';
|
||||||
|
} else {
|
||||||
|
return '5';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src[srcPos]) return '9';
|
if (src[srcPos]) {
|
||||||
else return '1';
|
return '9';
|
||||||
|
} else {
|
||||||
|
return '1';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src[srcPos + 2]) {
|
if (src[srcPos + 2]) {
|
||||||
if (src[srcPos + 1]) {
|
if (src[srcPos + 1]) {
|
||||||
if (src[srcPos]) return 'e';
|
if (src[srcPos]) {
|
||||||
else return '6';
|
return 'e';
|
||||||
|
} else {
|
||||||
|
return '6';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src[srcPos]) return 'a';
|
if (src[srcPos]) {
|
||||||
else return '2';
|
return 'a';
|
||||||
|
} else {
|
||||||
|
return '2';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src[srcPos + 1]) {
|
if (src[srcPos + 1]) {
|
||||||
if (src[srcPos]) return 'c';
|
if (src[srcPos]) {
|
||||||
else return '4';
|
return 'c';
|
||||||
|
} else {
|
||||||
|
return '4';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src[srcPos]) return '8';
|
if (src[srcPos]) {
|
||||||
else return '0';
|
return '8';
|
||||||
|
} else {
|
||||||
|
return '0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -421,7 +475,7 @@ public class Conversion {
|
||||||
* @param src the boolean array to convert
|
* @param src the boolean array to convert
|
||||||
* @return a hexadecimal digit representing the selected bits
|
* @return a hexadecimal digit representing the selected bits
|
||||||
* @throws IllegalArgumentException if {@code src} is empty
|
* @throws IllegalArgumentException if {@code src} is empty
|
||||||
* @throws NullPointerException if {@code src} is {@code null}
|
* @throws NullPointerException if {@code src} is {@code null}
|
||||||
*/
|
*/
|
||||||
public static char boolsBeM0ToHexDigit(boolean[] src) {
|
public static char boolsBeM0ToHexDigit(boolean[] src) {
|
||||||
return boolsBeM0ToHexDigit(src, 0);
|
return boolsBeM0ToHexDigit(src, 0);
|
||||||
|
@ -441,11 +495,12 @@ public class Conversion {
|
||||||
* @param srcPos the position of the lsb to start the conversion
|
* @param srcPos the position of the lsb to start the conversion
|
||||||
* @return a hexadecimal digit representing the selected bits
|
* @return a hexadecimal digit representing the selected bits
|
||||||
* @throws IllegalArgumentException if {@code src} is empty
|
* @throws IllegalArgumentException if {@code src} is empty
|
||||||
* @throws NullPointerException if {@code src} is {@code null}
|
* @throws NullPointerException if {@code src} is {@code null}
|
||||||
*/
|
*/
|
||||||
public static char boolsBeM0ToHexDigit(boolean[] src, int srcPos) {
|
public static char boolsBeM0ToHexDigit(boolean[] src, int srcPos) {
|
||||||
if (src.length == 0)
|
if (src.length == 0) {
|
||||||
throw new IllegalArgumentException("Cannot convert empty array.");
|
throw new IllegalArgumentException("Cannot convert empty array.");
|
||||||
|
}
|
||||||
int beSrcPos = src.length - 1 - srcPos;
|
int beSrcPos = src.length - 1 - srcPos;
|
||||||
int srcLen = Math.min(4, beSrcPos + 1);
|
int srcLen = Math.min(4, beSrcPos + 1);
|
||||||
boolean[] paddedSrc = new boolean[4];
|
boolean[] paddedSrc = new boolean[4];
|
||||||
|
@ -455,37 +510,61 @@ public class Conversion {
|
||||||
if (src[srcPos]) {
|
if (src[srcPos]) {
|
||||||
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
||||||
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
||||||
if (src.length > srcPos + 3 && src[srcPos + 3]) return 'f';
|
if (src.length > srcPos + 3 && src[srcPos + 3]) {
|
||||||
else return 'e';
|
return 'f';
|
||||||
|
} else {
|
||||||
|
return 'e';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src.length > srcPos + 3 && src[srcPos + 3]) return 'd';
|
if (src.length > srcPos + 3 && src[srcPos + 3]) {
|
||||||
else return 'c';
|
return 'd';
|
||||||
|
} else {
|
||||||
|
return 'c';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
||||||
if (src.length > srcPos + 3 && src[srcPos + 3]) return 'b';
|
if (src.length > srcPos + 3 && src[srcPos + 3]) {
|
||||||
else return 'a';
|
return 'b';
|
||||||
|
} else {
|
||||||
|
return 'a';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src.length > srcPos + 3 && src[srcPos + 3]) return '9';
|
if (src.length > srcPos + 3 && src[srcPos + 3]) {
|
||||||
else return '8';
|
return '9';
|
||||||
|
} else {
|
||||||
|
return '8';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
if (src.length > srcPos + 1 && src[srcPos + 1]) {
|
||||||
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
||||||
if (src.length > srcPos + 3 && src[srcPos + 3]) return '7';
|
if (src.length > srcPos + 3 && src[srcPos + 3]) {
|
||||||
else return '6';
|
return '7';
|
||||||
|
} else {
|
||||||
|
return '6';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src.length > srcPos + 3 && src[srcPos + 3]) return '5';
|
if (src.length > srcPos + 3 && src[srcPos + 3]) {
|
||||||
else return '4';
|
return '5';
|
||||||
|
} else {
|
||||||
|
return '4';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
if (src.length > srcPos + 2 && src[srcPos + 2]) {
|
||||||
if (src.length > srcPos + 3 && src[srcPos + 3]) return '3';
|
if (src.length > srcPos + 3 && src[srcPos + 3]) {
|
||||||
else return '2';
|
return '3';
|
||||||
|
} else {
|
||||||
|
return '2';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (src.length > srcPos + 3 && src[srcPos + 3]) return '1';
|
if (src.length > srcPos + 3 && src[srcPos + 3]) {
|
||||||
else return '0';
|
return '1';
|
||||||
|
} else {
|
||||||
|
return '0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -511,8 +590,9 @@ public class Conversion {
|
||||||
*/
|
*/
|
||||||
public static char intToHexDigit(int nibble) {
|
public static char intToHexDigit(int nibble) {
|
||||||
char c = Character.forDigit(nibble, 16);
|
char c = Character.forDigit(nibble, 16);
|
||||||
if (c == Character.MIN_VALUE)
|
if (c == Character.MIN_VALUE) {
|
||||||
throw new IllegalArgumentException("nibble value not between 0 and 15: " + nibble);
|
throw new IllegalArgumentException("nibble value not between 0 and 15: " + nibble);
|
||||||
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,11 +669,13 @@ public class Conversion {
|
||||||
* @throws IllegalArgumentException if {@code (nInts-1)*32+dstPos >= 64}
|
* @throws IllegalArgumentException if {@code (nInts-1)*32+dstPos >= 64}
|
||||||
*/
|
*/
|
||||||
public static long intsToLong(int[] src, int srcPos, long dstInit, int dstPos, int nInts) {
|
public static long intsToLong(int[] src, int srcPos, long dstInit, int dstPos, int nInts) {
|
||||||
if (0 == nInts)
|
if (0 == nInts) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nInts-1)*32+dstPos >= 64)
|
}
|
||||||
|
if ((nInts - 1) * 32 + dstPos >= 64) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nInts-1)*32+dstPos is greather or equal to than 64");
|
"(nInts-1)*32+dstPos is greather or equal to than 64");
|
||||||
|
}
|
||||||
long out = dstInit;
|
long out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nInts; i++ ) {
|
for (int i = 0; i < nInts; i++ ) {
|
||||||
|
@ -622,11 +704,13 @@ public class Conversion {
|
||||||
*/
|
*/
|
||||||
public static long shortsToLong(short[] src, int srcPos, long dstInit, int dstPos,
|
public static long shortsToLong(short[] src, int srcPos, long dstInit, int dstPos,
|
||||||
int nShorts) {
|
int nShorts) {
|
||||||
if (0 == nShorts)
|
if (0 == nShorts) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nShorts-1)*16+dstPos >= 64)
|
}
|
||||||
|
if ((nShorts - 1) * 16 + dstPos >= 64) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nShorts-1)*16+dstPos is greather or equal to than 64");
|
"(nShorts-1)*16+dstPos is greather or equal to than 64");
|
||||||
|
}
|
||||||
long out = dstInit;
|
long out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nShorts; i++ ) {
|
for (int i = 0; i < nShorts; i++ ) {
|
||||||
|
@ -654,11 +738,13 @@ public class Conversion {
|
||||||
* @throws IllegalArgumentException if {@code (nShorts-1)*16+dstPos >= 32}
|
* @throws IllegalArgumentException if {@code (nShorts-1)*16+dstPos >= 32}
|
||||||
*/
|
*/
|
||||||
public static int shortsToInt(short[] src, int srcPos, int dstInit, int dstPos, int nShorts) {
|
public static int shortsToInt(short[] src, int srcPos, int dstInit, int dstPos, int nShorts) {
|
||||||
if (0 == nShorts)
|
if (0 == nShorts) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nShorts-1)*16+dstPos >= 32)
|
}
|
||||||
|
if ((nShorts - 1) * 16 + dstPos >= 32) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nShorts-1)*16+dstPos is greather or equal to than 32");
|
"(nShorts-1)*16+dstPos is greather or equal to than 32");
|
||||||
|
}
|
||||||
int out = dstInit;
|
int out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nShorts; i++ ) {
|
for (int i = 0; i < nShorts; i++ ) {
|
||||||
|
@ -686,11 +772,13 @@ public class Conversion {
|
||||||
* @throws IllegalArgumentException if {@code (nBytes-1)*8+dstPos >= 64}
|
* @throws IllegalArgumentException if {@code (nBytes-1)*8+dstPos >= 64}
|
||||||
*/
|
*/
|
||||||
public static long bytesToLong(byte[] src, int srcPos, long dstInit, int dstPos, int nBytes) {
|
public static long bytesToLong(byte[] src, int srcPos, long dstInit, int dstPos, int nBytes) {
|
||||||
if (0 == nBytes)
|
if (0 == nBytes) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nBytes-1)*8+dstPos >= 64)
|
}
|
||||||
|
if ((nBytes - 1) * 8 + dstPos >= 64) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nBytes-1)*8+dstPos is greather or equal to than 64");
|
"(nBytes-1)*8+dstPos is greather or equal to than 64");
|
||||||
|
}
|
||||||
long out = dstInit;
|
long out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBytes; i++ ) {
|
for (int i = 0; i < nBytes; i++ ) {
|
||||||
|
@ -718,11 +806,13 @@ public class Conversion {
|
||||||
* @throws IllegalArgumentException if {@code (nBytes-1)*8+dstPos >= 32}
|
* @throws IllegalArgumentException if {@code (nBytes-1)*8+dstPos >= 32}
|
||||||
*/
|
*/
|
||||||
public static int bytesToInt(byte[] src, int srcPos, int dstInit, int dstPos, int nBytes) {
|
public static int bytesToInt(byte[] src, int srcPos, int dstInit, int dstPos, int nBytes) {
|
||||||
if (0 == nBytes)
|
if (0 == nBytes) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nBytes-1)*8+dstPos >= 32)
|
}
|
||||||
|
if ((nBytes - 1) * 8 + dstPos >= 32) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nBytes-1)*8+dstPos is greather or equal to than 32");
|
"(nBytes-1)*8+dstPos is greather or equal to than 32");
|
||||||
|
}
|
||||||
int out = dstInit;
|
int out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBytes; i++ ) {
|
for (int i = 0; i < nBytes; i++ ) {
|
||||||
|
@ -751,11 +841,13 @@ public class Conversion {
|
||||||
*/
|
*/
|
||||||
public static short bytesToShort(byte[] src, int srcPos, short dstInit, int dstPos,
|
public static short bytesToShort(byte[] src, int srcPos, short dstInit, int dstPos,
|
||||||
int nBytes) {
|
int nBytes) {
|
||||||
if (0 == nBytes)
|
if (0 == nBytes) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nBytes-1)*8+dstPos >= 16)
|
}
|
||||||
|
if ((nBytes - 1) * 8 + dstPos >= 16) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nBytes-1)*8+dstPos is greather or equal to than 16");
|
"(nBytes-1)*8+dstPos is greather or equal to than 16");
|
||||||
|
}
|
||||||
short out = dstInit;
|
short out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBytes; i++ ) {
|
for (int i = 0; i < nBytes; i++ ) {
|
||||||
|
@ -783,11 +875,13 @@ public class Conversion {
|
||||||
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 64}
|
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 64}
|
||||||
*/
|
*/
|
||||||
public static long hexsToLong(String src, int srcPos, long dstInit, int dstPos, int nHexs) {
|
public static long hexsToLong(String src, int srcPos, long dstInit, int dstPos, int nHexs) {
|
||||||
if (0 == nHexs)
|
if (0 == nHexs) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nHexs-1)*4+dstPos >= 64)
|
}
|
||||||
|
if ((nHexs - 1) * 4 + dstPos >= 64) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nHexs-1)*4+dstPos is greather or equal to than 64");
|
"(nHexs-1)*4+dstPos is greather or equal to than 64");
|
||||||
|
}
|
||||||
long out = dstInit;
|
long out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nHexs; i++ ) {
|
for (int i = 0; i < nHexs; i++ ) {
|
||||||
|
@ -815,11 +909,13 @@ public class Conversion {
|
||||||
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 32}
|
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 32}
|
||||||
*/
|
*/
|
||||||
public static int hexsToInt(String src, int srcPos, int dstInit, int dstPos, int nHexs) {
|
public static int hexsToInt(String src, int srcPos, int dstInit, int dstPos, int nHexs) {
|
||||||
if (0 == nHexs)
|
if (0 == nHexs) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nHexs-1)*4+dstPos >= 32)
|
}
|
||||||
|
if ((nHexs - 1) * 4 + dstPos >= 32) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nHexs-1)*4+dstPos is greather or equal to than 32");
|
"(nHexs-1)*4+dstPos is greather or equal to than 32");
|
||||||
|
}
|
||||||
int out = dstInit;
|
int out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nHexs; i++ ) {
|
for (int i = 0; i < nHexs; i++ ) {
|
||||||
|
@ -847,11 +943,13 @@ public class Conversion {
|
||||||
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 16}
|
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 16}
|
||||||
*/
|
*/
|
||||||
public static short hexsToShort(String src, int srcPos, short dstInit, int dstPos, int nHexs) {
|
public static short hexsToShort(String src, int srcPos, short dstInit, int dstPos, int nHexs) {
|
||||||
if (0 == nHexs)
|
if (0 == nHexs) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nHexs-1)*4+dstPos >= 16)
|
}
|
||||||
|
if ((nHexs - 1) * 4 + dstPos >= 16) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nHexs-1)*4+dstPos is greather or equal to than 16");
|
"(nHexs-1)*4+dstPos is greather or equal to than 16");
|
||||||
|
}
|
||||||
short out = dstInit;
|
short out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nHexs; i++ ) {
|
for (int i = 0; i < nHexs; i++ ) {
|
||||||
|
@ -879,11 +977,13 @@ public class Conversion {
|
||||||
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 8}
|
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 8}
|
||||||
*/
|
*/
|
||||||
public static byte hexsToByte(String src, int srcPos, byte dstInit, int dstPos, int nHexs) {
|
public static byte hexsToByte(String src, int srcPos, byte dstInit, int dstPos, int nHexs) {
|
||||||
if (0 == nHexs)
|
if (0 == nHexs) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nHexs-1)*4+dstPos >= 8)
|
}
|
||||||
|
if ((nHexs - 1) * 4 + dstPos >= 8) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nHexs-1)*4+dstPos is greather or equal to than 8");
|
"(nHexs-1)*4+dstPos is greather or equal to than 8");
|
||||||
|
}
|
||||||
byte out = dstInit;
|
byte out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nHexs; i++ ) {
|
for (int i = 0; i < nHexs; i++ ) {
|
||||||
|
@ -912,11 +1012,13 @@ public class Conversion {
|
||||||
*/
|
*/
|
||||||
public static long boolsToLong(boolean[] src, int srcPos, long dstInit, int dstPos,
|
public static long boolsToLong(boolean[] src, int srcPos, long dstInit, int dstPos,
|
||||||
int nBools) {
|
int nBools) {
|
||||||
if (0 == nBools)
|
if (0 == nBools) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if (nBools-1+dstPos >= 64)
|
}
|
||||||
|
if (nBools - 1 + dstPos >= 64) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"nBools-1+dstPos is greather or equal to than 64");
|
"nBools-1+dstPos is greather or equal to than 64");
|
||||||
|
}
|
||||||
long out = dstInit;
|
long out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBools; i++ ) {
|
for (int i = 0; i < nBools; i++ ) {
|
||||||
|
@ -944,11 +1046,13 @@ public class Conversion {
|
||||||
* @throws IllegalArgumentException if {@code nBools-1+dstPos >= 32}
|
* @throws IllegalArgumentException if {@code nBools-1+dstPos >= 32}
|
||||||
*/
|
*/
|
||||||
public static int boolsToInt(boolean[] src, int srcPos, int dstInit, int dstPos, int nBools) {
|
public static int boolsToInt(boolean[] src, int srcPos, int dstInit, int dstPos, int nBools) {
|
||||||
if (0 == nBools)
|
if (0 == nBools) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if (nBools-1+dstPos >= 32)
|
}
|
||||||
|
if (nBools - 1 + dstPos >= 32) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"nBools-1+dstPos is greather or equal to than 32");
|
"nBools-1+dstPos is greather or equal to than 32");
|
||||||
|
}
|
||||||
int out = dstInit;
|
int out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBools; i++ ) {
|
for (int i = 0; i < nBools; i++ ) {
|
||||||
|
@ -977,11 +1081,13 @@ public class Conversion {
|
||||||
*/
|
*/
|
||||||
public static short boolsToShort(boolean[] src, int srcPos, short dstInit, int dstPos,
|
public static short boolsToShort(boolean[] src, int srcPos, short dstInit, int dstPos,
|
||||||
int nBools) {
|
int nBools) {
|
||||||
if (0 == nBools)
|
if (0 == nBools) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if (nBools-1+dstPos >= 16)
|
}
|
||||||
|
if (nBools - 1 + dstPos >= 16) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"nBools-1+dstPos is greather or equal to than 16");
|
"nBools-1+dstPos is greather or equal to than 16");
|
||||||
|
}
|
||||||
short out = dstInit;
|
short out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBools; i++ ) {
|
for (int i = 0; i < nBools; i++ ) {
|
||||||
|
@ -1010,11 +1116,12 @@ public class Conversion {
|
||||||
*/
|
*/
|
||||||
public static byte boolsToByte(boolean[] src, int srcPos, byte dstInit, int dstPos,
|
public static byte boolsToByte(boolean[] src, int srcPos, byte dstInit, int dstPos,
|
||||||
int nBools) {
|
int nBools) {
|
||||||
if (0 == nBools)
|
if (0 == nBools) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if (nBools-1+dstPos >= 8)
|
}
|
||||||
throw new IllegalArgumentException(
|
if (nBools - 1 + dstPos >= 8) {
|
||||||
"nBools-1+dstPos is greather or equal to than 8");
|
throw new IllegalArgumentException("nBools-1+dstPos is greather or equal to than 8");
|
||||||
|
}
|
||||||
byte out = dstInit;
|
byte out = dstInit;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBools; i++ ) {
|
for (int i = 0; i < nBools; i++ ) {
|
||||||
|
@ -1033,21 +1140,22 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the long to convert
|
* @param src the long to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dst the destination array
|
* @param dst the destination array
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nInts the number of ints to copy to {@code dst}, must be smaller or equal to
|
* @param nInts the number of ints to copy to {@code dst}, must be smaller or equal to the
|
||||||
* the width of the input (from srcPos to msb)
|
* width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code (nInts-1)*32+srcPos >= 64}
|
* @throws IllegalArgumentException if {@code (nInts-1)*32+srcPos >= 64}
|
||||||
*/
|
*/
|
||||||
public static int[] longToInts(long src, int srcPos, int[] dst, int dstPos, int nInts) {
|
public static int[] longToInts(long src, int srcPos, int[] dst, int dstPos, int nInts) {
|
||||||
if (0 == nInts)
|
if (0 == nInts) {
|
||||||
return dst;
|
return dst;
|
||||||
if ((nInts - 1) * 32 + srcPos >= 64)
|
}
|
||||||
|
if ((nInts - 1) * 32 + srcPos >= 64) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nInts-1)*32+srcPos is greather or equal to than 64");
|
"(nInts-1)*32+srcPos is greather or equal to than 64");
|
||||||
|
}
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nInts; i++ ) {
|
for (int i = 0; i < nInts; i++ ) {
|
||||||
shift = i * 32 + srcPos;
|
shift = i * 32 + srcPos;
|
||||||
|
@ -1063,22 +1171,23 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the long to convert
|
* @param src the long to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dst the destination array
|
* @param dst the destination array
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nShorts the number of shorts to copy to {@code dst}, must be smaller or equal
|
* @param nShorts the number of shorts to copy to {@code dst}, must be smaller or equal to
|
||||||
* to the width of the input (from srcPos to msb)
|
* the width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code (nShorts-1)*16+srcPos >= 64}
|
* @throws IllegalArgumentException if {@code (nShorts-1)*16+srcPos >= 64}
|
||||||
*/
|
*/
|
||||||
public static short[] longToShorts(long src, int srcPos, short[] dst, int dstPos,
|
public static short[] longToShorts(long src, int srcPos, short[] dst, int dstPos,
|
||||||
int nShorts) {
|
int nShorts) {
|
||||||
if (0 == nShorts)
|
if (0 == nShorts) {
|
||||||
return dst;
|
return dst;
|
||||||
if ((nShorts - 1) * 16 + srcPos >= 64)
|
}
|
||||||
|
if ((nShorts - 1) * 16 + srcPos >= 64) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nShorts-1)*16+srcPos is greather or equal to than 64");
|
"(nShorts-1)*16+srcPos is greather or equal to than 64");
|
||||||
|
}
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nShorts; i++ ) {
|
for (int i = 0; i < nShorts; i++ ) {
|
||||||
shift = i * 16 + srcPos;
|
shift = i * 16 + srcPos;
|
||||||
|
@ -1094,21 +1203,22 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the int to convert
|
* @param src the int to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dst the destination array
|
* @param dst the destination array
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nShorts the number of shorts to copy to {@code dst}, must be smaller or equal
|
* @param nShorts the number of shorts to copy to {@code dst}, must be smaller or equal to
|
||||||
* to the width of the input (from srcPos to msb)
|
* the width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code (nShorts-1)*16+srcPos >= 32}
|
* @throws IllegalArgumentException if {@code (nShorts-1)*16+srcPos >= 32}
|
||||||
*/
|
*/
|
||||||
public static short[] intToShorts(int src, int srcPos, short[] dst, int dstPos, int nShorts) {
|
public static short[] intToShorts(int src, int srcPos, short[] dst, int dstPos, int nShorts) {
|
||||||
if (0 == nShorts)
|
if (0 == nShorts) {
|
||||||
return dst;
|
return dst;
|
||||||
if ((nShorts - 1) * 16 + srcPos >= 32)
|
}
|
||||||
|
if ((nShorts - 1) * 16 + srcPos >= 32) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nShorts-1)*16+srcPos is greather or equal to than 32");
|
"(nShorts-1)*16+srcPos is greather or equal to than 32");
|
||||||
|
}
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nShorts; i++ ) {
|
for (int i = 0; i < nShorts; i++ ) {
|
||||||
shift = i * 16 + srcPos;
|
shift = i * 16 + srcPos;
|
||||||
|
@ -1124,21 +1234,22 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the long to convert
|
* @param src the long to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dst the destination array
|
* @param dst the destination array
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nBytes the number of bytes to copy to {@code dst}, must be smaller or equal to
|
* @param nBytes the number of bytes to copy to {@code dst}, must be smaller or equal to the
|
||||||
* the width of the input (from srcPos to msb)
|
* width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code (nBytes-1)*8+srcPos >= 64}
|
* @throws IllegalArgumentException if {@code (nBytes-1)*8+srcPos >= 64}
|
||||||
*/
|
*/
|
||||||
public static byte[] longToBytes(long src, int srcPos, byte[] dst, int dstPos, int nBytes) {
|
public static byte[] longToBytes(long src, int srcPos, byte[] dst, int dstPos, int nBytes) {
|
||||||
if (0 == nBytes)
|
if (0 == nBytes) {
|
||||||
return dst;
|
return dst;
|
||||||
if ((nBytes - 1) * 8 + srcPos >= 64)
|
}
|
||||||
|
if ((nBytes - 1) * 8 + srcPos >= 64) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nBytes-1)*8+srcPos is greather or equal to than 64");
|
"(nBytes-1)*8+srcPos is greather or equal to than 64");
|
||||||
|
}
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBytes; i++ ) {
|
for (int i = 0; i < nBytes; i++ ) {
|
||||||
shift = i * 8 + srcPos;
|
shift = i * 8 + srcPos;
|
||||||
|
@ -1154,21 +1265,22 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the int to convert
|
* @param src the int to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dst the destination array
|
* @param dst the destination array
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nBytes the number of bytes to copy to {@code dst}, must be smaller or equal to
|
* @param nBytes the number of bytes to copy to {@code dst}, must be smaller or equal to the
|
||||||
* the width of the input (from srcPos to msb)
|
* width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code (nBytes-1)*8+srcPos >= 32}
|
* @throws IllegalArgumentException if {@code (nBytes-1)*8+srcPos >= 32}
|
||||||
*/
|
*/
|
||||||
public static byte[] intToBytes(int src, int srcPos, byte[] dst, int dstPos, int nBytes) {
|
public static byte[] intToBytes(int src, int srcPos, byte[] dst, int dstPos, int nBytes) {
|
||||||
if (0 == nBytes)
|
if (0 == nBytes) {
|
||||||
return dst;
|
return dst;
|
||||||
if ((nBytes - 1) * 8 + srcPos >= 32)
|
}
|
||||||
|
if ((nBytes - 1) * 8 + srcPos >= 32) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nBytes-1)*8+srcPos is greather or equal to than 32");
|
"(nBytes-1)*8+srcPos is greather or equal to than 32");
|
||||||
|
}
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBytes; i++ ) {
|
for (int i = 0; i < nBytes; i++ ) {
|
||||||
shift = i * 8 + srcPos;
|
shift = i * 8 + srcPos;
|
||||||
|
@ -1184,21 +1296,22 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the short to convert
|
* @param src the short to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dst the destination array
|
* @param dst the destination array
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nBytes the number of bytes to copy to {@code dst}, must be smaller or equal to
|
* @param nBytes the number of bytes to copy to {@code dst}, must be smaller or equal to the
|
||||||
* the width of the input (from srcPos to msb)
|
* width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code (nBytes-1)*8+srcPos >= 16}
|
* @throws IllegalArgumentException if {@code (nBytes-1)*8+srcPos >= 16}
|
||||||
*/
|
*/
|
||||||
public static byte[] shortToBytes(short src, int srcPos, byte[] dst, int dstPos, int nBytes) {
|
public static byte[] shortToBytes(short src, int srcPos, byte[] dst, int dstPos, int nBytes) {
|
||||||
if (0 == nBytes)
|
if (0 == nBytes) {
|
||||||
return dst;
|
return dst;
|
||||||
if ((nBytes - 1) * 8 + srcPos >= 16)
|
}
|
||||||
|
if ((nBytes - 1) * 8 + srcPos >= 16) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nBytes-1)*8+srcPos is greather or equal to than 16");
|
"(nBytes-1)*8+srcPos is greather or equal to than 16");
|
||||||
|
}
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBytes; i++ ) {
|
for (int i = 0; i < nBytes; i++ ) {
|
||||||
shift = i * 8 + srcPos;
|
shift = i * 8 + srcPos;
|
||||||
|
@ -1214,21 +1327,22 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the long to convert
|
* @param src the long to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dstInit the initial value for the result String
|
* @param dstInit the initial value for the result String
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to
|
* @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to the
|
||||||
* the width of the input (from srcPos to msb)
|
* width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 64}
|
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 64}
|
||||||
*/
|
*/
|
||||||
public static String longToHexs(long src, int srcPos, String dstInit, int dstPos, int nHexs) {
|
public static String longToHexs(long src, int srcPos, String dstInit, int dstPos, int nHexs) {
|
||||||
if (0 == nHexs)
|
if (0 == nHexs) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nHexs - 1) * 4 + srcPos >= 64)
|
}
|
||||||
|
if ((nHexs - 1) * 4 + srcPos >= 64) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nHexs-1)*4+srcPos is greather or equal to than 64");
|
"(nHexs-1)*4+srcPos is greather or equal to than 64");
|
||||||
|
}
|
||||||
StringBuilder sb = new StringBuilder(dstInit);
|
StringBuilder sb = new StringBuilder(dstInit);
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nHexs; i++ ) {
|
for (int i = 0; i < nHexs; i++ ) {
|
||||||
|
@ -1246,21 +1360,22 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the int to convert
|
* @param src the int to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dstInit the initial value for the result String
|
* @param dstInit the initial value for the result String
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to
|
* @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to the
|
||||||
* the width of the input (from srcPos to msb)
|
* width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 32}
|
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 32}
|
||||||
*/
|
*/
|
||||||
public static String intToHexs(int src, int srcPos, String dstInit, int dstPos, int nHexs) {
|
public static String intToHexs(int src, int srcPos, String dstInit, int dstPos, int nHexs) {
|
||||||
if (0 == nHexs)
|
if (0 == nHexs) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nHexs - 1) * 4 + srcPos >= 32)
|
}
|
||||||
|
if ((nHexs - 1) * 4 + srcPos >= 32) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nHexs-1)*4+srcPos is greather or equal to than 32");
|
"(nHexs-1)*4+srcPos is greather or equal to than 32");
|
||||||
|
}
|
||||||
StringBuilder sb = new StringBuilder(dstInit);
|
StringBuilder sb = new StringBuilder(dstInit);
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nHexs; i++ ) {
|
for (int i = 0; i < nHexs; i++ ) {
|
||||||
|
@ -1278,22 +1393,23 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the short to convert
|
* @param src the short to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dstInit the initial value for the result String
|
* @param dstInit the initial value for the result String
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to
|
* @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to the
|
||||||
* the width of the input (from srcPos to msb)
|
* width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 16}
|
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 16}
|
||||||
*/
|
*/
|
||||||
public static String shortToHexs(short src, int srcPos, String dstInit, int dstPos,
|
public static String shortToHexs(short src, int srcPos, String dstInit, int dstPos,
|
||||||
int nHexs) {
|
int nHexs) {
|
||||||
if (0 == nHexs)
|
if (0 == nHexs) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nHexs - 1) * 4 + srcPos >= 16)
|
}
|
||||||
|
if ((nHexs - 1) * 4 + srcPos >= 16) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nHexs-1)*4+srcPos is greather or equal to than 16");
|
"(nHexs-1)*4+srcPos is greather or equal to than 16");
|
||||||
|
}
|
||||||
StringBuilder sb = new StringBuilder(dstInit);
|
StringBuilder sb = new StringBuilder(dstInit);
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nHexs; i++ ) {
|
for (int i = 0; i < nHexs; i++ ) {
|
||||||
|
@ -1311,21 +1427,22 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the byte to convert
|
* @param src the byte to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dstInit the initial value for the result String
|
* @param dstInit the initial value for the result String
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to
|
* @param nHexs the number of Chars to copy to {@code dst}, must be smaller or equal to the
|
||||||
* the width of the input (from srcPos to msb)
|
* width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 8}
|
* @throws IllegalArgumentException if {@code (nHexs-1)*4+srcPos >= 8}
|
||||||
*/
|
*/
|
||||||
public static String byteToHexs(byte src, int srcPos, String dstInit, int dstPos, int nHexs) {
|
public static String byteToHexs(byte src, int srcPos, String dstInit, int dstPos, int nHexs) {
|
||||||
if (0 == nHexs)
|
if (0 == nHexs) {
|
||||||
return dstInit;
|
return dstInit;
|
||||||
if ((nHexs - 1) * 4 + srcPos >= 8)
|
}
|
||||||
|
if ((nHexs - 1) * 4 + srcPos >= 8) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"(nHexs-1)*4+srcPos is greather or equal to than 8");
|
"(nHexs-1)*4+srcPos is greather or equal to than 8");
|
||||||
|
}
|
||||||
StringBuilder sb = new StringBuilder(dstInit);
|
StringBuilder sb = new StringBuilder(dstInit);
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nHexs; i++ ) {
|
for (int i = 0; i < nHexs; i++ ) {
|
||||||
|
@ -1343,22 +1460,23 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the long to convert
|
* @param src the long to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dst the destination array
|
* @param dst the destination array
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nBools the number of booleans to copy to {@code dst}, must be smaller or equal
|
* @param nBools the number of booleans to copy to {@code dst}, must be smaller or equal to
|
||||||
* to the width of the input (from srcPos to msb)
|
* the width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code nBools-1+srcPos >= 64}
|
* @throws IllegalArgumentException if {@code nBools-1+srcPos >= 64}
|
||||||
*/
|
*/
|
||||||
public static boolean[] longToBools(long src, int srcPos, boolean[] dst, int dstPos,
|
public static boolean[] longToBools(long src, int srcPos, boolean[] dst, int dstPos,
|
||||||
int nBools) {
|
int nBools) {
|
||||||
if (0 == nBools)
|
if (0 == nBools) {
|
||||||
return dst;
|
return dst;
|
||||||
if (nBools - 1 + srcPos >= 64)
|
}
|
||||||
|
if (nBools - 1 + srcPos >= 64) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"nBools-1+srcPos is greather or equal to than 64");
|
"nBools-1+srcPos is greather or equal to than 64");
|
||||||
|
}
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBools; i++ ) {
|
for (int i = 0; i < nBools; i++ ) {
|
||||||
shift = i * 1 + srcPos;
|
shift = i * 1 + srcPos;
|
||||||
|
@ -1374,22 +1492,23 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the int to convert
|
* @param src the int to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dst the destination array
|
* @param dst the destination array
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nBools the number of booleans to copy to {@code dst}, must be smaller or equal
|
* @param nBools the number of booleans to copy to {@code dst}, must be smaller or equal to
|
||||||
* to the width of the input (from srcPos to msb)
|
* the width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code nBools-1+srcPos >= 32}
|
* @throws IllegalArgumentException if {@code nBools-1+srcPos >= 32}
|
||||||
*/
|
*/
|
||||||
public static boolean[] intToBools(int src, int srcPos, boolean[] dst, int dstPos,
|
public static boolean[] intToBools(int src, int srcPos, boolean[] dst, int dstPos,
|
||||||
int nBools) {
|
int nBools) {
|
||||||
if (0 == nBools)
|
if (0 == nBools) {
|
||||||
return dst;
|
return dst;
|
||||||
if (nBools - 1 + srcPos >= 32)
|
}
|
||||||
|
if (nBools - 1 + srcPos >= 32) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"nBools-1+srcPos is greather or equal to than 32");
|
"nBools-1+srcPos is greather or equal to than 32");
|
||||||
|
}
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBools; i++ ) {
|
for (int i = 0; i < nBools; i++ ) {
|
||||||
shift = i * 1 + srcPos;
|
shift = i * 1 + srcPos;
|
||||||
|
@ -1405,22 +1524,23 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the short to convert
|
* @param src the short to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dst the destination array
|
* @param dst the destination array
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nBools the number of booleans to copy to {@code dst}, must be smaller or equal
|
* @param nBools the number of booleans to copy to {@code dst}, must be smaller or equal to
|
||||||
* to the width of the input (from srcPos to msb)
|
* the width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code nBools-1+srcPos >= 16}
|
* @throws IllegalArgumentException if {@code nBools-1+srcPos >= 16}
|
||||||
*/
|
*/
|
||||||
public static boolean[] shortToBools(short src, int srcPos, boolean[] dst, int dstPos,
|
public static boolean[] shortToBools(short src, int srcPos, boolean[] dst, int dstPos,
|
||||||
int nBools) {
|
int nBools) {
|
||||||
if (0 == nBools)
|
if (0 == nBools) {
|
||||||
return dst;
|
return dst;
|
||||||
if (nBools - 1 + srcPos >= 16)
|
}
|
||||||
|
if (nBools - 1 + srcPos >= 16) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"nBools-1+srcPos is greather or equal to than 16");
|
"nBools-1+srcPos is greather or equal to than 16");
|
||||||
|
}
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
assert ((nBools - 1) * 1 < 16 - srcPos);
|
assert ((nBools - 1) * 1 < 16 - srcPos);
|
||||||
for (int i = 0; i < nBools; i++ ) {
|
for (int i = 0; i < nBools; i++ ) {
|
||||||
|
@ -1437,22 +1557,22 @@ public class Conversion {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the byte to convert
|
* @param src the byte to convert
|
||||||
* @param srcPos the position in {@code src}, in bits, from where to start the
|
* @param srcPos the position in {@code src}, in bits, from where to start the conversion
|
||||||
* conversion
|
|
||||||
* @param dst the destination array
|
* @param dst the destination array
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nBools the number of booleans to copy to {@code dst}, must be smaller or equal
|
* @param nBools the number of booleans to copy to {@code dst}, must be smaller or equal to
|
||||||
* to the width of the input (from srcPos to msb)
|
* the width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code nBools-1+srcPos >= 8}
|
* @throws IllegalArgumentException if {@code nBools-1+srcPos >= 8}
|
||||||
*/
|
*/
|
||||||
public static boolean[] byteToBools(byte src, int srcPos, boolean[] dst, int dstPos,
|
public static boolean[] byteToBools(byte src, int srcPos, boolean[] dst, int dstPos,
|
||||||
int nBools) {
|
int nBools) {
|
||||||
if (0 == nBools)
|
if (0 == nBools) {
|
||||||
return dst;
|
return dst;
|
||||||
if (nBools - 1 + srcPos >= 8)
|
}
|
||||||
throw new IllegalArgumentException(
|
if (nBools - 1 + srcPos >= 8) {
|
||||||
"nBools-1+srcPos is greather or equal to than 8");
|
throw new IllegalArgumentException("nBools-1+srcPos is greather or equal to than 8");
|
||||||
|
}
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
for (int i = 0; i < nBools; i++ ) {
|
for (int i = 0; i < nBools; i++ ) {
|
||||||
shift = i * 1 + srcPos;
|
shift = i * 1 + srcPos;
|
||||||
|
@ -1463,43 +1583,49 @@ public class Conversion {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Converts UUID into an array of byte using the default (little endian, Lsb0) byte and
|
* Converts UUID into an array of byte using the default (little endian, Lsb0) byte and bit
|
||||||
* bit ordering.
|
* ordering.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the UUID to convert
|
* @param src the UUID to convert
|
||||||
* @param dst the destination array
|
* @param dst the destination array
|
||||||
* @param dstPos the position in {@code dst} where to copy the result
|
* @param dstPos the position in {@code dst} where to copy the result
|
||||||
* @param nBytes the number of bytes to copy to {@code dst}, must be smaller or equal to
|
* @param nBytes the number of bytes to copy to {@code dst}, must be smaller or equal to the
|
||||||
* the width of the input (from srcPos to msb)
|
* width of the input (from srcPos to msb)
|
||||||
* @return {@code dst}
|
* @return {@code dst}
|
||||||
* @throws IllegalArgumentException if {@code nBytes > 16}
|
* @throws IllegalArgumentException if {@code nBytes > 16}
|
||||||
*/
|
*/
|
||||||
public static byte[] uuidToBytes(UUID src, byte[] dst, int dstPos, int nBytes) {
|
public static byte[] uuidToBytes(UUID src, byte[] dst, int dstPos, int nBytes) {
|
||||||
if (0 == nBytes)
|
if (0 == nBytes) {
|
||||||
return dst;
|
return dst;
|
||||||
if (nBytes > 16 )
|
}
|
||||||
|
if (nBytes > 16) {
|
||||||
throw new IllegalArgumentException("nBytes is greather than 16");
|
throw new IllegalArgumentException("nBytes is greather than 16");
|
||||||
|
}
|
||||||
longToBytes(src.getMostSignificantBits(), 0, dst, dstPos, nBytes > 8 ? 8 : nBytes);
|
longToBytes(src.getMostSignificantBits(), 0, dst, dstPos, nBytes > 8 ? 8 : nBytes);
|
||||||
if (nBytes >= 8)
|
if (nBytes >= 8) {
|
||||||
longToBytes(src.getLeastSignificantBits(), 0, dst, dstPos+8, nBytes-8);
|
longToBytes(src.getLeastSignificantBits(), 0, dst, dstPos + 8, nBytes - 8);
|
||||||
|
}
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Converts bytes fomr an array into a UUID using the default (little endian, Lsb0) byte and
|
* Converts bytes from an array into a UUID using the default (little endian, Lsb0) byte and
|
||||||
* bit ordering.
|
* bit ordering.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param src the source byte array
|
* @param src the source byte array
|
||||||
* @param srcPos the position in {@code src} where to copy the result from
|
* @param srcPos the position in {@code src} where to copy the result from
|
||||||
* @return a UUID
|
* @return a UUID
|
||||||
* @throws IllegalArgumentException if array does not contain at least 16 bytes beginning with {@code srcPos}
|
* @throws IllegalArgumentException if array does not contain at least 16 bytes beginning
|
||||||
|
* with {@code srcPos}
|
||||||
*/
|
*/
|
||||||
public static UUID bytesToUuid(byte[] src, int srcPos) {
|
public static UUID bytesToUuid(byte[] src, int srcPos) {
|
||||||
if (src.length-srcPos < 16 )
|
if (src.length - srcPos < 16) {
|
||||||
throw new IllegalArgumentException("Need at least 16 bytes for UUID");
|
throw new IllegalArgumentException("Need at least 16 bytes for UUID");
|
||||||
return new UUID(bytesToLong(src, srcPos, 0, 0, 8), bytesToLong(src, srcPos+8, 0, 0, 8));
|
}
|
||||||
|
return new UUID(
|
||||||
|
bytesToLong(src, srcPos, 0, 0, 8), bytesToLong(src, srcPos + 8, 0, 0, 8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -506,8 +506,11 @@ public class ConversionTest {
|
||||||
static String dbgPrint(boolean[] src) {
|
static String dbgPrint(boolean[] src) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (boolean e : src) {
|
for (boolean e : src) {
|
||||||
if (e) sb.append("1,");
|
if (e) {
|
||||||
else sb.append("0,");
|
sb.append("1,");
|
||||||
|
} else {
|
||||||
|
sb.append("0,");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String out = sb.toString();
|
String out = sb.toString();
|
||||||
return out.substring(0, out.length() - 1);
|
return out.substring(0, out.length() - 1);
|
||||||
|
|
Loading…
Reference in New Issue