de.caff.generics

## Class ActiveList<T>

- java.lang.Object
- - java.util.AbstractCollection<E>
  - - java.util.AbstractList<T>
    - - de.caff.generics.ActiveList<T>

- All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>

      public class ActiveList<T>
      extends java.util.AbstractList<T>

  An active lists sends events on changes.
  Author:
    Rammi

- - ### Field Summary

    - ### Fields inherited from class java.util.AbstractList

      `modCount`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ActiveList(java.util.List<T> wrapped)` Constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    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.

    - ### Methods inherited from class java.util.AbstractList

      `addAll, equals, hashCode, iterator, listIterator, listIterator, removeRange, subList`

    - ### Methods inherited from class java.util.AbstractCollection

      `addAll, removeAll, retainAll, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.List

      `addAll, removeAll, replaceAll, retainAll, sort, spliterator`

    - ### Methods inherited from interface java.util.Collection

      `parallelStream, removeIf, stream`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

- - ### Constructor Detail

    - #### ActiveList

          public ActiveList(@NotNull
                            java.util.List<T> wrapped)

      Constructor. This will allow all operations on the list.
      Parameters:
        `wrapped` - wrapped list, don't use directly any further or add a clone here!

  - ### Method Detail

    - #### wrap

          @NotNull
          public static <S> ActiveList<S> wrap(@NotNull
                                                        java.util.List<S> basicList)

      Wrap a basic list to make it active.
      Type Parameters:
        `S` - list type
      Parameters:
        `basicList` - basic list, don't use directly any further or add a clone here!
      Returns:
        active list

    - #### addActiveListListener

          public void addActiveListListener(@NotNull
                                            ActiveListListener<? super T> listener)

      Add an active list listener.
      Parameters:
        `listener` - listener to add

    - #### removeActiveListListener

          public void removeActiveListListener(@NotNull
                                               ActiveListListener<? super T> listener)

      Remove an active list listener.
      Parameters:
        `listener` - listener to remove

    - #### size

          public int size()

      Returns the number of elements in this list. If this list contains more than `Integer.MAX_VALUE` elements, returns `Integer.MAX_VALUE`.
      Specified by:
        `size` in interface `java.util.Collection<T>`
      Specified by:
        `size` in interface `java.util.List<T>`
      Specified by:
        `size` in class `java.util.AbstractCollection<T>`
      Returns:
        the number of elements in this list

    - #### isEmpty

          public boolean isEmpty()

      Returns `true` if this list contains no elements.
      Specified by:
        `isEmpty` in interface `java.util.Collection<T>`
      Specified by:
        `isEmpty` in interface `java.util.List<T>`
      Overrides:
        `isEmpty` in class `java.util.AbstractCollection<T>`
      Returns:
        `true` if this list contains no elements

    - #### contains

          public boolean contains(java.lang.Object o)

      Returns `true` if this list contains the specified element. More formally, returns `true` if and only if this list contains at least one element `e` such that `(o==null ? e==null : o.equals(e))`.
      Specified by:
        `contains` in interface `java.util.Collection<T>`
      Specified by:
        `contains` in interface `java.util.List<T>`
      Overrides:
        `contains` in class `java.util.AbstractCollection<T>`
      Parameters:
        `o` - element whose presence in this list is to be tested
      Returns:
        `true` if this list contains the specified element
      Throws:
        `java.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)

    - #### toArray

          @NotNull
          public java.lang.Object[] toArray()

      Returns an array containing all of the elements in this list in proper sequence (from first to last element).

      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.

      Specified by:
        `toArray` in interface `java.util.Collection<T>`
      Specified by:
        `toArray` in interface `java.util.List<T>`
      Overrides:
        `toArray` in class `java.util.AbstractCollection<T>`
      Returns:
        an array containing all of the elements in this list in proper sequence
      See Also:
        `Arrays.asList(Object[])`

    - #### toArray

          @NotNull
          public <T1> T1[] toArray(@NotNull
                                            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. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.

      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()`.
      Specified by:
        `toArray` in interface `java.util.Collection<T>`
      Specified by:
        `toArray` in interface `java.util.List<T>`
      Overrides:
        `toArray` in class `java.util.AbstractCollection<T>`
      Parameters:
        `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.
      Returns:
        an array containing the elements of this list
      Throws:
        `java.lang.ArrayStoreException` - if the runtime type of the specified array is not a supertype of the runtime type of every element in this list
        `java.lang.NullPointerException` - if the specified array is null

    - #### add

          public boolean add(T t)

      Appends the specified element to the end of this list (optional operation).

      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.

      Specified by:
        `add` in interface `java.util.Collection<T>`
      Specified by:
        `add` in interface `java.util.List<T>`
      Overrides:
        `add` in class `java.util.AbstractList<T>`
      Parameters:
        `t` - element to be appended to this list
      Returns:
        `true` (as specified by `Collection.add(E)`)
      Throws:
        `java.lang.UnsupportedOperationException` - if the `add` operation is not supported by this list
        `java.lang.ClassCastException` - if the class of the specified element prevents it from being added to this list
        `java.lang.NullPointerException` - if the specified element is null and this list does not permit null elements
        `java.lang.IllegalArgumentException` - if some property of this element prevents it from being added to this list

    - #### remove

          public boolean remove(java.lang.Object o)

      Removes the first occurrence of the specified element from this list, if it is present (optional operation). If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index `i` such that `(o==null ? get(i)==null : o.equals(get(i)))` (if such an element exists). Returns `true` if this list contained the specified element (or equivalently, if this list changed as a result of the call).
      Specified by:
        `remove` in interface `java.util.Collection<T>`
      Specified by:
        `remove` in interface `java.util.List<T>`
      Overrides:
        `remove` in class `java.util.AbstractCollection<T>`
      Parameters:
        `o` - element to be removed from this list, if present
      Returns:
        `true` if this list contained the specified element
      Throws:
        `java.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 list

    - #### containsAll

          public boolean containsAll(@NotNull
                                     java.util.Collection<?> c)

      Returns `true` if this list contains all of the elements of the specified collection.
      Specified by:
        `containsAll` in interface `java.util.Collection<T>`
      Specified by:
        `containsAll` in interface `java.util.List<T>`
      Overrides:
        `containsAll` in class `java.util.AbstractCollection<T>`
      Parameters:
        `c` - collection to be checked for containment in this list
      Returns:
        `true` if this list contains all of the elements of the specified collection
      Throws:
        `java.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 null
      See Also:
        `contains(Object)`

    - #### clear

          public void clear()

      Removes all of the elements from this list (optional operation). The list will be empty after this call returns.
      Specified by:
        `clear` in interface `java.util.Collection<T>`
      Specified by:
        `clear` in interface `java.util.List<T>`
      Overrides:
        `clear` in class `java.util.AbstractList<T>`
      Throws:
        `java.lang.UnsupportedOperationException` - if the `clear` operation is not supported by this list

    - #### get

          public T get(int index)

      Returns the element at the specified position in this list.
      Specified by:
        `get` in interface `java.util.List<T>`
      Specified by:
        `get` in class `java.util.AbstractList<T>`
      Parameters:
        `index` - index of the element to return
      Returns:
        the element at the specified position in this list
      Throws:
        `java.lang.IndexOutOfBoundsException` - if the index is out of range (`index < 0 || index >= size()`)

    - #### set

          public T set(int index,
                       T element)

      Replaces the element at the specified position in this list with the specified element (optional operation).
      Specified by:
        `set` in interface `java.util.List<T>`
      Overrides:
        `set` in class `java.util.AbstractList<T>`
      Parameters:
        `index` - index of the element to replace
        `element` - element to be stored at the specified position
      Returns:
        the element previously at the specified position
      Throws:
        `java.lang.UnsupportedOperationException` - if the `set` operation is not supported by this list
        `java.lang.ClassCastException` - if the class of the specified element prevents it from being added to this list
        `java.lang.NullPointerException` - if the specified element is null and this list does not permit null elements
        `java.lang.IllegalArgumentException` - if some property of the specified element prevents it from being added to this list
        `java.lang.IndexOutOfBoundsException` - if the index is out of range (`index < 0 || index >= size()`)

    - #### add

          public void add(int index,
                          T element)

      Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
      Specified by:
        `add` in interface `java.util.List<T>`
      Overrides:
        `add` in class `java.util.AbstractList<T>`
      Parameters:
        `index` - index at which the specified element is to be inserted
        `element` - element to be inserted
      Throws:
        `java.lang.UnsupportedOperationException` - if the `add` operation is not supported by this list
        `java.lang.ClassCastException` - if the class of the specified element prevents it from being added to this list
        `java.lang.NullPointerException` - if the specified element is null and this list does not permit null elements
        `java.lang.IllegalArgumentException` - if some property of the specified element prevents it from being added to this list
        `java.lang.IndexOutOfBoundsException` - if the index is out of range (`index < 0 || index > size()`)

    - #### remove

          public T remove(int index)

      Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
      Specified by:
        `remove` in interface `java.util.List<T>`
      Overrides:
        `remove` in class `java.util.AbstractList<T>`
      Parameters:
        `index` - the index of the element to be removed
      Returns:
        the element previously at the specified position
      Throws:
        `java.lang.UnsupportedOperationException` - if the `remove` operation is not supported by this list
        `java.lang.IndexOutOfBoundsException` - if the index is out of range (`index < 0 || index >= size()`)

    - #### indexOf

          public 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. More formally, returns the lowest index `i` such that `(o==null ? get(i)==null : o.equals(get(i)))`, or -1 if there is no such index.
      Specified by:
        `indexOf` in interface `java.util.List<T>`
      Overrides:
        `indexOf` in class `java.util.AbstractList<T>`
      Parameters:
        `o` - element to search for
      Returns:
        the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element
      Throws:
        `java.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)

    - #### lastIndexOf

          public 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. More formally, returns the highest index `i` such that `(o==null ? get(i)==null : o.equals(get(i)))`, or -1 if there is no such index.
      Specified by:
        `lastIndexOf` in interface `java.util.List<T>`
      Overrides:
        `lastIndexOf` in class `java.util.AbstractList<T>`
      Parameters:
        `o` - element to search for
      Returns:
        the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element
      Throws:
        `java.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)