name.remal.collections.ObservableCollection Maven / Gradle / Ivy
package name.remal.collections;
import java.util.Collection;
import org.jetbrains.annotations.NotNull;
public interface ObservableCollection extends Collection {
@NotNull
HandlerRegistration registerElementAddedHandler(@NotNull ElementAddedHandler handler);
@NotNull
HandlerRegistration registerElementRemovedHandler(@NotNull ElementRemovedHandler handler);
@NotNull
default HandlerRegistration registerCollectionChangedHandler(@NotNull CollectionChangedHandler handler) {
HandlerRegistration elementAddedHandlerRegistration = registerElementAddedHandler(__ -> handler.onCollectionChanged());
HandlerRegistration elementRemovedHandlerRegistration = registerElementRemovedHandler(__ -> handler.onCollectionChanged());
return () -> {
elementAddedHandlerRegistration.deregister();
elementRemovedHandlerRegistration.deregister();
};
}
}