public class ECollections
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
static <T> EList<T> |
asEList(java.util.List<T> list)
Returns an EList view of the specified list.
|
static <T> EList<T> |
asEList(T... elements)
Returns a mutable, fixed-size, random access EList backed by the given array.
|
static <K,V> EMap<K,V> |
asEMap(java.util.Map<K,V> map)
Returns a mutable EMap view of the specified map.
|
static <T> EList<T> |
emptyEList()
Returns an empty unmodifiable list.
|
static <K,V> EMap<K,V> |
emptyEMap()
Returns an empty unmodifiable map.
|
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 <T> BasicEList<T> |
newBasicEList()
Creates an empty mutable
BasicEList> . |
static <T> BasicEList<T> |
newBasicEList(java.lang.Iterable<? extends T> iterable)
Creates a mutable
BasicEList> containing the given elements. |
static <T> BasicEList<T> |
newBasicEList(java.util.Iterator<? extends T> iterator)
Creates a mutable
BasicEList> containing the given elements. |
static <T> BasicEList<T> |
newBasicEList(T... elements)
Creates a mutable
BasicEList> containing the given elements. |
static <T> BasicEList<T> |
newBasicEListWithCapacity(int capacity)
Creates an empty mutable
BasicEList> with the given capacity. |
static <T> BasicEList<T> |
newBasicEListWithExpectedSize(int estimatedSize)
Creates an empty mutable
BasicEList> with a capacity large enough to hold a bit more than the estimated number of elements. |
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 <T> EList<T> |
singletonEList(T o)
Returns an immutable list containing just the one object.
|
static <K,V> EMap<K,V> |
singletonEMap(K key,
V value)
Returns an immutable map containing just the one key/value mapping.
|
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> InterningSet<T> |
synchronizedInterningSet(InterningSet<T> set)
Returns a synchronized, i.e., thread-safe view of the interning set.
|
static <T> EList<T> |
toEList(java.lang.Iterable<? extends T> iterable)
Returns a list containing the elements of the given iterable.
|
static <T> EList<T> |
toEList(java.util.Iterator<? extends T> iterator)
Returns a mutable list containing the elements of the given iterator.
|
static <T> EList<T> |
unmodifiableEList(EList<? extends T> list)
Returns an unmodifiable view of the list.
|
static <T> EList<T> |
unmodifiableEList(java.util.List<? 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.
|
public static final EList<?> EMPTY_ELIST
public static final EMap<?,?> EMPTY_EMAP
public static <T> void move(java.util.List<T> list, int newPosition, T object)
list
- newPosition
- the position of the object after the move.object
- the object to move.public static <T> T move(java.util.List<T> list, int targetIndex, int sourceIndex)
list
- targetIndex
- the position of the object after the move.sourceIndex
- the position of the object before the move.public static void reverse(EList<?> list)
public static int indexOf(java.util.List<?> list, java.lang.Object o, int fromIndex)
list
- o
- an object (can be null)fromIndex
- public static void sort(EList<?> list)
Collections.sort(java.util.List)
to
avoid errors when sorting unique lists.public static <T> void sort(EList<T> list, java.util.Comparator<? super T> comparator)
Collections.sort(java.util.List, java.util.Comparator)
to
avoid errors when sorting unique lists.public static <T> void setEList(EList<T> eList, java.util.List<? extends T> prototypeList)
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.eList
- the list to set.prototypeList
- the list representing the desired content and order.public static <T> EList<T> unmodifiableEList(EList<? extends T> list)
public static <K,V> EMap<K,V> unmodifiableEMap(EMap<? extends K,? extends V> map)
public static <T> EList<T> emptyEList()
public static <K,V> EMap<K,V> emptyEMap()
public static <T> EList<T> singletonEList(T o)
public static <K,V> EMap<K,V> singletonEMap(K key, V value)
public static <T> EList<T> toEList(java.util.Iterator<? extends T> iterator)
public static <T> EList<T> toEList(java.lang.Iterable<? extends T> iterable)
EList
, that list itself is returned.
If the iterable is of type List
, a view
of that list is returned;
all changes to view are reflected in the underlying list and all changes to the underlying list are reflected in the view.
In all other cases, the result is a copy
of the iterable.public static <K,V> EMap<K,V> asEMap(java.util.Map<K,V> map)
EList.move(int, int)
, EList.move(int, Object)
, List.add(int, Object)
, and List.addAll(int, Collection)
,
i.e., the methods that expect to control the exact order of entries in the map's entry set,
are not supported and throw UnsupportedOperationException
.
All other changes to the EMap write through to the underlying map.map
- the map to which the EMap delegates.public static <T> EList<T> asEList(java.util.List<T> list)
list
- the list to which the EList delegates.public static <T> EList<T> asEList(T... elements)
UnsupportedOperationException
.
This is analogous to Arrays.asList(Object...)
with the advantage that you can move
objects;
hence you can sort
without using List.add(int, Object)
and List.remove(int)
.elements
- the array to which the EList delegates.public static <T> EList<T> unmodifiableEList(java.util.List<? extends T> list)
public static <T> BasicEList<T> newBasicEList()
BasicEList>
.BasicEList>
.public static <T> BasicEList<T> newBasicEListWithCapacity(int capacity)
BasicEList>
with the given capacity.BasicEList>
.public static <T> BasicEList<T> newBasicEListWithExpectedSize(int estimatedSize)
BasicEList>
with a capacity large enough to hold a bit more than the estimated number of elements.
If you know the exact size, use newBasicEListWithCapacity(int)
instead.BasicEList>
.public static <T> BasicEList<T> newBasicEList(T... elements)
BasicEList>
containing the given elements.BasicEList>
containing the given elements.public static <T> BasicEList<T> newBasicEList(java.util.Iterator<? extends T> iterator)
BasicEList>
containing the given elements.BasicEList>
containing the given elements.public static <T> BasicEList<T> newBasicEList(java.lang.Iterable<? extends T> iterable)
BasicEList>
containing the given elements.BasicEList>
containing the given elements.public static <T> InterningSet<T> synchronizedInterningSet(InterningSet<T> set)
set
- the interning set to which this interning set delegates.