From c75b8a54a7cc9f777c1feaabb8fdbf6e5ef7e010 Mon Sep 17 00:00:00 2001 From: pmarguerite Date: Fri, 2 Feb 2007 17:45:52 +0000 Subject: [PATCH] Added generateClientUrn method to generate a urn from client name and version. Ensures that the client urn is generated, when one of the attribute is modified. And, add support for null attribute in the equals method git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@344 be28352e-c001-0410-b1a7-c7978e42abec --- src/uk/ac/vamsas/client/ClientHandle.java | 46 ++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/uk/ac/vamsas/client/ClientHandle.java b/src/uk/ac/vamsas/client/ClientHandle.java index 6f86bce..a168c4d 100644 --- a/src/uk/ac/vamsas/client/ClientHandle.java +++ b/src/uk/ac/vamsas/client/ClientHandle.java @@ -10,15 +10,17 @@ import java.io.Serializable; */ public class ClientHandle implements Serializable { static final long serialVersionUID = 0; + /** * @param clientName * @param version */ - public ClientHandle(String clientName, String version) { + public ClientHandle(String _clientName, String _version) { super(); - this.clientName = clientName; - this.version = version; - this.setClientUrn("vamsas://"+clientName+":"+version+"/"); // TODO: decide on application handle ornthing (used to prefix new ids made by a particular application) + this.clientName = _clientName; + this.version = _version; + //this.setClientUrn("vamsas://"+clientName+":"+version+"/"); // TODO: decide on application handle ornthing (used to prefix new ids made by a particular application) + this.setClientUrn(this.generateClientUrn(this.clientName, this.version)); } /** * (non-unique) human readable vamsas client name @@ -40,10 +42,22 @@ public class ClientHandle implements Serializable { String version; /** + * Generates the client Urn from the clientName and version + * + * @param clientName (non-unique) human readable vamsas client name + * @param version version modifier + * @return a String corresponding to the clientUrn + */ + private String generateClientUrn(String _clientName, String _version) + { + return ("vamsas://"+_clientName+":"+_version+"/").intern(); + } + + /** * @return Returns the clientUrn. */ public String getClientUrn() { - return clientUrn; + return this.clientUrn; } /** @@ -51,23 +65,24 @@ public class ClientHandle implements Serializable { * @param clientUrn * The clientUrn to set. */ - public void setClientUrn(String clientUrn) { - this.clientUrn = clientUrn; + public void setClientUrn(String _clientUrn) { + this.clientUrn = _clientUrn; } /** * @return Returns the version. */ public String getVersion() { - return version; + return this.version; } /** * @param version * The version to set. */ - public void setVersion(String version) { - this.version = version; + public void setVersion(String _version) { + this.version = _version; + this.setClientUrn(this.generateClientUrn(this.clientName, this.version)); } @@ -75,15 +90,16 @@ public class ClientHandle implements Serializable { * @return Returns the clientName. */ public String getClientName() { - return clientName; + return this.clientName; } /** * @param clientName * The clientName to set. */ - public void setClientName(String clientName) { - this.clientName = clientName; + public void setClientName(String _clientName) { + this.clientName = _clientName; + this.setClientUrn(this.generateClientUrn(this.clientName, this.version)); } public boolean equals(Object that) { @@ -92,6 +108,8 @@ public class ClientHandle implements Serializable { return false; } public boolean equals(ClientHandle that) { - return (clientName.equals(that.clientName) && version.equals(that.version) && clientUrn.equals(that.clientUrn)); + return ( (this.clientName == null || this.clientName.equals(that.clientName)) + && (this.version == null || this.version.equals(that.version)) + && (this.clientUrn == null || this.clientUrn.equals(that.clientUrn))); } } -- 1.7.10.2