test.ca.odell.glazedlists.DelayList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of glazedlists_java15 Show documentation
Show all versions of glazedlists_java15 Show documentation
Event-driven lists for dynamically filtered and sorted tables
/* Glazed Lists (c) 2003-2006 */
/* http://publicobject.com/glazedlists/ publicobject.com,*/
/* O'Dell Engineering Ltd.*/
package ca.odell.glazedlists;
import ca.odell.glazedlists.event.ListEvent;
/**
* This EventList simply delays each read and write operation by the given
* delay (in milliseconds).
*
* @author James Lemieux
*/
public class DelayList extends TransformedList {
private final long delay;
public DelayList(EventList source, long delay) {
super(source);
if (delay < 1)
throw new IllegalArgumentException("delay is not a non-negative number");
this.delay = delay;
source.addListEventListener(this);
}
private void delay() {
try {
Thread.sleep(this.delay);
} catch (InterruptedException e) {
// this is best effort only
}
}
public void listChanged(ListEvent listChanges) {
this.delay();
updates.forwardEvent(listChanges);
}
protected boolean isWritable() {
return true;
}
public int size() {
this.delay();
return super.size();
}
public S get(int index) {
this.delay();
return super.get(index);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy