org.eclipse.emf.common.util
Class ECollections

java.lang.Object
  extended by org.eclipse.emf.common.util.ECollections

public class ECollections
extends java.lang.Object

Support for empty and unmodifiable ELists.


Field Summary
static EList<?> EMPTY_ELIST
          An unmodifiable empty list with an efficient reusable iterator.
static EMap<?,?> EMPTY_EMAP
          An unmodifiable empty map with an efficient reusable iterator.
 
Method Summary
static
<T> EList<T>
emptyEList()
           
static
<K,V> EMap<K,V>
emptyEMap()
           
static int indexOf(java.util.List<?> list, java.lang.Object o, int fromIndex)
          Searches for the first occurrence of the given argument in list starting from a specified index.
static
<T> T
move(java.util.List<T> list, int targetIndex, int sourceIndex)
          Moves the object from the old position to the new position.
static
<T> void
move(java.util.List<T> list, int newPosition, T object)
          Moves the object to the new position, if is in the list.
static void reverse(EList<?> list)
          Reverses the order of the elements in the specified EList.
static
<T> void
setEList(EList<T> eList, java.util.List<? extends T> prototypeList)
          Sets the eList's contents and order to be exactly that of the prototype list.
static void sort(EList<?> list)
          Sorts the specified list.
static
<T> void
sort(EList<T> list, java.util.Comparator<? super T> comparator)
          Sorts the specified list based on the order defined by the specified comparator.
static
<T> EList<T>
unmodifiableEList(EList<? extends T> list)
          Returns an unmodifiable view of the list.
static
<K,V> EMap<K,V>
unmodifiableEMap(EMap<? extends K,? extends V> map)
          Returns an unmodifiable view of the map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ELIST

public static final EList<?> EMPTY_ELIST
An unmodifiable empty list with an efficient reusable iterator.


EMPTY_EMAP

public static final EMap<?,?> EMPTY_EMAP
An unmodifiable empty map with an efficient reusable iterator.

Method Detail

move

public static <T> void move(java.util.List<T> list,
                            int newPosition,
                            T object)
Moves the object to the new position, if is in the list.

Parameters:
list -
newPosition - the position of the object after the move.
object - the object to move.

move

public static <T> T move(java.util.List<T> list,
                         int targetIndex,
                         int sourceIndex)
Moves the object from the old position to the new position.

Parameters:
list -
targetIndex - the position of the object after the move.
sourceIndex - the position of the object before the move.
Returns:
the moved object

reverse

public static void reverse(EList<?> list)
Reverses the order of the elements in the specified EList.


indexOf

public static int indexOf(java.util.List<?> list,
                          java.lang.Object o,
                          int fromIndex)
Searches for the first occurrence of the given argument in list starting from a specified index. The equality is tested using the operator == and the equals method.

Parameters:
list -
o - an object (can be null)
fromIndex -
Returns:
the index of the first occurrence of the argument in this list (where index>=fromIndex); returns -1 if the object is not found.
Since:
2.1.0

sort

public static void sort(EList<?> list)
Sorts the specified list. Use this method instead of Collections.sort(java.util.List) to avoid errors when sorting unique lists.

Since:
2.1.0

sort

public static <T> void sort(EList<T> list,
                            java.util.Comparator<? super T> comparator)
Sorts the specified list based on the order defined by the specified comparator. Use this method instead of Collections.sort(java.util.List, java.util.Comparator) to avoid errors when sorting unique lists.

Since:
2.1.0

setEList

public static <T> void setEList(EList<T> eList,
                                java.util.List<? extends T> prototypeList)
Sets the eList's contents and order to be exactly that of the prototype list. This implementation minimizes the number of notifications the operation will produce. Objects already in the list will be moved, missing objects will be added, and extra objects will be removed. If eList's contents and order are already exactly that of the prototype list, no change will be made.

Parameters:
eList - the list to set.
prototypeList - the list representing the desired content and order.

unmodifiableEList

public static <T> EList<T> unmodifiableEList(EList<? extends T> list)
Returns an unmodifiable view of the list.

Returns:
an unmodifiable view of the list.

unmodifiableEMap

public static <K,V> EMap<K,V> unmodifiableEMap(EMap<? extends K,? extends V> map)
Returns an unmodifiable view of the map.

Returns:
an unmodifiable view of the map.

emptyEList

public static <T> EList<T> emptyEList()

emptyEMap

public static <K,V> EMap<K,V> emptyEMap()

Copyright 2001-2006 IBM Corporation and others.
All Rights Reserved.