- java.lang.Object
-
- ch.bind.philib.lang.ArrayUtil
-
-
Field Summary
Fields Modifier and Type Field Description static boolean[]EMPTY_BOOL_ARRAYstatic boolean[]EMPTY_BOOLEAN_ARRAYstatic byte[]EMPTY_BYTE_ARRAYstatic char[]EMPTY_CHAR_ARRAYstatic double[]EMPTY_DOUBLE_ARRAYstatic float[]EMPTY_FLOAT_ARRAYstatic int[]EMPTY_INT_ARRAYstatic long[]EMPTY_LONG_ARRAYstatic Object[]EMPTY_OBJECT_ARRAYstatic short[]EMPTY_SHORT_ARRAY
-
Constructor Summary
Constructors Modifier Constructor Description protectedArrayUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]append(byte[] a, byte[] b, int capacity)append the content of two byte arrays up to a certain capacity limitstatic <T> T[]append(Class<T> clazz, T[] a, T b)static byte[]concat(byte[] a, byte[] b)concatenate the content of two byte arrays.static booleancontains(byte[] data, byte[] search)static byte[]extractBack(byte[] data, int len)static byte[]extractFront(byte[] data, int len)static intfind(byte[] data, byte[] search)static intfind(byte[] data, byte[] search, int dataOffset)static StringformatShortHex(byte[] data)static StringformatShortHex(byte[] data, int off, int len)static StringformatShortHex(ByteBuffer data)static StringformatShortHex(ByteBuffer data, int len)static voidmemclr(byte[] buf)Overwrites the buffer's content with zeros.static voidmemclr(ByteBuffer buf)Overwrites the buffer's content with zeros.static <T> T[]newArray(Class<T> clazz, int size)shorthand forjava.lang.reflect.Array.newInstance(clazz, size)static <T> voidpickRandom(T[] source, T[] destination)Fills thedestinationarray with randomly picked values from thesourcearray.static <T> T[]prepend(Class<T> clazz, T[] a, T b)static <T> T[]remove(Class<T> clazz, T[] from, T what)static <T> T[]toArray(Class<T> clazz, Collection<? extends T> collection)
-
-
-
Field Detail
-
EMPTY_BOOLEAN_ARRAY
public static final boolean[] EMPTY_BOOLEAN_ARRAY
-
EMPTY_BOOL_ARRAY
public static final boolean[] EMPTY_BOOL_ARRAY
-
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY
-
EMPTY_CHAR_ARRAY
public static final char[] EMPTY_CHAR_ARRAY
-
EMPTY_SHORT_ARRAY
public static final short[] EMPTY_SHORT_ARRAY
-
EMPTY_INT_ARRAY
public static final int[] EMPTY_INT_ARRAY
-
EMPTY_LONG_ARRAY
public static final long[] EMPTY_LONG_ARRAY
-
EMPTY_FLOAT_ARRAY
public static final float[] EMPTY_FLOAT_ARRAY
-
EMPTY_DOUBLE_ARRAY
public static final double[] EMPTY_DOUBLE_ARRAY
-
EMPTY_OBJECT_ARRAY
public static final Object[] EMPTY_OBJECT_ARRAY
-
-
Method Detail
-
newArray
public static <T> T[] newArray(Class<T> clazz, int size)
shorthand forjava.lang.reflect.Array.newInstance(clazz, size)- Parameters:
clazz- -size- -- Returns:
- -
-
pickRandom
public static <T> void pickRandom(T[] source, T[] destination)Fills thedestinationarray with randomly picked values from thesourcearray. No value will be picked twice.- Parameters:
source- The array from which random values must be picked. The content of this array will not be altered.destination- The array which must be filled with random values. Previous values within this array will be overwritten.- Throws:
NullPointerException- If either of the two parameters is null.IllegalArgumentException- If thesource-array is smaller than thedestination-array.
-
concat
public static byte[] concat(byte[] a, byte[] b)concatenate the content of two byte arrays.- Parameters:
a- the first byte array (may be null)b- the second byte array (may be null)- Returns:
- a new byte array with the combined length of
aandb, containing a copy of their content.
-
append
public static byte[] append(byte[] a, byte[] b, int capacity)append the content of two byte arrays up to a certain capacity limit- Parameters:
a- the first byte array (may be null)b- the second byte array (may be null)- Returns:
- a new byte array with the combined length of
aandb, containing a copy of their content. if the combined length exceedscapacitythe returned arrayawill havea.length == capacity.
-
prepend
public static <T> T[] prepend(Class<T> clazz, T[] a, T b)
-
append
public static <T> T[] append(Class<T> clazz, T[] a, T b)
-
remove
public static <T> T[] remove(Class<T> clazz, T[] from, T what)
-
extractBack
public static byte[] extractBack(byte[] data, int len)
-
extractFront
public static byte[] extractFront(byte[] data, int len)
-
contains
public static boolean contains(byte[] data, byte[] search)
-
find
public static int find(byte[] data, byte[] search)
-
find
public static int find(byte[] data, byte[] search, int dataOffset)
-
formatShortHex
public static String formatShortHex(byte[] data)
-
formatShortHex
public static String formatShortHex(byte[] data, int off, int len)
-
formatShortHex
public static String formatShortHex(ByteBuffer data, int len)
-
formatShortHex
public static String formatShortHex(ByteBuffer data)
-
memclr
public static void memclr(ByteBuffer buf)
Overwrites the buffer's content with zeros.- Parameters:
buf- -
-
memclr
public static void memclr(byte[] buf)
Overwrites the buffer's content with zeros.- Parameters:
buf- -
-
toArray
public static <T> T[] toArray(Class<T> clazz, Collection<? extends T> collection)
-
-