2525
2626package com .sun .javafx .binding ;
2727
28- import javafx .beans .Observable ;
2928import javafx .beans .WeakListener ;
3029import javafx .beans .property .*;
3130import javafx .beans .value .ChangeListener ;
3534import java .lang .ref .WeakReference ;
3635import java .text .Format ;
3736import java .text .ParseException ;
37+ import java .util .Objects ;
3838
3939public abstract class BidirectionalBinding <T > implements ChangeListener <T >, WeakListener {
4040
4141 private static void checkParameters (Object property1 , Object property2 ) {
42- if ((property1 == null ) || (property2 == null )) {
43- throw new NullPointerException ("Both properties must be specified." );
44- }
42+ Objects .requireNonNull (property1 , "Both properties must be specified." );
43+ Objects .requireNonNull (property2 , "Both properties must be specified." );
4544 if (property1 == property2 ) {
4645 throw new IllegalArgumentException ("Cannot bind property to itself" );
4746 }
@@ -69,10 +68,8 @@ public static <T> BidirectionalBinding bind(Property<T> property1, Property<T> p
6968
7069 public static Object bind (Property <String > stringProperty , Property <?> otherProperty , Format format ) {
7170 checkParameters (stringProperty , otherProperty );
72- if (format == null ) {
73- throw new NullPointerException ("Format cannot be null" );
74- }
75- final StringConversionBidirectionalBinding <?> binding = new StringFormatBidirectionalBinding (stringProperty , otherProperty , format );
71+ Objects .requireNonNull (format , "Format cannot be null" );
72+ final var binding = new StringFormatBidirectionalBinding (stringProperty , otherProperty , format );
7673 stringProperty .setValue (format .format (otherProperty .getValue ()));
7774 stringProperty .addListener (binding );
7875 otherProperty .addListener (binding );
@@ -81,10 +78,8 @@ public static Object bind(Property<String> stringProperty, Property<?> otherProp
8178
8279 public static <T > Object bind (Property <String > stringProperty , Property <T > otherProperty , StringConverter <T > converter ) {
8380 checkParameters (stringProperty , otherProperty );
84- if (converter == null ) {
85- throw new NullPointerException ("Converter cannot be null" );
86- }
87- final StringConversionBidirectionalBinding <T > binding = new StringConverterBidirectionalBinding <T >(stringProperty , otherProperty , converter );
81+ Objects .requireNonNull (converter , "Converter cannot be null" );
82+ final var binding = new StringConverterBidirectionalBinding <>(stringProperty , otherProperty , converter );
8883 stringProperty .setValue (converter .toString (otherProperty .getValue ()));
8984 stringProperty .addListener (binding );
9085 otherProperty .addListener (binding );
0 commit comments