public class ArrayUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.util.List<java.lang.Integer> |
asList(int[] a) |
static void |
bubbleSort(int[] array) |
static <T extends java.lang.Comparable<? super T>> |
bubbleSort(T[] array) |
static <T> boolean |
checkDuplicate(T[] input)
Since Set doesn't allow duplicates add() return false
if we try to add duplicates into Set and this property
can be used to check if array contains duplicates.
|
static byte[] |
concat(byte[] first,
byte[]... rest) |
static <T> T[] |
concat(java.lang.Class<T> type,
T[]... arrays)
Type safe concatenation of arrays with upper type bound T
|
static <T> T[] |
concat(T[]... arrays)
Type safe concatenation of arrays with upper type bound T
|
static int |
findEqualOrLess(int[] a,
int key) |
static int |
findEqualOrLess(int[] a,
int fromIndex,
int toIndex,
int key)
Find the index of the element which is equal or less than the key.
|
static <T> int |
findEqualOrLess(T[] a,
int fromIndex,
int toIndex,
T key,
java.util.Comparator<? super T> c) |
static <T> int |
findEqualOrLess(T[] a,
T key,
java.util.Comparator<? super T> c) |
static byte[] |
flipEndian(byte[] input,
int offset,
int len,
int bits,
int scanLineStride,
boolean bigEndian)
Flip the endian of the input byte-compacted array
|
static int |
fromFloat(float fval) |
static byte[] |
getBitReverseTable()
Since nonzero-length array is always mutable, we should return
a clone of the underlying array as BIT_REVERSE_TABLE.clone().
|
static void |
insertionsort(int[] array) |
static void |
insertionsort(int[] array,
int start,
int end) |
static <T extends java.lang.Comparable<? super T>> |
insertionsort(T[] array) |
static <T extends java.lang.Comparable<? super T>> |
insertionsort(T[] array,
int start,
int end) |
static void |
mergesort(int[] array) |
static void |
mergesort(int[] array,
int left,
int right) |
static <T extends java.lang.Comparable<? super T>> |
mergesort(T[] array) |
static <T extends java.lang.Comparable<? super T>> |
mergesort(T[] array,
int left,
int right) |
static byte[] |
packByteArray(byte[] input,
int start,
int bits,
int len)
Packs all or part of the input byte array which uses "bits" bits to use all 8 bits.
|
static byte[] |
packByteArray(byte[] input,
int stride,
int start,
int bits,
int len)
Packs all or part of the input byte array which uses "bits" bits to use all 8 bits.
|
static void |
quicksort(int[] array) |
static void |
quicksort(int[] array,
int start,
int end) |
static <T extends java.lang.Comparable<? super T>> |
quicksort(T[] array) |
static <T extends java.lang.Comparable<? super T>> |
quicksort(T[] array,
int low,
int high) |
static int[] |
removeDuplicates(int[] input)
Remove duplicate elements from an int array
|
static byte[] |
reverse(byte[] array) |
static <T> void |
reverse(T[] data) |
static void |
reverseBits(byte[] input) |
static void |
shellsort(int[] array) |
static void |
shellsort(int[] array,
int start,
int end) |
static <T extends java.lang.Comparable<? super T>> |
shellsort(T[] array) |
static <T extends java.lang.Comparable<? super T>> |
shellsort(T[] array,
int start,
int end) |
static byte[] |
subArray(byte[] src,
int offset,
int len) |
static float[] |
to16BitFloatArray(byte[] data,
boolean bigEndian) |
static float[] |
to24BitFloatArray(byte[] data,
boolean bigEndian) |
static int[] |
to32BitsLongArray(byte[] data,
boolean bigEndian) |
static byte[] |
toByteArray(int value) |
static byte[] |
toByteArray(int[] data,
boolean bigEndian) |
static byte[] |
toByteArray(long[] data,
boolean bigEndian) |
static byte[] |
toByteArray(short value) |
static byte[] |
toByteArray(short[] data,
boolean bigEndian) |
static byte[] |
toByteArrayMM(int value) |
static byte[] |
toByteArrayMM(short value) |
static double[] |
toDoubleArray(byte[] data,
boolean bigEndian) |
static double[] |
toDoubleArray(byte[] data,
int offset,
int len,
boolean bigEndian) |
static float |
toFloat(int lbits) |
static float[] |
toFloatArray(byte[] data,
boolean bigEndian) |
static float[] |
toFloatArray(byte[] data,
int offset,
int len,
boolean bigEndian) |
static int[] |
toIntArray(byte[] data,
boolean bigEndian) |
static int[] |
toIntArray(byte[] data,
int offset,
int len,
boolean bigEndian) |
static long[] |
toLongArray(byte[] data,
boolean bigEndian) |
static long[] |
toLongArray(byte[] data,
int offset,
int len,
boolean bigEndian) |
static java.lang.Object |
toNBits(int nBits,
byte[] input,
int stride,
boolean bigEndian)
Converts an input byte array to nBits data array using the smallest data type which
can hold the nBits data.
|
static double[] |
toPrimitive(java.lang.Double[] doubles) |
static float[] |
toPrimitive(java.lang.Float[] floats) |
static int[] |
toPrimitive(java.lang.Integer[] integers) |
static long[] |
toPrimitive(java.lang.Long[] longs) |
static short[] |
toPrimitive(java.lang.Short[] shorts) |
static short[] |
toShortArray(byte[] data,
boolean bigEndian) |
static short[] |
toShortArray(byte[] data,
int offset,
int len,
boolean bigEndian) |
static byte[] |
trim(byte[] input) |
public static java.util.List<java.lang.Integer> asList(int[] a)
public static void bubbleSort(int[] array)
public static <T extends java.lang.Comparable<? super T>> void bubbleSort(T[] array)
public static <T> boolean checkDuplicate(T[] input)
input
- input arraypublic static byte[] concat(byte[] first, byte[]... rest)
public static <T> T[] concat(T[]... arrays)
Note: if type parameter is not explicitly supplied, it will be inferred as the upper bound for the two parameters.
arrays
- the arrays to be concatenatedjava.lang.NullPointerException
- if any of the input array is nullpublic static <T> T[] concat(java.lang.Class<T> type, T[]... arrays)
type
- type bound for the concatenated arrayarrays
- arrays to be concatenatedjava.lang.NullPointerException
- if any of the arrays to be
concatenated is null.public static int findEqualOrLess(int[] a, int key)
public static int findEqualOrLess(int[] a, int fromIndex, int toIndex, int key)
a
- the array to be searchedkey
- the value to be searched forpublic static <T> int findEqualOrLess(T[] a, int fromIndex, int toIndex, T key, java.util.Comparator<? super T> c)
public static <T> int findEqualOrLess(T[] a, T key, java.util.Comparator<? super T> c)
public static byte[] flipEndian(byte[] input, int offset, int len, int bits, int scanLineStride, boolean bigEndian)
input
- the input byte array which is byte compactedoffset
- the offset to start the reading inputlen
- number of bytes to readbits
- number of bits for the data before compactionscanLineStride
- scan line stride to skip bitsbigEndian
- whether or not the input data is in big endian orderpublic static int fromFloat(float fval)
public static byte[] getBitReverseTable()
public static void insertionsort(int[] array)
public static void insertionsort(int[] array, int start, int end)
public static <T extends java.lang.Comparable<? super T>> void insertionsort(T[] array)
public static <T extends java.lang.Comparable<? super T>> void insertionsort(T[] array, int start, int end)
public static void mergesort(int[] array)
public static void mergesort(int[] array, int left, int right)
public static <T extends java.lang.Comparable<? super T>> void mergesort(T[] array)
public static <T extends java.lang.Comparable<? super T>> void mergesort(T[] array, int left, int right)
public static byte[] packByteArray(byte[] input, int start, int bits, int len)
input
- input byte arraystart
- offset of the input array to start packingbits
- number of bits used by the input arraylen
- number of bytes from the input to be packedpublic static byte[] packByteArray(byte[] input, int stride, int start, int bits, int len)
We assume len is a multiplication of stride. The parameter stride controls the packing unit length and different units DO NOT share same byte. This happens when packing image data where each scan line MUST start at byte boundary like TIFF.
input
- input byte array to be packedstride
- length of packing unitstart
- offset of the input array to start packingbits
- number of bits used in each byte of the inputlen
- number of input bytes to be packedpublic static void quicksort(int[] array)
public static void quicksort(int[] array, int start, int end)
public static <T extends java.lang.Comparable<? super T>> void quicksort(T[] array)
public static <T extends java.lang.Comparable<? super T>> void quicksort(T[] array, int low, int high)
public static int[] removeDuplicates(int[] input)
input
- input unsorted int arraypublic static void reverseBits(byte[] input)
public static byte[] reverse(byte[] array)
public static <T> void reverse(T[] data)
public static void shellsort(int[] array)
public static void shellsort(int[] array, int start, int end)
public static <T extends java.lang.Comparable<? super T>> void shellsort(T[] array)
public static <T extends java.lang.Comparable<? super T>> void shellsort(T[] array, int start, int end)
public static byte[] subArray(byte[] src, int offset, int len)
public static float[] to16BitFloatArray(byte[] data, boolean bigEndian)
public static float[] to24BitFloatArray(byte[] data, boolean bigEndian)
public static int[] to32BitsLongArray(byte[] data, boolean bigEndian)
public static byte[] toByteArray(int value)
public static byte[] toByteArray(int[] data, boolean bigEndian)
public static byte[] toByteArray(long[] data, boolean bigEndian)
public static byte[] toByteArray(short value)
public static byte[] toByteArray(short[] data, boolean bigEndian)
public static byte[] toByteArrayMM(int value)
public static byte[] toByteArrayMM(short value)
public static double[] toDoubleArray(byte[] data, boolean bigEndian)
public static double[] toDoubleArray(byte[] data, int offset, int len, boolean bigEndian)
public static float toFloat(int lbits)
public static float[] toFloatArray(byte[] data, boolean bigEndian)
public static float[] toFloatArray(byte[] data, int offset, int len, boolean bigEndian)
public static int[] toIntArray(byte[] data, boolean bigEndian)
public static int[] toIntArray(byte[] data, int offset, int len, boolean bigEndian)
public static long[] toLongArray(byte[] data, boolean bigEndian)
public static long[] toLongArray(byte[] data, int offset, int len, boolean bigEndian)
public static java.lang.Object toNBits(int nBits, byte[] input, int stride, boolean bigEndian)
nBits
- number of bits for the data elementinput
- the input array for the data elementsstride
- scan line stride used to discard remaining bitsbigEndian
- the packing order of the bits. True if bigEndian, otherwise false.public static double[] toPrimitive(java.lang.Double[] doubles)
public static float[] toPrimitive(java.lang.Float[] floats)
public static int[] toPrimitive(java.lang.Integer[] integers)
public static long[] toPrimitive(java.lang.Long[] longs)
public static short[] toPrimitive(java.lang.Short[] shorts)
public static short[] toShortArray(byte[] data, boolean bigEndian)
public static short[] toShortArray(byte[] data, int offset, int len, boolean bigEndian)
public static byte[] trim(byte[] input)