Skip to content

Commit

Permalink
8240692: Cleanup of the javafx property objects
Browse files Browse the repository at this point in the history
Reviewed-by: kcr
  • Loading branch information
nlisker committed Mar 24, 2020
1 parent 90289a2 commit e9c6119
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package com.sun.javafx.binding;

import javafx.beans.Observable;
import javafx.beans.WeakListener;
import javafx.beans.property.*;
import javafx.beans.value.ChangeListener;
Expand All @@ -35,13 +34,13 @@
import java.lang.ref.WeakReference;
import java.text.Format;
import java.text.ParseException;
import java.util.Objects;

public abstract class BidirectionalBinding<T> implements ChangeListener<T>, WeakListener {

private static void checkParameters(Object property1, Object property2) {
if ((property1 == null) || (property2 == null)) {
throw new NullPointerException("Both properties must be specified.");
}
Objects.requireNonNull(property1, "Both properties must be specified.");
Objects.requireNonNull(property2, "Both properties must be specified.");
if (property1 == property2) {
throw new IllegalArgumentException("Cannot bind property to itself");
}
Expand Down Expand Up @@ -69,10 +68,8 @@ public static <T> BidirectionalBinding bind(Property<T> property1, Property<T> p

public static Object bind(Property<String> stringProperty, Property<?> otherProperty, Format format) {
checkParameters(stringProperty, otherProperty);
if (format == null) {
throw new NullPointerException("Format cannot be null");
}
final StringConversionBidirectionalBinding<?> binding = new StringFormatBidirectionalBinding(stringProperty, otherProperty, format);
Objects.requireNonNull(format, "Format cannot be null");
final var binding = new StringFormatBidirectionalBinding(stringProperty, otherProperty, format);
stringProperty.setValue(format.format(otherProperty.getValue()));
stringProperty.addListener(binding);
otherProperty.addListener(binding);
Expand All @@ -81,10 +78,8 @@ public static Object bind(Property<String> stringProperty, Property<?> otherProp

public static <T> Object bind(Property<String> stringProperty, Property<T> otherProperty, StringConverter<T> converter) {
checkParameters(stringProperty, otherProperty);
if (converter == null) {
throw new NullPointerException("Converter cannot be null");
}
final StringConversionBidirectionalBinding<T> binding = new StringConverterBidirectionalBinding<T>(stringProperty, otherProperty, converter);
Objects.requireNonNull(converter, "Converter cannot be null");
final var binding = new StringConverterBidirectionalBinding<>(stringProperty, otherProperty, converter);
stringProperty.setValue(converter.toString(otherProperty.getValue()));
stringProperty.addListener(binding);
otherProperty.addListener(binding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package javafx.beans.property;

import java.util.Objects;

import com.sun.javafx.binding.BidirectionalBinding;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ObservableValue;
Expand Down Expand Up @@ -133,9 +135,7 @@ public String toString() {
* @since JavaFX 8.0
*/
public static BooleanProperty booleanProperty(final Property<Boolean> property) {
if (property == null) {
throw new NullPointerException("Property cannot be null");
}
Objects.requireNonNull(property, "Property cannot be null");
return property instanceof BooleanProperty ? (BooleanProperty)property : new BooleanPropertyBase() {
{
BidirectionalBinding.bind(this, property);
Expand Down Expand Up @@ -164,7 +164,7 @@ public String getName() {
*/
@Override
public ObjectProperty<Boolean> asObject() {
return new ObjectPropertyBase<Boolean> () {
return new ObjectPropertyBase<> () {
{
BidirectionalBinding.bind(this, BooleanProperty.this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@

package javafx.beans.property;

import java.util.Objects;

import com.sun.javafx.binding.BidirectionalBinding;
import com.sun.javafx.binding.ExpressionHelper;
import com.sun.javafx.binding.Logging;

import javafx.beans.binding.Bindings;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.WritableDoubleValue;
import com.sun.javafx.binding.Logging;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.WeakInvalidationListener;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableDoubleValue;

/**
* This class defines a {@link Property} wrapping a {@code double} value.
Expand Down Expand Up @@ -148,9 +145,7 @@ public String toString() {
* @since JavaFX 8.0
*/
public static DoubleProperty doubleProperty(final Property<Double> property) {
if (property == null) {
throw new NullPointerException("Property cannot be null");
}
Objects.requireNonNull(property, "Property cannot be null");
return new DoublePropertyBase() {
{
BidirectionalBinding.bindNumber(this, property);
Expand Down Expand Up @@ -189,7 +184,7 @@ public String getName() {
*/
@Override
public ObjectProperty<Double> asObject() {
return new ObjectPropertyBase<Double> () {
return new ObjectPropertyBase<> () {
{
BidirectionalBinding.bindNumber(this, DoubleProperty.this);
}
Expand All @@ -205,6 +200,4 @@ public String getName() {
}
};
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package javafx.beans.property;

import java.util.Objects;

import com.sun.javafx.binding.BidirectionalBinding;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ObservableValue;
Expand Down Expand Up @@ -142,10 +144,8 @@ public String toString() {
* @see #asObject()
* @since JavaFX 8.0
*/
public static FloatProperty floatProperty(final Property<Float> property) {
if (property == null) {
throw new NullPointerException("Property cannot be null");
}
public static FloatProperty floatProperty(final Property<Float> property) {
Objects.requireNonNull(property, "Property cannot be null");
return new FloatPropertyBase() {
{
BidirectionalBinding.bindNumber(this, property);
Expand Down Expand Up @@ -184,7 +184,7 @@ public String getName() {
*/
@Override
public ObjectProperty<Float> asObject() {
return new ObjectPropertyBase<Float> () {
return new ObjectPropertyBase<> () {
{
BidirectionalBinding.bindNumber(this, FloatProperty.this);
}
Expand All @@ -200,5 +200,4 @@ public String getName() {
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package javafx.beans.property;

import java.util.Objects;

import com.sun.javafx.binding.BidirectionalBinding;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ObservableValue;
Expand Down Expand Up @@ -142,10 +144,8 @@ public String toString() {
* @see #asObject()
* @since JavaFX 8.0
*/
public static IntegerProperty integerProperty(final Property<Integer> property) {
if (property == null) {
throw new NullPointerException("Property cannot be null");
}
public static IntegerProperty integerProperty(final Property<Integer> property) {
Objects.requireNonNull(property, "Property cannot be null");
return new IntegerPropertyBase() {
{
BidirectionalBinding.bindNumber(this, property);
Expand Down Expand Up @@ -184,7 +184,7 @@ public String getName() {
*/
@Override
public ObjectProperty<Integer> asObject() {
return new ObjectPropertyBase<Integer> () {
return new ObjectPropertyBase<> () {
{
BidirectionalBinding.bindNumber(this, IntegerProperty.this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package javafx.beans.property;

import java.util.Objects;

import com.sun.javafx.binding.BidirectionalBinding;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ObservableValue;
Expand Down Expand Up @@ -140,10 +142,8 @@ public String toString() {
* @see #asObject()
* @since JavaFX 8.0
*/
public static LongProperty longProperty(final Property<Long> property) {
if (property == null) {
throw new NullPointerException("Property cannot be null");
}
public static LongProperty longProperty(final Property<Long> property) {
Objects.requireNonNull(property, "Property cannot be null");
return new LongPropertyBase() {
{
BidirectionalBinding.bindNumber(this, property);
Expand Down Expand Up @@ -182,7 +182,7 @@ public String getName() {
*/
@Override
public ObjectProperty<Long> asObject() {
return new ObjectPropertyBase<Long> () {
return new ObjectPropertyBase<> () {
{
BidirectionalBinding.bindNumber(this, LongProperty.this);
}
Expand Down

0 comments on commit e9c6119

Please sign in to comment.