net.sf.doolin.util.collection
Class ListUtils

java.lang.Object
  extended by net.sf.doolin.util.collection.ListUtils

public class ListUtils
extends Object

This class provides utility methods for collection conversions.

Author:
Damien Coraboeuf

Method Summary
static
<T,K,V> Map<K,V>
convertMap(Map<K,? extends T> map, ItemConverter<T,V> valueExtractor)
          Deprecated. Use Maps.transformValues(Map, com.google.common.base.Function) instead.
static
<T,K,V> Map<K,V>
convertMap(Map<K,? extends T> map, String property)
          Converts values from a source map to a target map, by getting a property from the source value.
static
<T> List<T>
extractList(Collection<? extends T> list, com.google.common.base.Predicate<T> predicate)
          Extracts a sub-list by evaluating a Predicate on the source list
static
<E> E
find(List<? extends E> list, com.google.common.base.Predicate<E> predicate)
          Finds the first element in a list which is evaluated to true by a Predicate.
static
<T,K,V> Map<K,V>
indexMap(Collection<? extends T> values, com.google.common.base.Function<T,K> keyExtractor, com.google.common.base.Function<T,V> valueExtractor)
          Converts a list to a map by extracting keys and values from each element of the list
static
<T,K,V> Map<K,V>
indexMap(Collection<? extends T> values, ItemConverter<T,K> keyExtractor, ItemConverter<T,V> valueExtractor)
          Deprecated. Use indexMap(Collection, Function, Function) instead
static
<T,K,V> Map<K,V>
indexMap(Collection<? extends T> list, String keyProperty, String valueProperty)
          Converts a list to a map by extracting keys and values from each element of the list using a property
static
<K,V> Map<K,V>
indexMap(List<? extends V> values, ItemConverter<V,K> keyExtractor)
          Deprecated. Use Maps.uniqueIndex(Iterable, Function) instead
static
<K,V> Map<K,V>
indexMap(List<V> values, String propertyName)
          Converts a list to a map by extracting keys from each element of the list using a property name.
static
<E> int
indexOf(List<? extends E> list, com.google.common.base.Predicate<E> predicate)
          Returns the index of the first element of the list that is evaluated to true by the predicate.
static
<T> List<T>
sublist(List<? extends T> list, int[] indexes)
          Creates a sub-list that contains items referenced by a list of indexes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

convertMap

@Deprecated
public static <T,K,V> Map<K,V> convertMap(Map<K,? extends T> map,
                                                     ItemConverter<T,V> valueExtractor)
Deprecated. Use Maps.transformValues(Map, com.google.common.base.Function) instead.

Converts values from a source map to a target map using a converter for the values.

Type Parameters:
T - Type of the value in the source map
K - Type of key for both maps
V - Type of value for the target map
Parameters:
map - Source map
valueExtractor - Converter for the value
Returns:
Target map

convertMap

public static <T,K,V> Map<K,V> convertMap(Map<K,? extends T> map,
                                          String property)
Converts values from a source map to a target map, by getting a property from the source value.

Type Parameters:
T - Type of the value in the source map
K - Type of key for both maps
V - Type of value for the target map
Parameters:
map - Source map
property - Property to take from the source value
Returns:
Target map
See Also:
PropertyItemConverter

extractList

public static <T> List<T> extractList(Collection<? extends T> list,
                                      com.google.common.base.Predicate<T> predicate)
Extracts a sub-list by evaluating a Predicate on the source list

Type Parameters:
T - Type of object in the list
Parameters:
list - Source list
predicate - Predicate to evaluate
Returns:
List of objects in the source list the predicate has returned true for

find

public static <E> E find(List<? extends E> list,
                         com.google.common.base.Predicate<E> predicate)
Finds the first element in a list which is evaluated to true by a Predicate.

Type Parameters:
E - Type of item in the list
Parameters:
list - List
predicate - Predicate to apply
Returns:
First found item or null if none is found

indexMap

public static <T,K,V> Map<K,V> indexMap(Collection<? extends T> values,
                                        com.google.common.base.Function<T,K> keyExtractor,
                                        com.google.common.base.Function<T,V> valueExtractor)
Converts a list to a map by extracting keys and values from each element of the list

Type Parameters:
T - Type of element in the list
K - Type for the key
V - Type for the value
Parameters:
values - Source collection
keyExtractor - Converter for the key
valueExtractor - Converter for the value
Returns:
Map

indexMap

@Deprecated
public static <T,K,V> Map<K,V> indexMap(Collection<? extends T> values,
                                                   ItemConverter<T,K> keyExtractor,
                                                   ItemConverter<T,V> valueExtractor)
Deprecated. Use indexMap(Collection, Function, Function) instead

Converts a list to a map by extracting keys and values from each element of the list

Type Parameters:
T - Type of element in the list
K - Type for the key
V - Type for the value
Parameters:
values - Source collection
keyExtractor - Converter for the key
valueExtractor - Converter for the value
Returns:
Map

indexMap

public static <T,K,V> Map<K,V> indexMap(Collection<? extends T> list,
                                        String keyProperty,
                                        String valueProperty)
Converts a list to a map by extracting keys and values from each element of the list using a property

Type Parameters:
T - Type of element in the list
K - Type for the key
V - Type for the value
Parameters:
list - Source collection
keyProperty - Property for the key
valueProperty - Property for the value
Returns:
Map

indexMap

@Deprecated
public static <K,V> Map<K,V> indexMap(List<? extends V> values,
                                                 ItemConverter<V,K> keyExtractor)
Deprecated. Use Maps.uniqueIndex(Iterable, Function) instead

Converts a list to a map by extracting keys from each element of the list. The values for the map are the elements of the list.

Type Parameters:
K - Type for the key
V - Type for the list and the map value
Parameters:
values - Source collection
keyExtractor - Converter for the key
Returns:
Map
See Also:
IdentityConverter

indexMap

public static <K,V> Map<K,V> indexMap(List<V> values,
                                      String propertyName)
Converts a list to a map by extracting keys from each element of the list using a property name. The values for the map are the elements of the list.

Type Parameters:
K - Type for the key
V - Type for the list and the map value
Parameters:
values - Source collection
propertyName - Property for the key
Returns:
Map

indexOf

public static <E> int indexOf(List<? extends E> list,
                              com.google.common.base.Predicate<E> predicate)
Returns the index of the first element of the list that is evaluated to true by the predicate.

Type Parameters:
E - Type of object in the list
Parameters:
list - List
predicate - Predicate to apply
Returns:
Index of the first positive element or -1 if not found

sublist

public static <T> List<T> sublist(List<? extends T> list,
                                  int[] indexes)
Creates a sub-list that contains items referenced by a list of indexes.

Type Parameters:
T - Type of object in the list
Parameters:
list - Source list
indexes - List of indexes in the source list
Returns:
Sub-list


Copyright © 2011. All Rights Reserved.