public class ActiveList<T>
extends java.util.AbstractList<T>
Constructor and Description |
---|
ActiveList(java.util.List<T> wrapped)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
T element)
Inserts the specified element at the specified position in this list
(optional operation).
|
boolean |
add(T t)
Appends the specified element to the end of this list (optional
operation).
|
void |
addActiveListListener(ActiveListListener<? super T> listener)
Add an active list listener.
|
void |
clear()
Removes all of the elements from this list (optional operation).
|
boolean |
contains(java.lang.Object o)
Returns true if this list contains the specified element.
|
boolean |
containsAll(java.util.Collection<?> c)
Returns true if this list contains all of the elements of the
specified collection.
|
T |
get(int index)
Returns the element at the specified position in this list.
|
int |
indexOf(java.lang.Object o)
Returns the index of the first occurrence of the specified element
in this list, or -1 if this list does not contain the element.
|
boolean |
isEmpty()
Returns true if this list contains no elements.
|
int |
lastIndexOf(java.lang.Object o)
Returns the index of the last occurrence of the specified element
in this list, or -1 if this list does not contain the element.
|
T |
remove(int index)
Removes the element at the specified position in this list (optional
operation).
|
boolean |
remove(java.lang.Object o)
Removes the first occurrence of the specified element from this list,
if it is present (optional operation).
|
void |
removeActiveListListener(ActiveListListener<? super T> listener)
Remove an active list listener.
|
T |
set(int index,
T element)
Replaces the element at the specified position in this list with the
specified element (optional operation).
|
int |
size()
Returns the number of elements in this list.
|
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this list in proper
sequence (from first to last element).
|
<T1> T1[] |
toArray(T1[] a)
Returns an array containing all of the elements in this list in
proper sequence (from first to last element); the runtime type of
the returned array is that of the specified array.
|
static <S> ActiveList<S> |
wrap(java.util.List<S> basicList)
Wrap a basic list to make it active.
|
addAll, equals, hashCode, iterator, listIterator, listIterator, removeRange, subList
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
@NotNull public static <S> ActiveList<S> wrap(@NotNull java.util.List<S> basicList)
S
- list typebasicList
- basic list, don't use directly any further or add a clone here!public void addActiveListListener(@NotNull ActiveListListener<? super T> listener)
listener
- listener to addpublic void removeActiveListListener(@NotNull ActiveListListener<? super T> listener)
listener
- listener to removepublic int size()
public boolean isEmpty()
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<T>
contains
in interface java.util.List<T>
contains
in class java.util.AbstractCollection<T>
o
- element whose presence in this list is to be testedjava.lang.ClassCastException
- if the type of the specified element
is incompatible with this list (optional)java.lang.NullPointerException
- if the specified element is null and this
list does not permit null elements (optional)@NotNull public java.lang.Object[] toArray()
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
@NotNull public <T1> T1[] toArray(@NotNull T1[] a)
If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the list is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)
Like the toArray()
method, this method acts as bridge between
array-based and collection-based APIs. Further, this method allows
precise control over the runtime type of the output array, and may,
under certain circumstances, be used to save allocation costs.
Suppose x is a list known to contain only strings. The following code can be used to dump the list into a newly allocated array of String:
String[] y = x.toArray(new String[0]);Note that toArray(new Object[0]) is identical in function to toArray().
toArray
in interface java.util.Collection<T>
toArray
in interface java.util.List<T>
toArray
in class java.util.AbstractCollection<T>
a
- the array into which the elements of this list are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.java.lang.ArrayStoreException
- if the runtime type of the specified array
is not a supertype of the runtime type of every element in
this listjava.lang.NullPointerException
- if the specified array is nullpublic boolean add(T t)
Lists that support this operation may place limitations on what elements may be added to this list. In particular, some lists will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. List classes should clearly specify in their documentation any restrictions on what elements may be added.
add
in interface java.util.Collection<T>
add
in interface java.util.List<T>
add
in class java.util.AbstractList<T>
t
- element to be appended to this listCollection.add(E)
)java.lang.UnsupportedOperationException
- if the add operation
is not supported by this listjava.lang.ClassCastException
- if the class of the specified element
prevents it from being added to this listjava.lang.NullPointerException
- if the specified element is null and this
list does not permit null elementsjava.lang.IllegalArgumentException
- if some property of this element
prevents it from being added to this listpublic boolean remove(java.lang.Object o)
remove
in interface java.util.Collection<T>
remove
in interface java.util.List<T>
remove
in class java.util.AbstractCollection<T>
o
- element to be removed from this list, if presentjava.lang.ClassCastException
- if the type of the specified element
is incompatible with this list (optional)java.lang.NullPointerException
- if the specified element is null and this
list does not permit null elements (optional)java.lang.UnsupportedOperationException
- if the remove operation
is not supported by this listpublic boolean containsAll(@NotNull java.util.Collection<?> c)
containsAll
in interface java.util.Collection<T>
containsAll
in interface java.util.List<T>
containsAll
in class java.util.AbstractCollection<T>
c
- collection to be checked for containment in this listjava.lang.ClassCastException
- if the types of one or more elements
in the specified collection are incompatible with this
list (optional)java.lang.NullPointerException
- if the specified collection contains one
or more null elements and this list does not permit null
elements (optional), or if the specified collection is nullcontains(Object)
public void clear()
public T get(int index)
get
in interface java.util.List<T>
get
in class java.util.AbstractList<T>
index
- index of the element to returnjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())public T set(int index, T element)
set
in interface java.util.List<T>
set
in class java.util.AbstractList<T>
index
- index of the element to replaceelement
- element to be stored at the specified positionjava.lang.UnsupportedOperationException
- if the set operation
is not supported by this listjava.lang.ClassCastException
- if the class of the specified element
prevents it from being added to this listjava.lang.NullPointerException
- if the specified element is null and
this list does not permit null elementsjava.lang.IllegalArgumentException
- if some property of the specified
element prevents it from being added to this listjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())public void add(int index, T element)
add
in interface java.util.List<T>
add
in class java.util.AbstractList<T>
index
- index at which the specified element is to be insertedelement
- element to be insertedjava.lang.UnsupportedOperationException
- if the add operation
is not supported by this listjava.lang.ClassCastException
- if the class of the specified element
prevents it from being added to this listjava.lang.NullPointerException
- if the specified element is null and
this list does not permit null elementsjava.lang.IllegalArgumentException
- if some property of the specified
element prevents it from being added to this listjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > size())public T remove(int index)
remove
in interface java.util.List<T>
remove
in class java.util.AbstractList<T>
index
- the index of the element to be removedjava.lang.UnsupportedOperationException
- if the remove operation
is not supported by this listjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())public int indexOf(java.lang.Object o)
indexOf
in interface java.util.List<T>
indexOf
in class java.util.AbstractList<T>
o
- element to search forjava.lang.ClassCastException
- if the type of the specified element
is incompatible with this list (optional)java.lang.NullPointerException
- if the specified element is null and this
list does not permit null elements (optional)public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List<T>
lastIndexOf
in class java.util.AbstractList<T>
o
- element to search forjava.lang.ClassCastException
- if the type of the specified element
is incompatible with this list (optional)java.lang.NullPointerException
- if the specified element is null and this
list does not permit null elements (optional)