org.reactfx.util.AccumulationFacility Maven / Gradle / Ivy
package org.reactfx.util;
import java.util.Deque;
import java.util.LinkedList;
import org.reactfx.collection.ListChangeAccumulator;
import org.reactfx.collection.ListModificationSequence;
import org.reactfx.collection.QuasiListChange;
public interface AccumulationFacility {
A initialAccumulator(T value);
A reduce(A accum, T value);
interface IllegalAccumulation extends AccumulationFacility {
@Override
default A reduce(A accum, T value) { throw new IllegalStateException(); }
}
interface HomotypicAccumulation extends AccumulationFacility {
@Override
default T initialAccumulator(T value) { return value; }
}
interface NoAccumulation
extends IllegalAccumulation, HomotypicAccumulation {}
interface Queuing extends AccumulationFacility> {
@Override
default Deque initialAccumulator(T value) {
Deque res = new LinkedList<>();
res.add(value);
return res;
}
@Override
default Deque reduce(Deque accum, T value) {
accum.addLast(value);
return accum;
}
}
interface RetainLatest extends HomotypicAccumulation {
@Override
default T reduce(T accum, T value) { return value; }
}
interface RetainOldest extends HomotypicAccumulation {
@Override
default T reduce(T accum, T value) { return accum; }
}
interface ListChangeAccumulation
extends AccumulationFacility, ListModificationSequence> {
@Override
default ListModificationSequence initialAccumulator(
QuasiListChange extends E> value) {
return QuasiListChange.safeCast(value);
}
@Override
default ListChangeAccumulator reduce(
ListModificationSequence accum,
QuasiListChange extends E> value) {
return accum.asListChangeAccumulator().add(value);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy