-
Notifications
You must be signed in to change notification settings - Fork 5
/
ObservableInheritanceComputer.java
67 lines (56 loc) · 2 KB
/
ObservableInheritanceComputer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org.genericsystem.defaults.tools;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.genericsystem.api.core.FiltersBuilder;
import org.genericsystem.api.core.IndexFilter;
import org.genericsystem.defaults.DefaultGeneric;
import javafx.beans.Observable;
import javafx.beans.binding.ListBinding;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
/**
* @author Nicolas Feybesse
*
* @param <T>
*/
public class ObservableInheritanceComputer<T extends DefaultGeneric<T>> extends ListBinding<T> {
List<Observable> invalidators = new ArrayList<>();
private final T base;
private final T origin;
private final int level;
public ObservableInheritanceComputer(T base, T origin, int level) {
this.base = base;
this.origin = origin;
this.level = level;
}
@Override
protected ObservableList<T> computeValue() {
invalidators.forEach(ObservableInheritanceComputer.this::unbind);
List<Observable> newInvalidators = new ArrayList<>();
List<T> internal = new InheritanceComputer<T>(base, origin, level) {
@Override
protected Inheritings buildInheritings(T superVertex) {
return new Inheritings(superVertex) {
@Override
protected Stream<T> compositesByMeta(T holder) {
ObservableList<T> filtered = localBase.getComposites().filter(new IndexFilter(FiltersBuilder.HAS_META, holder)).toObservableList();
newInvalidators.add(filtered);
bind(filtered);
return super.compositesByMeta(holder);
}
@Override
protected Stream<T> compositesBySuper(T holder) {
ObservableList<T> filtered = localBase.getComposites().filter(new IndexFilter(FiltersBuilder.HAS_SUPER, holder)).toObservableList();
newInvalidators.add(filtered);
bind(filtered);
return super.compositesBySuper(holder);
}
};
};
}.inheritanceStream().collect(Collectors.toList());
invalidators = newInvalidators;
return FXCollections.observableList(internal);
}
}