Ticket #269: Added hashcode functions for MySQLUSer and MySQLConnection.

This commit is contained in:
James Muehlner
2013-02-20 12:49:45 -08:00
parent 39665ad0f6
commit df50454f15
2 changed files with 26 additions and 3 deletions

View File

@@ -91,7 +91,6 @@ public class MySQLConnection implements Connection {
* @param connection
*/
public void initNew(Connection connection) {
configuration = connection.getConfiguration();
this.connection.setConnection_name(connection.getIdentifier());
this.configuration = connection.getConfiguration();
}
@@ -150,7 +149,19 @@ public class MySQLConnection implements Connection {
public boolean equals(Object other) {
if(!(other instanceof MySQLConnection))
return false;
return ((MySQLConnection)other).getConnectionID() == this.getConnectionID();
boolean idsAreEqual = ((MySQLConnection)other).getConnectionID() == this.getConnectionID();
// they are both new, check if they have the same name
if(idsAreEqual && this.getConnectionID() == 0)
return this.getIdentifier().equals(((MySQLConnection)other).getIdentifier());
return idsAreEqual;
}
@Override
public int hashCode() {
int hash = 7;
hash = 73 * hash + getConnectionID();
hash = 73 * hash + getIdentifier().hashCode();
return hash;
}
@Override

View File

@@ -207,6 +207,18 @@ public class MySQLUser implements User {
public boolean equals(Object other) {
if(!(other instanceof MySQLUser))
return false;
return ((MySQLUser)other).getUserID() == this.getUserID();
boolean idsAreEqual = ((MySQLUser)other).getUserID() == this.getUserID();
// they are both new, check if they have the same name
if(idsAreEqual && this.getUserID() == 0)
return this.getUsername().equals(((MySQLUser)other).getUsername());
return idsAreEqual;
}
@Override
public int hashCode() {
int hash = 7;
hash = 73 * hash + getUserID();
hash = 73 * hash + getUsername().hashCode();
return hash;
}
}