Skip to content

Instantly share code, notes, and snippets.

@Tuupertunut
Created October 27, 2016 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tuupertunut/b48e7c916a381da2141f3709f2062a44 to your computer and use it in GitHub Desktop.
Save Tuupertunut/b48e7c916a381da2141f3709f2062a44 to your computer and use it in GitHub Desktop.
package compositelisttest;
import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.CollectionList;
import ca.odell.glazedlists.CompositeList;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.event.ListEventAssembler;
import ca.odell.glazedlists.event.ListEventPublisher;
import ca.odell.glazedlists.util.concurrent.LockFactory;
import ca.odell.glazedlists.util.concurrent.ReadWriteLock;
import java.util.List;
/**
*
* @author Tuupertunut
*/
public class CompositeListTest {
public static void main(String[] args) {
workingRun();
notWorkingRun();
}
private static void workingRun() {
ListEventPublisher publisher = ListEventAssembler.createListEventPublisher();
ReadWriteLock lock = LockFactory.DEFAULT.createReadWriteLock();
EventList<String> rootList = new BasicEventList<>(publisher, lock);
/* adding element before making the CollectionList */
rootList.add("working run");
CollectionList<String, String> colle = new CollectionList<String, String>(rootList, new CollectionList.Model<String, String>() {
@Override
public List<String> getChildren(String parent) {
/* constructing an example list */
EventList<String> basic = new BasicEventList<>(publisher, lock);
basic.add("first");
basic.add("second");
System.out.println("working: basic: " + basic);
/* wrapping the example list in CompositeList to prove a point */
CompositeList<String> compo = new CompositeList<String>(publisher, lock);
compo.addMemberList(basic);
System.out.println("working: compo: " + compo);
return compo;
}
});
}
private static void notWorkingRun() {
ListEventPublisher publisher = ListEventAssembler.createListEventPublisher();
ReadWriteLock lock = LockFactory.DEFAULT.createReadWriteLock();
EventList<String> rootList = new BasicEventList<>(publisher, lock);
CollectionList<String, String> colle = new CollectionList<String, String>(rootList, new CollectionList.Model<String, String>() {
@Override
public List<String> getChildren(String parent) {
/* constructing an example list */
EventList<String> basic = new BasicEventList<>(publisher, lock);
basic.add("first");
basic.add("second");
System.out.println("not working: basic: " + basic);
/* wrapping the example list in CompositeList to prove a point */
CompositeList<String> compo = new CompositeList<String>(publisher, lock);
compo.addMemberList(basic);
/* prints an empty list, showing that the CompositeList does not
* correctly reflect the state of its member list */
System.out.println("not working: compo: " + compo);
return compo;
}
});
/* adding element after making the CollectionList */
rootList.add("not working run");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment