All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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();
        };
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy