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

org.reactfx.collection.QuasiListChange Maven / Gradle / Ivy

There is a newer version: 1.11
Show newest version
package org.reactfx.collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javafx.collections.ListChangeListener.Change;
import javafx.collections.ObservableList;

import org.reactfx.util.Lists;

public interface QuasiListChange extends ListModificationSequence {

    @Override
    default QuasiListChange asListChange() {
        return this;
    }

    @Override
    default ListChangeAccumulator asListChangeAccumulator() {
        return new ListChangeAccumulator<>(this);
    }

    @SuppressWarnings("unchecked")
    static  QuasiListChange safeCast(
            QuasiListChange mod) {
        // the cast is safe, because instances are immutable
        return (QuasiListChange) mod;
    }


    static  QuasiListChange from(Change ch) {
        QuasiListChangeImpl res = new QuasiListChangeImpl<>();
        while(ch.next()) {
            res.add(QuasiListModification.fromCurrentStateOf(ch));
        }
        return res;
    }

    static  ListChange instantiate(
            QuasiListChange change,
            ObservableList list) {
        return () -> Lists., ListModification>mappedView(
                change.getModifications(),
                mod -> QuasiListModification.instantiate(mod, list));
    }
}

@SuppressWarnings("serial")
final class QuasiListChangeImpl
extends ArrayList>
implements QuasiListChange {

    public QuasiListChangeImpl() {
        super();
    }

    public QuasiListChangeImpl(int initialCapacity) {
        super(initialCapacity);
    }

    public QuasiListChangeImpl(QuasiListChange change) {
        super(change.getModifications());
    }

    @Override
    public List> getModifications() {
        return Collections.unmodifiableList(this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy