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

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

There is a newer version: 0.9.9
Show newest version
package org.aksw.commons.collection.observable;

import java.beans.PropertyChangeListener;
import java.beans.VetoableChangeListener;
import java.util.Collection;
import java.util.function.Function;
import java.util.function.Predicate;

import com.google.common.base.Converter;

public interface ObservableCollection
    extends DeltaCollection
{
    /** Whether to notify listeners */
//    void setEnableEvents(boolean onOrOff);

//    boolean isEnableEvents();

//    Runnable addListener(Consumer> listener);

    Runnable addVetoableChangeListener(VetoableChangeListener listener);
    Registration addPropertyChangeListener(PropertyChangeListener listener);

    /** Replace the content of this collection thereby firing only a single event */
//    boolean replace(Collection newValues);



    default ObservableCollection filter(Predicate predicate) {
        return new FilteredObservableCollection<>(this, predicate);
    }

    default  ObservableCollection map(Function predicate) {
        throw new UnsupportedOperationException("not implemented yet");
    }

    /**
     * Return a view of this collection as a scalar value:
     * If the collection contains a single item then this item becomes the view's value.
     * Otherwise the view's value is null.
     *
     * @return
     */
    default ObservableValue mapToValue() {
        return ObservableValueFromObservableCollection.decorate(this);
    }

    default  ObservableValue mapToValue(
            Function, O> xform,
            Function valueToItem) {
        return new ObservableValueFromObservableCollection<>(this, xform, valueToItem);
    }

    default  ObservableCollection convert(Converter converter) {
        return new ObservableConvertingCollection<>(this, converter);
    }

//    default  ObservableValue mapToValue(Function, ? extends U> fn) {
//    	return new ObservableValueFromObservableCollection<>(this);
//    }

//    default ObservableCollection mapToSet(Predicate predicate) {
//    	return null;
//    }

}