public void setName(String name) {
String oldName = this.name;
this.name = name;
- if (!equal(oldName, name)) {
- firePropertyChange(PROPERTY_NAME, oldName, name);
- }
+ fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
}
/**
public void setHostname(String hostname) {
String oldHostname = this.hostname;
this.hostname = hostname;
- if (!equal(oldHostname, hostname)) {
- firePropertyChange(PROPERTY_HOSTNAME, oldHostname, hostname);
- }
+ fireIfPropertyChanged(PROPERTY_HOSTNAME, oldHostname, hostname);
}
/**
public void setPort(int port) {
int oldPort = this.port;
this.port = port;
- if (oldPort != port) {
- firePropertyChange(PROPERTY_PORT, oldPort, port);
- }
+ fireIfPropertyChanged(PROPERTY_PORT, oldPort, port);
}
/**
package net.pterodactylus.jsite.core;
-
import net.pterodactylus.util.beans.AbstractBean;
/**
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
-public class Request extends
-AbstractBean {
+public class Request extends AbstractBean {
/**
* The type of a request.
public void setType(Type type) {
Type oldType = this.type;
this.type = type;
- if (!equal(oldType, type)) {
- firePropertyChange(PROPERTY_TYPE, oldType, type);
- }
+ fireIfPropertyChanged(PROPERTY_TYPE, oldType, type);
}
/**
public void setClientToken(String clientToken) {
String oldClientToken = this.clientToken;
this.clientToken = clientToken;
- if (!equal(oldClientToken, clientToken)) {
- firePropertyChange(PROPERTY_CLIENT_TOKEN, oldClientToken, clientToken);
- }
+ fireIfPropertyChanged(PROPERTY_CLIENT_TOKEN, oldClientToken, clientToken);
}
/**
public void setTotalBlocks(int totalBlocks) {
int oldTotalBlocks = this.totalBlocks;
this.totalBlocks = totalBlocks;
- if (oldTotalBlocks != totalBlocks) {
- firePropertyChange(PROPERTY_TOTAL_BLOCKS, oldTotalBlocks, totalBlocks);
- }
+ fireIfPropertyChanged(PROPERTY_TOTAL_BLOCKS, oldTotalBlocks, totalBlocks);
}
/**
public void setRequiredBlocks(int requiredBlocks) {
int oldRequiredBlocks = this.requiredBlocks;
this.requiredBlocks = requiredBlocks;
- if (oldRequiredBlocks != requiredBlocks) {
- firePropertyChange(PROPERTY_REQUIRED_BLOCKS, oldRequiredBlocks, requiredBlocks);
- }
+ fireIfPropertyChanged(PROPERTY_REQUIRED_BLOCKS, oldRequiredBlocks, requiredBlocks);
}
/**
public void setSuccessfulBlocks(int successfulBlocks) {
int oldSuccessfulBlocks = this.successfulBlocks;
this.successfulBlocks = successfulBlocks;
- if (oldSuccessfulBlocks != successfulBlocks) {
- firePropertyChange(PROPERTY_SUCCESSFUL_BLOCKS, oldSuccessfulBlocks, successfulBlocks);
- }
+ fireIfPropertyChanged(PROPERTY_SUCCESSFUL_BLOCKS, oldSuccessfulBlocks, successfulBlocks);
}
/**
public void setFailedBlocks(int failedBlocks) {
int oldFailedBlocks = this.failedBlocks;
this.failedBlocks = failedBlocks;
- if (oldFailedBlocks != failedBlocks) {
- firePropertyChange(PROPERTY_FAILED_BLOCKS, oldFailedBlocks, failedBlocks);
- }
+ fireIfPropertyChanged(PROPERTY_FAILED_BLOCKS, oldFailedBlocks, failedBlocks);
}
/**
public void setFatallyFailedBlocks(int fatallyFailedBlocks) {
int oldFatallyFailedBlocks = this.fatallyFailedBlocks;
this.fatallyFailedBlocks = fatallyFailedBlocks;
- if (oldFatallyFailedBlocks != fatallyFailedBlocks) {
- firePropertyChange(PROPERTY_FATALLY_FAILED_BLOCKS, oldFatallyFailedBlocks, fatallyFailedBlocks);
- }
+ fireIfPropertyChanged(PROPERTY_FATALLY_FAILED_BLOCKS, oldFatallyFailedBlocks, fatallyFailedBlocks);
}
/**
public void setTotalFinalized(boolean totalFinalized) {
boolean oldTotalFinalized = this.totalFinalized;
this.totalFinalized = totalFinalized;
- if (oldTotalFinalized != totalFinalized) {
- firePropertyChange(PROPERTY_TOTAL_FINALIZED, oldTotalFinalized, totalFinalized);
- }
+ fireIfPropertyChanged(PROPERTY_TOTAL_FINALIZED, oldTotalFinalized, totalFinalized);
}
}
public void setName(String name) {
String oldName = this.name;
this.name = name;
- if (!equal(oldName, name)) {
- firePropertyChange(PROPERTY_NAME, oldName, name);
- }
+ fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
}
/**
public void setDescription(String description) {
String oldDescription = this.description;
this.description = description;
- if (!equal(oldDescription, description)) {
- firePropertyChange(PROPERTY_DESCRIPTION, oldDescription, description);
- }
+ fireIfPropertyChanged(PROPERTY_DESCRIPTION, oldDescription, description);
}
/**
public void setPublicKey(String publicKey) {
String oldPublicKey = this.publicKey;
this.publicKey = publicKey;
- if (!equal(oldPublicKey, publicKey)) {
- firePropertyChange(PROPERTY_PUBLIC_KEY, oldPublicKey, publicKey);
- }
+ fireIfPropertyChanged(PROPERTY_PUBLIC_KEY, oldPublicKey, publicKey);
}
/**
public void setPrivateKey(String privateKey) {
String oldPrivateKey = this.privateKey;
this.privateKey = privateKey;
- if (!equal(oldPrivateKey, privateKey)) {
- firePropertyChange(PROPERTY_PRIVATE_KEY, oldPrivateKey, privateKey);
- }
+ fireIfPropertyChanged(PROPERTY_PRIVATE_KEY, oldPrivateKey, privateKey);
}
/**
public void setBasePath(String basePath) {
String oldBasePath = this.basePath;
this.basePath = basePath;
- firePropertyChange(PROPERTY_LOCAL_PATH, oldBasePath, basePath);
+ fireIfPropertyChanged(PROPERTY_LOCAL_PATH, oldBasePath, basePath);
}
}
}
/**
+ * 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.
* @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));
}