Before introducing EasyBind -
DoubleBinding contentHeight = Bindings.createDoubleBinding(
() -> getHeight() - getInsets().getTop() - getInsets().getBottom(),
heightProperty(), insetsProperty());
After introducing EasyBind -
Binding<Double> contentHeight = EasyBind.combine(
heightProperty(), insetsProperty(),
(h, i) -> h.doubleValue() - i.getTop() - i.getBottom());
I'm somewhat uncomfortable regarding doubleValue() part. Every time I combine some subclass of NumberProperty, EasyBind passes Number instead of i.e. Double, Integer, ...
Is there some way to avoid doubleValue()?
It's not EasyBind that's causing the need for you to call
doubleValue()- it's a consequence of the JavaFX API.EasyBind.combine()has a parameter list(ObservableValue<A>, ObservableValue<B>, BiFunction<A,B,R>), and returns aBinding<R>. For the first parameter you're passing in aDoubleProperty. The issue is thatDoubleProperty(somewhat counter-intuitively) implementsObservableValue<Number>, notObservableValue<Double>. Thecombinemethod invokes your BiFunction on the result of callinggetValue()on the first two parameters: i.e. it callsgetValue()on yourDoubleProperty, which returns aNumber, not aDouble. Thus yourBiFunctionhas to be aBiFunction<Number, Insets, Double>(mapping aNumberandInsetsto aDouble).You could consider implementing your
heightPropertyas aObjectProperty<Double>, which would allow you to omit the call todoubleValue(); but it might make other parts of your application harder to code (specifically if you have other bindings to the height). I'm not sure I would consider the need to calldoubleValue()a problem.