X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Futil%2Fbeans%2FAbstractBean.java;h=b2da7324962fc4837db538da71205d703fdc0a44;hb=d6015942121ba0e43177da20c3559126e9c6dafe;hp=df6f78963726e2fcee12deb7c758fdd3d606e0b9;hpb=e8cc52293a249598d1b2b3ad952dc296357d20d7;p=jSite2.git
diff --git a/src/net/pterodactylus/util/beans/AbstractBean.java b/src/net/pterodactylus/util/beans/AbstractBean.java
index df6f789..b2da732 100644
--- a/src/net/pterodactylus/util/beans/AbstractBean.java
+++ b/src/net/pterodactylus/util/beans/AbstractBean.java
@@ -29,7 +29,6 @@ import java.util.List;
* Abstract bean super class that contains property change listener management.
*
* @author David âBombeâ Roden <bombe@freenetproject.org>
- * @version $Id$
*/
public abstract class AbstractBean {
@@ -74,4 +73,40 @@ 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 null
+ * into account as a valid value for an object.
+ *
+ * @param first
+ * The first object
+ * @param second
+ * The second object
+ * @return true
if the two objects are equal,
+ * false
otherwise
+ */
+ private boolean equal(Object first, Object second) {
+ return ((first == null) && (second == null)) || ((first != null) && first.equals(second)) || ((second != null) && second.equals(first));
+ }
+
}