From fffb06b094d47ecb7d0282fade99e2d2f109fcbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 17 May 2008 14:55:14 +0000 Subject: [PATCH] move compare method to AbstractBean git-svn-id: http://trooper/svn/projects/jSite/trunk@906 c3eda9e8-030b-0410-8277-bc7414b0a119 --- src/net/pterodactylus/jsite/core/Node.java | 5 +-- src/net/pterodactylus/jsite/core/Project.java | 9 ++--- src/net/pterodactylus/jsite/core/Request.java | 5 +-- src/net/pterodactylus/util/beans/AbstractBean.java | 16 ++++++++ src/net/pterodactylus/util/beans/Comparer.java | 46 ---------------------- 5 files changed, 24 insertions(+), 57 deletions(-) delete mode 100644 src/net/pterodactylus/util/beans/Comparer.java diff --git a/src/net/pterodactylus/jsite/core/Node.java b/src/net/pterodactylus/jsite/core/Node.java index b7359ca..9435995 100644 --- a/src/net/pterodactylus/jsite/core/Node.java +++ b/src/net/pterodactylus/jsite/core/Node.java @@ -22,7 +22,6 @@ package net.pterodactylus.jsite.core; import java.beans.PropertyChangeListener; import net.pterodactylus.util.beans.AbstractBean; -import net.pterodactylus.util.beans.Comparer; /** * Container for a Freenet node. A Node is capable of notifying @@ -73,7 +72,7 @@ public class Node extends AbstractBean { public void setName(String name) { String oldName = this.name; this.name = name; - if (!Comparer.equal(oldName, name)) { + if (!equal(oldName, name)) { firePropertyChange(PROPERTY_NAME, oldName, name); } } @@ -96,7 +95,7 @@ public class Node extends AbstractBean { public void setHostname(String hostname) { String oldHostname = this.hostname; this.hostname = hostname; - if (!Comparer.equal(oldHostname, hostname)) { + if (!equal(oldHostname, hostname)) { firePropertyChange(PROPERTY_HOSTNAME, oldHostname, hostname); } } diff --git a/src/net/pterodactylus/jsite/core/Project.java b/src/net/pterodactylus/jsite/core/Project.java index 186ecb6..b651d4c 100644 --- a/src/net/pterodactylus/jsite/core/Project.java +++ b/src/net/pterodactylus/jsite/core/Project.java @@ -22,7 +22,6 @@ package net.pterodactylus.jsite.core; import java.beans.PropertyChangeListener; import net.pterodactylus.util.beans.AbstractBean; -import net.pterodactylus.util.beans.Comparer; /** * Container for project information. A Project is capable of notifying @@ -86,7 +85,7 @@ AbstractBean { public void setName(String name) { String oldName = this.name; this.name = name; - if (!Comparer.equal(oldName, name)) { + if (!equal(oldName, name)) { firePropertyChange(PROPERTY_NAME, oldName, name); } } @@ -109,7 +108,7 @@ AbstractBean { public void setDescription(String description) { String oldDescription = this.description; this.description = description; - if (!Comparer.equal(oldDescription, description)) { + if (!equal(oldDescription, description)) { firePropertyChange(PROPERTY_DESCRIPTION, oldDescription, description); } } @@ -132,7 +131,7 @@ AbstractBean { public void setPublicKey(String publicKey) { String oldPublicKey = this.publicKey; this.publicKey = publicKey; - if (!Comparer.equal(oldPublicKey, publicKey)) { + if (!equal(oldPublicKey, publicKey)) { firePropertyChange(PROPERTY_PUBLIC_KEY, oldPublicKey, publicKey); } } @@ -155,7 +154,7 @@ AbstractBean { public void setPrivateKey(String privateKey) { String oldPrivateKey = this.privateKey; this.privateKey = privateKey; - if (!Comparer.equal(oldPrivateKey, privateKey)) { + if (!equal(oldPrivateKey, privateKey)) { firePropertyChange(PROPERTY_PRIVATE_KEY, oldPrivateKey, privateKey); } } diff --git a/src/net/pterodactylus/jsite/core/Request.java b/src/net/pterodactylus/jsite/core/Request.java index 703ba57..7b1bbe9 100644 --- a/src/net/pterodactylus/jsite/core/Request.java +++ b/src/net/pterodactylus/jsite/core/Request.java @@ -21,7 +21,6 @@ package net.pterodactylus.jsite.core; import net.pterodactylus.util.beans.AbstractBean; -import net.pterodactylus.util.beans.Comparer; /** * A request is an ongoing download or upload reported by the freenet node. @@ -163,7 +162,7 @@ AbstractBean { public void setType(Type type) { Type oldType = this.type; this.type = type; - if (!Comparer.equal(oldType, type)) { + if (!equal(oldType, type)) { firePropertyChange(PROPERTY_TYPE, oldType, type); } } @@ -186,7 +185,7 @@ AbstractBean { public void setClientToken(String clientToken) { String oldClientToken = this.clientToken; this.clientToken = clientToken; - if (!Comparer.equal(oldClientToken, clientToken)) { + if (!equal(oldClientToken, clientToken)) { firePropertyChange(PROPERTY_CLIENT_TOKEN, oldClientToken, clientToken); } } diff --git a/src/net/pterodactylus/util/beans/AbstractBean.java b/src/net/pterodactylus/util/beans/AbstractBean.java index df6f789..53fe690 100644 --- a/src/net/pterodactylus/util/beans/AbstractBean.java +++ b/src/net/pterodactylus/util/beans/AbstractBean.java @@ -74,4 +74,20 @@ public abstract class AbstractBean { } + /** + * 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 + */ + protected boolean equal(Object first, Object second) { + return ((first == null) && (second == null)) || ((first != null) && first.equals(second)) || ((second != null) && second.equals(first)); + } + } diff --git a/src/net/pterodactylus/util/beans/Comparer.java b/src/net/pterodactylus/util/beans/Comparer.java deleted file mode 100644 index 68c5264..0000000 --- a/src/net/pterodactylus/util/beans/Comparer.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * jSite2 - StringComparer.java - * Copyright © 2008 David Roden - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package net.pterodactylus.util.beans; - -/** - * Compares different objects. Can be used to detect change in property values. - * - * @author David ‘Bombe’ Roden <bombe@freenetproject.org> - * @version $Id$ - */ -public class Comparer { - - /** - * 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 - */ - public static boolean equal(Object first, Object second) { - return ((first == null) && (second == null)) || ((first != null) && first.equals(second)) || ((second != null) && second.equals(first)); - } - -} -- 2.7.4