-
Notifications
You must be signed in to change notification settings - Fork 5
/
MetaBinding.java
38 lines (27 loc) · 1.46 KB
/
MetaBinding.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
package org.genericsystem.reactor;
import java.util.function.BiFunction;
import java.util.function.Function;
import org.genericsystem.common.Generic;
import javafx.collections.ObservableList;
public class MetaBinding<BETWEEN> {
private final Function<Context, ObservableList<BETWEEN>> betweenChildren;
private final BiFunction<Context, BETWEEN, Context> modelBuilder;
private static BiFunction<Context, Generic, Context> MODEL_BUILDER = (model, generic) -> new Context(model, Context.addToGenerics(generic, model.getGenerics()));
private static BiFunction<Context, Context, Context> MODEL_CLONER = (model, subModel) -> new Context(model, subModel.getGenerics());
public MetaBinding(Function<Context, ObservableList<BETWEEN>> betweenChildren, BiFunction<Context, BETWEEN, Context> modelBuilder) {
this.betweenChildren = betweenChildren;
this.modelBuilder = modelBuilder;
}
public ObservableList<BETWEEN> buildBetweenChildren(Context model) {
return betweenChildren.apply(model);
}
public Context buildModel(Context parent, BETWEEN betweenChild) {
return modelBuilder.apply(parent, betweenChild);
}
public static MetaBinding<Context> selectMetaBinding(Function<Context, ObservableList<Context>> betweenChildren) {
return new MetaBinding<Context>(betweenChildren, MODEL_CLONER);
}
public static MetaBinding<Generic> forEachMetaBinding(Function<Context, ObservableList<Generic>> betweenChildren) {
return new MetaBinding<Generic>(betweenChildren, MODEL_BUILDER);
}
}