jlibs.core.util
Class CollectionUtil

java.lang.Object
  extended by jlibs.core.util.CollectionUtil

public class CollectionUtil
extends Object

Author:
Santhosh Kumar T

Constructor Summary
CollectionUtil()
           
 
Method Summary
static
<E,T extends E>
void
add(List<E> list, int index, T item)
          Adds the given item to the list at specified index.
static
<E,T extends E>
Collection<E>
addAll(Collection<E> c, T... array)
          Adds objects in array to the given collection
static
<T> List<T>
filter(Collection<T> c, Filter<T> filter)
          Returns List with elements from given collections which are selected by specified filter
static
<K,V> K
getKey(Map<K,V> map, V value)
          returns key whose value matches with specified value from given map if the given map contains multiple keys mapped to specified value, it returns first key encountered
static Properties readProperties(InputStream is, Properties props)
          Reads Properties from given inputStream and returns it.
static
<E,T extends E>
Collection<E>
removeAll(Collection<E> c, T... array)
          Removes objects in array to the given collection
static boolean[] toBooleanArray(Collection<Boolean> c)
           
static byte[] toByteArray(Collection<? extends Number> c)
           
static double[] toDoubleArray(Collection<? extends Number> c)
           
static float[] toFloatArray(Collection<? extends Number> c)
           
static int[] toIntArray(Collection<? extends Number> c)
           
static long[] toLongArray(Collection<? extends Number> c)
           
static short[] toShortArray(Collection<? extends Number> c)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionUtil

public CollectionUtil()
Method Detail

readProperties

public static Properties readProperties(InputStream is,
                                        Properties props)
                                 throws IOException
Reads Properties from given inputStream and returns it. NOTE: the given stream is closed by this method

Throws:
IOException

addAll

public static <E,T extends E> Collection<E> addAll(Collection<E> c,
                                                   T... array)
Adds objects in array to the given collection

Returns:
the same collection which is passed as argument

removeAll

public static <E,T extends E> Collection<E> removeAll(Collection<E> c,
                                                      T... array)
Removes objects in array to the given collection

Returns:
the same collection which is passed as argument

add

public static <E,T extends E> void add(List<E> list,
                                       int index,
                                       T item)
Adds the given item to the list at specified index. if index is greater than list size, it simply appends to the list.


filter

public static <T> List<T> filter(Collection<T> c,
                                 Filter<T> filter)
Returns List with elements from given collections which are selected by specified filter


getKey

public static <K,V> K getKey(Map<K,V> map,
                             V value)
returns key whose value matches with specified value from given map if the given map contains multiple keys mapped to specified value, it returns first key encountered


toBooleanArray

public static boolean[] toBooleanArray(Collection<Boolean> c)

toIntArray

public static int[] toIntArray(Collection<? extends Number> c)

toLongArray

public static long[] toLongArray(Collection<? extends Number> c)

toFloatArray

public static float[] toFloatArray(Collection<? extends Number> c)

toDoubleArray

public static double[] toDoubleArray(Collection<? extends Number> c)

toByteArray

public static byte[] toByteArray(Collection<? extends Number> c)

toShortArray

public static short[] toShortArray(Collection<? extends Number> c)


Copyright © 2018. All rights reserved.