jlibs.core.lang
Class ArrayUtil

java.lang.Object
  extended by jlibs.core.lang.ArrayUtil

public class ArrayUtil
extends Object

Author:
Santhosh Kumar T

Constructor Summary
ArrayUtil()
           
 
Method Summary
static
<T> T[]
clone(Object[] src, Class<T> componentType)
          returns the clone of src array.
static Object[] concat(Object[] array1, Object[] array2)
          Returns new array which has all values from array1 and array2 in order.
static
<T> T[]
concat(Object[] array1, Object[] array2, Class<T> componentType)
           
static
<T,S extends T>
boolean
contains(T[] array, S item)
          tells whether the array contains the given item
static
<T> T[]
copy(Object[] src, T[] dest)
          Copies all elements from src array to dest array.
static boolean endsWith(Object[] array1, Object[] array2)
          Returns true if array1 ends with array2
static byte[] ensureCapacity(byte[] array, int capacity)
           
static char[] ensureCapacity(char[] array, int capacity)
           
static boolean equals(Object[] array1, int from1, Object[] array2, int from2, int length)
          returns array1[from1, from1+length-1] and array2[from2, from2+length-1] contain same elements in case of index out of range, returns false
static
<T> T[]
filter(T[] array, Filter<T> filter)
          Returns new array which contains only those elements from given array which are selected by the filter
static
<T> T
getFirst(T[] array)
          Returns first element in given array.
static
<T> T
getLast(T[] array)
          Returns last element in given array.
static
<T,S extends T>
int
indexOf(T[] array, S item)
          Returns first index of item in given array
static
<T,S extends T>
int
indexOf(T[] array, S item, int fromIndex)
          returns first index of item in given array starting from fromIndex(inclusive)
static boolean startsWith(Object[] array1, Object[] array2)
          Returns true if array1 starts with array2
static Boolean[] toObjectArray(boolean[] arr)
           
static Byte[] toObjectArray(byte[] arr)
           
static Character[] toObjectArray(char[] arr)
           
static Double[] toObjectArray(double[] arr)
           
static Float[] toObjectArray(float[] arr)
           
static Integer[] toObjectArray(int[] arr)
           
static Long[] toObjectArray(long[] arr)
           
static Short[] toObjectArray(short[] arr)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayUtil

public ArrayUtil()
Method Detail

indexOf

public static <T,S extends T> int indexOf(T[] array,
                                          S item,
                                          int fromIndex)
returns first index of item in given array starting from fromIndex(inclusive)

Parameters:
array - object array, can be null
item - item to be searched, can be null
fromIndex - index(inclusive) from which search happens.
Returns:
-1 if array is null, or the item is not found otherwize returns first index of item in array

indexOf

public static <T,S extends T> int indexOf(T[] array,
                                          S item)
Returns first index of item in given array

Parameters:
array - object array, can be null
item - item to be searched, can be null
Returns:
-1 if array is null, or the item is not found. Otherwise returns first index of item in array
See Also:
indexOf(Object[], Object, int)

contains

public static <T,S extends T> boolean contains(T[] array,
                                               S item)
tells whether the array contains the given item

Parameters:
array - object array, can be null
item - item to be searched, can be null
Returns:
false if array is null, or item is not found otherwize returns true;

getFirst

public static <T> T getFirst(T[] array)
Returns first element in given array.

if array is null or of length zero, then returns null


getLast

public static <T> T getLast(T[] array)
Returns last element in given array.

if array is null or of length zero, then returns null


equals

public static boolean equals(Object[] array1,
                             int from1,
                             Object[] array2,
                             int from2,
                             int length)
returns array1[from1, from1+length-1] and array2[from2, from2+length-1] contain same elements in case of index out of range, returns false


startsWith

public static boolean startsWith(Object[] array1,
                                 Object[] array2)
Returns true if array1 starts with array2


endsWith

public static boolean endsWith(Object[] array1,
                               Object[] array2)
Returns true if array1 ends with array2


copy

public static <T> T[] copy(Object[] src,
                           T[] dest)
Copies all elements from src array to dest array.

If dest.length&lt;src.length, it copies only the number of elements that can fit in dest array.

Parameters:
src - source array
dest - destination array
Returns:
the destination array specified

clone

public static <T> T[] clone(Object[] src,
                            Class<T> componentType)
returns the clone of src array.

Parameters:
src - source array
componentType - the componentType used for the new array created
Returns:
cloned array

filter

public static <T> T[] filter(T[] array,
                             Filter<T> filter)
Returns new array which contains only those elements from given array which are selected by the filter

Parameters:
array - the array to be filtered
filter - filter to use
Returns:
filtered array

concat

public static <T> T[] concat(Object[] array1,
                             Object[] array2,
                             Class<T> componentType)

concat

public static Object[] concat(Object[] array1,
                              Object[] array2)
Returns new array which has all values from array1 and array2 in order. The componentType for the new array is determined by the componentTypes of two arrays.


toObjectArray

public static Boolean[] toObjectArray(boolean[] arr)

toObjectArray

public static Character[] toObjectArray(char[] arr)

toObjectArray

public static Byte[] toObjectArray(byte[] arr)

toObjectArray

public static Short[] toObjectArray(short[] arr)

toObjectArray

public static Integer[] toObjectArray(int[] arr)

toObjectArray

public static Long[] toObjectArray(long[] arr)

toObjectArray

public static Float[] toObjectArray(float[] arr)

toObjectArray

public static Double[] toObjectArray(double[] arr)

ensureCapacity

public static byte[] ensureCapacity(byte[] array,
                                    int capacity)

ensureCapacity

public static char[] ensureCapacity(char[] array,
                                    int capacity)


Copyright © 2018. All rights reserved.