0

I have a SetProperty<Point> and a function that produces a Stream<Point>.

Stream<Point> generatePoints(Point p) {
    // ...
}
ObjectProperty<Point> selectedPointProperty() {
    // ...
}

SetProperty<Point> generatedPoints = new SimpleSetProperty();

I would like to bind generatedPoints to the result of applying generatedPoints to the result of selectedPointProperty(). I tried following code, but it has type error.

generatedPoints.bind(Bindings.createObjectBinding(() -> generatePoints(selectedPointProperty().get()).collect(Collectors.toSet()),
 selectedPointProperty()));
charlieh_7
  • 334
  • 3
  • 12

1 Answers1

1

A SetProperty<T> is not a Property<Set<T>> but a Property<ObservableSet<T>>.

Therefore the type needed for the property and the type returned by

generatePoints(selectedPointProperty().get()).collect(Collectors.toSet())

do not match. You need to return a ObservableSet from the Callable instead, e.g:

generatedPoints.bind(Bindings.createObjectBinding(() -> FXCollections.observableSet(generatePoints(selectedPointProperty().get()).toArray(Point[]::new)),
        selectedPointProperty()));
fabian
  • 80,457
  • 12
  • 86
  • 114