org.reactfx.collection.ValAsList 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 javafx.beans.value.ObservableValue;
import org.reactfx.Subscription;
import org.reactfx.util.Lists;
import org.reactfx.value.Val;
class ValAsList extends LiveListBase implements UnmodifiableByDefaultLiveList {
private final ObservableValue underlying;
ValAsList(ObservableValue underlying) {
this.underlying = underlying;
}
@Override
public int size() {
return underlying.getValue() == null ? 0 : 1;
}
@Override
public T get(int index) {
Lists.checkIndex(index, size());
return underlying.getValue();
}
@Override
protected Subscription observeInputs() {
return Val.observeChanges(underlying, (obs, oldVal, newVal) -> {
if(oldVal == null) {
assert newVal != null;
fireElemInsertion(0);
} else if(newVal == null) {
assert oldVal != null; // superfluous, just for symmetry
fireElemRemoval(0, oldVal);
} else {
fireElemReplacement(0, oldVal);
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy