commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1557679 - /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PStmtKey.java
Date Mon, 13 Jan 2014 11:32:16 GMT
Author: markt
Date: Mon Jan 13 11:32:15 2014
New Revision: 1557679

URL: http://svn.apache.org/r1557679
Log:
Prep for fixing a FindBugs issue in a sub-class
- Add a short-cut to equals for the same object
- Use explicit tests rather than exception handling (should be faster)
- Use all of the fields for the hashCode to improve performance when used in HashTables etc.

Modified:
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PStmtKey.java

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PStmtKey.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PStmtKey.java?rev=1557679&r1=1557678&r2=1557679&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PStmtKey.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PStmtKey.java Mon Jan 13 11:32:15
2014
@@ -95,28 +95,32 @@ public class PStmtKey {
     }
 
     @Override
-    public boolean equals(Object that) {
-        try {
-            PStmtKey key = (PStmtKey)that;
-            return( ((null == _sql && null == key._sql) || _sql.equals(key._sql))
&&
-                    ((null == _catalog && null == key._catalog) || _catalog.equals(key._catalog))
&&
-                    ((null == _resultSetType && null == key._resultSetType) || _resultSetType.equals(key._resultSetType))
&&
-                    ((null == _resultSetConcurrency && null == key._resultSetConcurrency)
|| _resultSetConcurrency.equals(key._resultSetConcurrency)) &&
-                    (_stmtType == key._stmtType)
-                  );
-        } catch(ClassCastException e) {
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
             return false;
-        } catch(NullPointerException e) {
+        if (getClass() != obj.getClass())
             return false;
-        }
+        PStmtKey key = (PStmtKey) obj;
+        return( ((null == _sql && null == key._sql) || _sql.equals(key._sql)) &&
+                ((null == _catalog && null == key._catalog) || _catalog.equals(key._catalog))
&&
+                ((null == _resultSetType && null == key._resultSetType) || _resultSetType.equals(key._resultSetType))
&&
+                ((null == _resultSetConcurrency && null == key._resultSetConcurrency)
|| _resultSetConcurrency.equals(key._resultSetConcurrency)) &&
+                (_stmtType == key._stmtType)
+              );
     }
 
     @Override
     public int hashCode() {
-        if (_catalog==null)
-            return(null == _sql ? 0 : _sql.hashCode());
-        else
-            return(null == _sql ? _catalog.hashCode() : (_catalog + _sql).hashCode());
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((_catalog == null) ? 0 : _catalog.hashCode());
+        result = prime * result + ((_resultSetConcurrency == null) ? 0 : _resultSetConcurrency.hashCode());
+        result = prime * result + ((_resultSetType == null) ? 0 : _resultSetType.hashCode());
+        result = prime * result + ((_sql == null) ? 0 : _sql.hashCode());
+        result = prime * result + _stmtType;
+        return result;
     }
 
     @Override



Mime
View raw message