ca.odell.glazedlists.CompositeList Maven / Gradle / Ivy
Show all versions of glazedlists_java15 Show documentation
/* Glazed Lists (c) 2003-2006 */
/* http://publicobject.com/glazedlists/ publicobject.com,*/
/* O'Dell Engineering Ltd.*/
package ca.odell.glazedlists;
// the core Glazed Lists package
import ca.odell.glazedlists.event.ListEventPublisher;
import ca.odell.glazedlists.util.concurrent.ReadWriteLock;
import java.util.Iterator;
/**
* An {@link EventList} composed of multiple source {@link EventList}s. This list
* shows the contents of its source lists.
*
* Note that all contained {@link EventList}s must use the same {@link ListEventPublisher} and
* {@link ReadWriteLock}, particularly if this {@link EventList} is to be used my multiple threads
* concurrently. To construct an {@link EventList} that shares the {@link ListEventPublisher} and
* {@link ReadWriteLock} with this {@link CompositeList}, use {@link #createMemberList()}.
*
*
* EventList Overview
* Writable: only {@link #set(int,Object)} and {@link #remove(int)}
* Concurrency: not thread safe
* Performance: reads: O(log N), writes O(log N)
* Memory: 96 bytes per element
* Unit Tests: N/A
* Issues:
* 25
* 93
* 96
* 162
*
*
*
* @author Jesse Wilson
*/
public class CompositeList extends CollectionList, E> {
public CompositeList() {
super(new BasicEventList>(), (Model)GlazedLists.listCollectionListModel());
}
/**
* Create a {@link CompositeList} that uses the given lock
. Note that this lock
* will also be used when {@link #createMemberList building new member lists}.
*
* This can be a convenient constructor to use when the member lists are prebuilt ahead of time
* with a common {@link ReadWriteLock} and it is desirable to compose their union with a
* {@link CompositeList}.
*
* @param lock the {@link ReadWriteLock} to use within the {@link CompositeList}
* @deprecated replaced by {@link #CompositeList(ListEventPublisher, ReadWriteLock)}, because
* prebuilt member lists should share lock and publisher with the
* CompositeList.
*/
public CompositeList(ReadWriteLock lock) {
super(new BasicEventList>(lock), (Model)GlazedLists.listCollectionListModel());
}
/**
* Create a {@link CompositeList} that uses the given publisher
and
* lock
. Note that this publisher and lock will also be used when
* {@link #createMemberList building new member lists}.
*
* This can be a convenient constructor to use when the member lists are prebuilt ahead of time
* with a common {@link ListEventPublisher} and {@link ReadWriteLock} and it is desirable to
* compose their union with a {@link CompositeList}.
*
* @param publisher the {@link ListEventPublisher} to use within the {@link CompositeList}
* @param lock the {@link ReadWriteLock} to use within the {@link CompositeList}
*/
public CompositeList(ListEventPublisher publisher, ReadWriteLock lock) {
super(new BasicEventList>(publisher, lock), (Model)GlazedLists.listCollectionListModel());
}
/**
* Adds the specified {@link EventList} as a source to this {@link CompositeList}.
*
* To ensure correct behaviour when this {@link CompositeList} is used by multiple threads, the
* specified EventList has to share the same {@link ReadWriteLock} and
* {@link ListEventPublisher} with this CompositeList.
*
* @throws IllegalArgumentException if the specified EventList uses a different
* {@link ReadWriteLock} or {@link ListEventPublisher}
* @see #createMemberList()
*/
public void addMemberList(EventList list) {
if(!getPublisher().equals(list.getPublisher()))
throw new IllegalArgumentException("Member list must share publisher with CompositeList");
if(!getReadWriteLock().equals(list.getReadWriteLock()))
throw new IllegalArgumentException("Member list must share lock with CompositeList");
source.add(list);
}
/**
* Creates a new {@link EventList} that shares its {@link ReadWriteLock} with
* this {@link CompositeList}. This is necessary when this {@link CompositeList}
* will be used by multiple threads.
*
* Note that the created {@link EventList} must be explicitly added as a member
* to this {@link CompositeList} using {@link #addMemberList(EventList)}.
*/
public EventList createMemberList() {
return new BasicEventList(getPublisher(), getReadWriteLock());
}
/**
* Removes the specified {@link EventList} as a source {@link EventList}
* to this {@link CompositeList}.
*/
public void removeMemberList(EventList list) {
for(Iterator> i = source.iterator(); i.hasNext(); ) {
if(i.next() == list) {
i.remove();
return;
}
}
throw new IllegalArgumentException("Cannot remove list " + list + " which is not in this CompositeList");
}
}