simplify abstract bean a bit
[jSite2.git] / src / net / pterodactylus / util / beans / AbstractBean.java
index 53fe690..b586353 100644 (file)
@@ -75,6 +75,26 @@ public abstract class AbstractBean {
        }
 
        /**
+        * Fires a property change event if the two values are not equal.
+        * 
+        * @param propertyName
+        *            The name of the property
+        * @param oldValue
+        *            The old value of the property
+        * @param newValue
+        *            The new value of the property
+        */
+       protected void fireIfPropertyChanged(String propertyName, Object oldValue, Object newValue) {
+               if (!equal(oldValue, newValue)) {
+                       firePropertyChange(propertyName, oldValue, newValue);
+               }
+       }
+
+       //
+       // PRIVATE METHODS
+       //
+
+       /**
         * Compares the two objects and returns whether they are equal according to
         * {@link Object#equals(Object)}. This method takes <code>null</code>
         * into account as a valid value for an object.
@@ -86,7 +106,7 @@ public abstract class AbstractBean {
         * @return <code>true</code> if the two objects are equal,
         *         <code>false</code> otherwise
         */
-       protected boolean equal(Object first, Object second) {
+       private boolean equal(Object first, Object second) {
                return ((first == null) && (second == null)) || ((first != null) && first.equals(second)) || ((second != null) && second.equals(first));
        }