org.reactfx.collection.QuasiListChange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
FX-Text-Area for formatted text and other special effects.
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 extends E> mod) {
// the cast is safe, because instances are immutable
return (QuasiListChange) mod;
}
static QuasiListChange from(Change extends E> ch) {
QuasiListChangeImpl res = new QuasiListChangeImpl<>();
while(ch.next()) {
res.add(QuasiListModification.fromCurrentStateOf(ch));
}
return res;
}
static ListChange instantiate(
QuasiListChange extends E> change,
ObservableList list) {
return () -> Lists., ListModification extends E>>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);
}
}