Created
October 27, 2016 22:12
-
-
Save Tuupertunut/b48e7c916a381da2141f3709f2062a44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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