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

org.aksw.commons.collection.observable.ObservableSetImpl Maven / Gradle / Ivy

package org.aksw.commons.collection.observable;

import java.beans.PropertyChangeListener;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;

public class ObservableSetImpl
    extends ObservableCollectionBase>
    implements ObservableSet
{
    public ObservableSetImpl(Set decoratee) {
        super(decoratee);
    }

    public static  ObservableSet decorate(Set decoratee) {
        return new ObservableSetImpl(decoratee);
    }

    /**
     *
     * Removals are carried out as given in order for linked collections to yield items in the right order.
     * Hence, even if an item to be removed is contained in the additions it will be removed first.
     *
     */
   @Override
   public boolean delta(Collection rawAdditions, Collection rawRemovals) {
       return ObservableCollectionOps.applyDeltaSet(
               this, backend,
               vcs, pcs,
               true,
               rawAdditions, rawRemovals);
   }

    @Override
    public Registration addPropertyChangeListener(PropertyChangeListener listener) {
        pcs.addPropertyChangeListener(listener);
        // return () -> pcs.removePropertyChangeListener(listener);

        return Registration.from(
            () ->  { listener.propertyChange(new CollectionChangedEventImpl(
                    this, this, this,
                    Collections.emptySet(), Collections.emptySet(), Collections.emptySet())); },
            () -> pcs.removePropertyChangeListener(listener));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy