com.levigo.util.base.glazedlists
Class BasicEventList<E>

java.lang.Object
  extended by com.levigo.util.base.glazedlists.AbstractEventList<E>
      extended by com.levigo.util.base.glazedlists.BasicEventList<E>
All Implemented Interfaces:
EventList<E>, Serializable, Iterable<E>, Collection<E>, List<E>, RandomAccess

public final class BasicEventList<E>
extends AbstractEventList<E>
implements Serializable, RandomAccess

An EventList that wraps any simple List, such as ArrayList or LinkedList.

Unlike most EventLists, this class is Serializable. When BasicEventList is serialized, all of its elements are serialized and all of its listeners that implement Serializable. Upon deserialization, the new copy uses a different lock than its source BasicEventList.

Overview
EventList Overview
Writable: yes
Concurrency: thread ready, not thread safe
Performance: reads: O(1), writes O(1) amortized
Memory: O(N)
Unit Tests: N/A
Issues: N/A

Author:
Jesse Wilson
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.levigo.util.base.glazedlists.AbstractEventList
publisher, readWriteLock, updates
 
Constructor Summary
BasicEventList()
          Creates a BasicEventList.
BasicEventList(int initalCapacity)
          Creates an empty BasicEventList with the given initialCapacity.
BasicEventList(int initialCapacity, ListEventPublisher publisher, ReadWriteLock readWriteLock)
          Creates a BasicEventList using the specified initial capacity, ListEventPublisher and ReadWriteLock.
BasicEventList(List<E> list)
          Deprecated. As of 2005/03/06, this constructor has been declared unsafe because the source list is exposed. This allows it to be modified without the required events being fired. This constructor has been replaced by the factory method GlazedLists.eventList(Collection).
BasicEventList(ListEventPublisher publisher, ReadWriteLock readWriteLock)
          Creates a BasicEventList using the specified ListEventPublisher and ReadWriteLock.
BasicEventList(ReadWriteLock readWriteLock)
          Creates a BasicEventList that uses the specified ReadWriteLock for concurrent access.
 
Method Summary
 boolean add(E element)
          Appends the specified element to the end of this list (optional operation).
 void add(int index, E element)
          Inserts the specified element at the specified position in this list (optional operation).
 boolean addAll(Collection<? extends E> collection)
          Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).
 boolean addAll(int index, Collection<? extends E> collection)
          Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
 void clear()
          Removes all of the elements from this list (optional operation).
 void dispose()
          This method does nothing.
 E get(int index)
          Returns the element at the specified position in this list.
 E remove(int index)
          Removes the element at the specified position in this list (optional operation).
 boolean remove(Object element)
          Removes the first occurrence in this list of the specified element (optional operation).
 boolean removeAll(Collection<?> collection)
          Removes from this list all the elements that are contained in the specified collection (optional operation).
 boolean retainAll(Collection<?> collection)
          Retains only the elements in this list that are contained in the specified collection (optional operation).
 E set(int index, E 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.
 
Methods inherited from class com.levigo.util.base.glazedlists.AbstractEventList
addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeListEventListener, subList, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicEventList

public BasicEventList()
Creates a BasicEventList.


BasicEventList

public BasicEventList(ReadWriteLock readWriteLock)
Creates a BasicEventList that uses the specified ReadWriteLock for concurrent access.


BasicEventList

public BasicEventList(int initalCapacity)
Creates an empty BasicEventList with the given initialCapacity.


BasicEventList

public BasicEventList(ListEventPublisher publisher,
                      ReadWriteLock readWriteLock)
Creates a BasicEventList using the specified ListEventPublisher and ReadWriteLock.

Since:
2006-June-12

BasicEventList

public BasicEventList(int initialCapacity,
                      ListEventPublisher publisher,
                      ReadWriteLock readWriteLock)
Creates a BasicEventList using the specified initial capacity, ListEventPublisher and ReadWriteLock.

Since:
2007-April-19

BasicEventList

@Deprecated
public BasicEventList(List<E> list)
Deprecated. As of 2005/03/06, this constructor has been declared unsafe because the source list is exposed. This allows it to be modified without the required events being fired. This constructor has been replaced by the factory method GlazedLists.eventList(Collection).

Creates a BasicEventList that uses the specified List as the underlying implementation.

Warning: all editing to the specified List must be done through via this BasicEventList interface. Otherwise this BasicEventList will become out of sync and operations will fail.

Method Detail

add

public void add(int index,
                E 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 List<E>
Overrides:
add in class AbstractEventList<E>
Parameters:
index - index at which the specified element is to be inserted.
element - element to be inserted.

add

public boolean add(E element)
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 Collection<E>
Specified by:
add in interface List<E>
Overrides:
add in class AbstractEventList<E>
Parameters:
element - element to be appended to this list.
Returns:
true (as per the general contract of the Collection.add method).

addAll

public boolean addAll(Collection<? extends E> collection)
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation). The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)

Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface List<E>
Overrides:
addAll in class AbstractEventList<E>
Parameters:
collection - collection whose elements are to be added to this list.
Returns:
true if this list changed as a result of the call.
See Also:
AbstractEventList.add(Object)

addAll

public boolean addAll(int index,
                      Collection<? extends E> collection)
Inserts all of the elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)

Specified by:
addAll in interface List<E>
Overrides:
addAll in class AbstractEventList<E>
Parameters:
index - index at which to insert first element from the specified collection.
collection - elements to be inserted into this list.
Returns:
true if this list changed as a result of the call.

remove

public E 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 List<E>
Overrides:
remove in class AbstractEventList<E>
Parameters:
index - the index of the element to removed.
Returns:
the element previously at the specified position.

remove

public boolean remove(Object element)
Removes the first occurrence in this list of the specified element (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).

Specified by:
remove in interface Collection<E>
Specified by:
remove in interface List<E>
Overrides:
remove in class AbstractEventList<E>
Parameters:
element - element to be removed from this list, if present.
Returns:
true if this list contained the specified element.

clear

public void clear()
Removes all of the elements from this list (optional operation). This list will be empty after this call returns (unless it throws an exception).

Specified by:
clear in interface Collection<E>
Specified by:
clear in interface List<E>
Overrides:
clear in class AbstractEventList<E>

set

public E set(int index,
             E element)
Replaces the element at the specified position in this list with the specified element (optional operation).

Specified by:
set in interface List<E>
Overrides:
set in class AbstractEventList<E>
Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.

get

public E get(int index)
Returns the element at the specified position in this list.

Specified by:
get in interface List<E>
Specified by:
get in class AbstractEventList<E>
Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.

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 Collection<E>
Specified by:
size in interface List<E>
Specified by:
size in class AbstractEventList<E>
Returns:
the number of elements in this list.

removeAll

public boolean removeAll(Collection<?> collection)
Removes from this list all the elements that are contained in the specified collection (optional operation).

Specified by:
removeAll in interface Collection<E>
Specified by:
removeAll in interface List<E>
Overrides:
removeAll in class AbstractEventList<E>
Parameters:
collection - collection that defines which elements will be removed from this list.
Returns:
true if this list changed as a result of the call.
See Also:
AbstractEventList.remove(Object), AbstractEventList.contains(Object)

retainAll

public boolean retainAll(Collection<?> collection)
Retains only the elements in this list that are contained in the specified collection (optional operation). In other words, removes from this list all the elements that are not contained in the specified collection.

Specified by:
retainAll in interface Collection<E>
Specified by:
retainAll in interface List<E>
Overrides:
retainAll in class AbstractEventList<E>
Parameters:
collection - collection that defines which elements this set will retain.
Returns:
true if this list changed as a result of the call.
See Also:
AbstractEventList.remove(Object), AbstractEventList.contains(Object)

dispose

public void dispose()
This method does nothing. It is not necessary to dispose a BasicEventList.

Specified by:
dispose in interface EventList<E>


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.