|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jopendocument.util.CollectionUtils
public class CollectionUtils
Une classe regroupant des méthodes utilitaires pour les collections.
| Constructor Summary | |
|---|---|
CollectionUtils()
|
|
| Method Summary | ||
|---|---|---|
static
|
addIfNotPresent(Map<K,V> map,
Map<? extends K,? extends V> toAdd)
Add entries from toAdd into map only if the key is not already
present. |
|
static
|
addTo(Iterator<T> iter,
C c)
|
|
static List<int[]> |
aggregate(Collection<? extends Number> ints)
Aggregate a list of ints into a list of intervals. |
|
static
|
castToList(U[] array,
Class<T> clazz)
Convert an array to a list of a different type. |
|
static
|
contains(Set<T> col1,
Set<T> col2)
Test whether col2 is contained in col1. |
|
static
|
containsAny(C coll1,
C coll2)
|
|
static
|
createIdentitySet(T... items)
|
|
static
|
createMap(Collection<? extends K> keys)
Creates a map with null values. |
|
static
|
createMap(K key,
V val,
K key2,
V val2)
|
|
static
|
createMap(K key,
V val,
K key2,
V val2,
K key3,
V val3)
|
|
static
|
createSet(T... items)
|
|
static void |
delete(List<?> l,
int from)
Deletes the tail of a list. |
|
static void |
delete(List<?> l,
int from,
int to)
Deletes a slice of a list. |
|
static
|
emptyIdentitySet()
|
|
static
|
emptyIterator()
|
|
static
|
equals(List<A> a,
List<B> b,
boolean fromEnd,
ITransformer<A,B> transf)
The number of equals item between a and b, starting from the choosen end. |
|
static
|
equalsFromEnd(List<T> a,
List<T> b)
The number of equals item between a and b, starting from the end. |
|
static
|
equalsFromStart(List<T> a,
List<T> b)
|
|
static
|
exists(Collection<T> collection,
IPredicate<? super T> predicate)
|
|
static
|
fillMap(M m,
Collection<? extends K> keys)
Fills a map with null values. |
|
static
|
filter(Collection<T> collection,
IPredicate<? super T> predicate)
|
|
static
|
filterAndTransform(Collection<T> c,
IPredicate<? super T> filterBefore,
ITransformer<? super T,U> transf,
C res)
|
|
static
|
filterTransformAndFilter(Collection<T> c,
IPredicate<? super T> filterBefore,
ITransformer<? super T,U> transf,
IPredicate<? super U> filterAfter,
C res)
|
|
static List |
flatten(Map hierarchy)
Permet d'aplatir une hiérarchie. |
|
static List |
flatten(Map hierarchy,
org.apache.commons.collections.Transformer itemTransf)
Permet d'aplatir une hiérarchie. |
|
static
|
getFirst(Collection<T> l)
|
|
static
|
getFirst(List<T> l)
Return the first item of l if it isn't empty, otherwise null. |
|
static
|
getIndexesChanged(List<E> oldList,
List<E> newList)
Compute the index that have changed (added or removed) between 2 lists. |
|
static
|
getLast(List<T> l)
Return the last item of l if it isn't empty, otherwise null. |
|
static
|
getListIterator(List<T> l,
boolean reversed)
|
|
static
|
getNoExn(List<T> l,
int index)
Return the item no index of l if it exists, otherwise
null. |
|
static
|
getSole(Collection<T> l)
|
|
static
|
getSole(List<T> l)
Return the first item of l if it's the only one, otherwise null. |
|
static int |
getValidIndex(List<?> l,
int i)
Return an index between 0 and l.size() inclusive. |
|
static int |
getValidIndex(List<?> l,
int i,
boolean strict)
|
|
static
|
inter(List<Set<T>> sets)
|
|
static
|
inter(Set<T>... sets)
|
|
static
|
inter(Set<T> a,
Set<T> b)
Compute the intersection of a and b. |
|
static
|
intersection(Collection<T> a,
Collection<T> b)
|
|
static
|
interSubtype(Set<? extends T> a,
Set<? extends T> b)
|
|
static
|
iterate(Collection<T> c,
IClosure<T> cl)
|
|
static
|
iterate(Collection<T> c,
IPredicate<? super T> filterBefore,
IClosure<T> cl)
|
|
static
|
join(Collection<E> c,
String sep,
ITransformer<? super E,?> tf)
Concatene une collection. |
|
static
|
join(Collection<T> c,
String sep)
Concatene une collection en appelant simplement toString() sur chaque élément. |
|
static
|
mapToLists(Map<K,V> map)
Convertit une map en 2 listes, une pour les clefs, une pour les valeurs. |
|
static SortedMap |
organize(Collection col,
List<? extends org.apache.commons.collections.Transformer> propExtractors,
List<? extends Comparator> propComp,
Comparator itemOrdering)
Permet d'organiser une collection en une hiérarchie à l'aide de Map. |
|
static
|
reverseListIterator(ListIterator<T> listIter)
|
|
static
|
select(Collection<T> a,
IPredicate<? super T> pred)
|
|
static
|
select(Collection<T> a,
IPredicate<? super T> pred,
C b)
|
|
static List<String> |
split(String s)
|
|
static List<String> |
split(String s,
Pattern pattern)
Split a string into a list based on a pattern. |
|
static List<String> |
split(String s,
String sep)
|
|
static
|
substract(Collection<T> a,
Collection<? extends T> b)
|
|
static
|
subtract(Collection<T> a,
Collection<? extends T> b)
|
|
static
|
toArrayList(Iterator<T> iter,
int estimatedSize)
|
|
static
|
toIdentitySet(Collection<T> items)
Return an IdentitySet consisting of items. |
|
static
|
toLinkedList(Iterator<T> iter)
|
|
static
|
transform(Collection<T> c,
ITransformer<? super T,U> transf,
C res)
|
|
static
|
transformAndFilter(Collection<T> c,
ITransformer<? super T,U> transf,
IPredicate<? super U> filterAfter,
C res)
|
|
static
|
union(Set<? extends T> a,
Set<? extends T> b)
Returns a Set containing the union of the given Sets. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CollectionUtils()
| Method Detail |
|---|
public static final <E> String join(Collection<E> c,
String sep,
ITransformer<? super E,?> tf)
E - type of itemsc - la collection a concaténer.sep - le séparateur entre chaque élément.tf - la transformation à appliquer à chaque élément.
sep.
public static <T> String join(Collection<T> c,
String sep)
T - type of collectionc - la collection a concaténer.sep - le séparateur entre chaque élément.
sep.join(Collection, String, ITransformer)
public static <T,U,C extends Collection<? super U>> C transform(Collection<T> c,
ITransformer<? super T,U> transf,
C res)
public static <T,U,C extends Collection<? super U>> C transformAndFilter(Collection<T> c,
ITransformer<? super T,U> transf,
IPredicate<? super U> filterAfter,
C res)
public static <T,U,C extends Collection<? super U>> C filterAndTransform(Collection<T> c,
IPredicate<? super T> filterBefore,
ITransformer<? super T,U> transf,
C res)
public static <T,U,C extends Collection<? super U>> C filterTransformAndFilter(Collection<T> c,
IPredicate<? super T> filterBefore,
ITransformer<? super T,U> transf,
IPredicate<? super U> filterAfter,
C res)
public static <T> void iterate(Collection<T> c,
IClosure<T> cl)
public static <T> void iterate(Collection<T> c,
IPredicate<? super T> filterBefore,
IClosure<T> cl)
public static List<String> split(String s)
public static List<String> split(String s,
String sep)
public static List<String> split(String s,
Pattern pattern)
s - the string to split.pattern - the pattern where to cut the string.
s is "".
public static int getValidIndex(List<?> l,
int i)
0 and l.size() inclusive. If i
is negative, it is added to l.size() (but bounded to 0), ie for a list of 3
items, -1 is the index of the last item ; -3 and -4 are both the first. If i is
greater than l.size() then l.size() is returned.
a b c a b c
-3 -2 -1 0 1 2 3
l - the list, eg a list of 3 items.i - the virtual index, eg -1.
public static int getValidIndex(List<?> l,
int i,
boolean strict)
public static void delete(List<?> l,
int from,
int to)
getValidIndex(List, int) to allow
delete(l, 0, -1) to clear l or delete(l, -2, -2) to remove the penultimate item.
l - the list to delete from.from - the first index to be removed (inclusive).to - the last index to be removed (inclusive).
public static void delete(List<?> l,
int from)
from.
l - the list to delete from.from - the first index to be removed (inclusive).
public static <T> void filter(Collection<T> collection,
IPredicate<? super T> predicate)
public static <T> boolean exists(Collection<T> collection,
IPredicate<? super T> predicate)
public static final SortedMap organize(Collection col,
List<? extends org.apache.commons.collections.Transformer> propExtractors,
List<? extends Comparator> propComp,
Comparator itemOrdering)
Col = [
Obs1(bat=BAT A, local=A1, num=1),
Obs2(bat=BAT B, local=B1, num=2),
Obs3(bat=BAT B, local=B2, num=3),
Obs4(bat=BAT B, local=B2, num=4)
]
ainsi que deux extracteurs pour trouver le batiment et le local, et enfin itemOrdering suivant le numero, on a
{ BAT A => {A1 => {Obs1}}, {BAT B => {B1 => {Obs2}, B2 => {Obs3, Obs4}}}}.
- Parameters:
col - la collection à organiser.propExtractors - les extracteurs de propriétes.propComp - les Comparator pour les propriétés renvoyées par les extracteurs, peut être
null si les propriétés sont des Comparable.itemOrdering - comment ordonner les éléments dans la dernière tranche, peut être
null si les éléments sont des Comparable.
- Returns:
- une hiérarchie de SortedMap et en dernier un SortedSet.
public static final List flatten(Map hierarchy,
org.apache.commons.collections.Transformer itemTransf)
A-
A1
A2
B-
B1
B11
B12
devient [A, A1, A2, B, B1, B11, B12].
hierarchy - la hiérarchie à aplatir.itemTransf - la transformation à faire sur les feuilles.
public static final List flatten(Map hierarchy)
hierarchy - la hiérarchie à aplatir.
public static <K,V> Tuple2<List<K>,List<V>> mapToLists(Map<K,V> map)
K - type of keyV - type of valuemap - la Map à convertir.
public static <K,V> Map<K,V> addIfNotPresent(Map<K,V> map,
Map<? extends K,? extends V> toAdd)
toAdd into map only if the key is not already
present.
K - type of keys.V - type of values.map - the map to fill.toAdd - the entries to add.
map.
public static <E> List<Integer> getIndexesChanged(List<E> oldList,
List<E> newList)
E - type of itemoldList - the first list.newList - the second list.
IllegalStateException - if one list is not a sublist of the other.public static List<int[]> aggregate(Collection<? extends Number> ints)
ints - a list of Integer strictly increasing.
public static <T> Set<T> contains(Set<T> col1,
Set<T> col2)
T - type of collectioncol1 - the first collectioncol2 - the second collection
null if col1 contains all of col2, else return the extra items that col2
have.
public static <C extends Collection<?>> boolean containsAny(C coll1,
C coll2)
public static <U,T extends U> List<T> castToList(U[] array,
Class<T> clazz)
throws ClassCastException
U - type of arrayT - type of listarray - the array to convert, eg new Object[]{"a", "b"}.clazz - the class of the list items, eg String.class.
array into a list, eg ["a", "b"].
ClassCastException - if some item of array is not a T.
public static <T> int equalsFromEnd(List<T> a,
List<T> b)
T - type of items.a - the first list, eg [a, b, c].b - the second list, eg [a, null, z, c].
public static <T> int equalsFromStart(List<T> a,
List<T> b)
public static final <A,B> int equals(List<A> a,
List<B> b,
boolean fromEnd,
ITransformer<A,B> transf)
A - type of the first list.B - type of the second list.a - the first list, eg [a, b, c].b - the second list, eg [a, null, z, c].fromEnd - whether search from the start or the end, true.transf - how items of a should be transformed before being compared, can be
null.
public static <T> Collection<T> select(Collection<T> a,
IPredicate<? super T> pred)
public static <T,C extends Collection<? super T>> C select(Collection<T> a,
IPredicate<? super T> pred,
C b)
public static <T> Collection<T> intersection(Collection<T> a,
Collection<T> b)
public static <T> Set<T> inter(Set<T> a,
Set<T> b)
nulls are ignored : x ∩ null = x.
T - type of collection.a - the first set, can be null.b - the second set, can be null.
public static <T> Set<? extends T> interSubtype(Set<? extends T> a,
Set<? extends T> b)
public static <T> Set<T> inter(Set<T>... sets)
public static <T> Set<T> inter(List<Set<T>> sets)
public static <T> Set<T> union(Set<? extends T> a,
Set<? extends T> b)
Set containing the union of the given Sets.
T - type of items.a - the first set, must not be nullb - the second set, must not be null
public static <T> Collection<T> subtract(Collection<T> a,
Collection<? extends T> b)
public static <T> Collection<T> substract(Collection<T> a,
Collection<? extends T> b)
public static <T> T getSole(List<T> l)
l if it's the only one, otherwise null.
T - type of list.l - the list.
l or null.public static <T> T getSole(Collection<T> l)
public static <T> T getFirst(Collection<T> l)
public static <T> T getFirst(List<T> l)
l if it isn't empty, otherwise null.
T - type of list.l - the list.
l or null.public static <T> T getLast(List<T> l)
l if it isn't empty, otherwise null.
T - type of list.l - the list.
l or null.
public static <T> T getNoExn(List<T> l,
int index)
index of l if it exists, otherwise
null.
T - type of list.l - the list.index - the wanted index.
l or null.public static <T> Iterator<T> emptyIterator()
public static <T> LinkedList<T> toLinkedList(Iterator<T> iter)
public static <T> ArrayList<T> toArrayList(Iterator<T> iter,
int estimatedSize)
public static <T,C extends Collection<? super T>> C addTo(Iterator<T> iter,
C c)
public static <T> ListIterator<T> getListIterator(List<T> l,
boolean reversed)
public static <T> ListIterator<T> reverseListIterator(ListIterator<T> listIter)
public static <T> Set<T> createSet(T... items)
public static <T> IdentitySet<T> createIdentitySet(T... items)
public static <T> Set<T> toIdentitySet(Collection<T> items)
IdentitySet consisting of items.
items - the collection whose elements are to be in the result.
items if it's already an identity set.public static <T> IdentitySet<T> emptyIdentitySet()
public static <K,V> Map<K,V> createMap(K key,
V val,
K key2,
V val2)
public static <K,V> Map<K,V> createMap(K key,
V val,
K key2,
V val2,
K key3,
V val3)
public static <K,V> Map<K,V> createMap(Collection<? extends K> keys)
K - type of key.V - type of value.keys - the keys of the map.
keys is a List it will be ordered.
public static <K,V,M extends Map<K,V>> M fillMap(M m,
Collection<? extends K> keys)
K - type of key.V - type of value.M - type of map.m - the map to fill.keys - the keys to add.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||