/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.dbcp2.datasources;

import java.io.Serializable;

/**
 * @since 2.0
 */
class PoolKey implements Serializable {
    private static final long serialVersionUID = 2252771047542484533L;

    private final String dataSourceName;
    private final String username;

    PoolKey(final String dataSourceName, final String username) {
        this.dataSourceName = dataSourceName;
        this.username = username;
    }

    @Override
    public boolean equals(final Object obj) {
        if (obj instanceof PoolKey) {
            final PoolKey pk = (PoolKey)obj;
            return (null == dataSourceName ? null == pk.dataSourceName : dataSourceName.equals(pk.dataSourceName)) &&
                (null == username ? null == pk.username : username.equals(pk.username));
        }
        return false;
    }

    @Override
    public int hashCode() {
        int h = 0;
        if (dataSourceName != null) {
            h += dataSourceName.hashCode();
        }
        if (username != null) {
            h = 29 * h + username.hashCode();
        }
        return h;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer(50);
        sb.append("PoolKey(");
        sb.append(username).append(", ").append(dataSourceName);
        sb.append(')');
        return sb.toString();
    }
}

@@ -1074,25 +1074,25 @@
  String user
-n
+N
 ame;%0A%0A    Po
@@ -1210,25 +1210,25 @@
    this.user
-n
+N
 ame = userna
@@ -1278,22 +1278,16 @@
  equals(
-final 
 Object o
@@ -1308,51 +1308,208 @@
 if (
-obj instanceof PoolKey) %7B%0A            final
+this == obj) %7B%0A            return true;%0A        %7D%0A        if (obj == null) %7B%0A            return false;%0A        %7D%0A        if (getClass() != obj.getClass()) %7B%0A            return false;%0A        %7D%0A       
  Poo
@@ -1513,18 +1513,21 @@
 PoolKey 
-pk
+other
  = (Pool
@@ -1530,16 +1530,17 @@
 PoolKey)
+ 
 obj;%0A   
@@ -1548,28 +1548,12 @@
     
-    return (null == 
+if (
 data
@@ -1567,38 +1567,131 @@
 ame 
-?
+==
  null
- == pk.dataSourceName : 
+) %7B%0A            if (other.dataSourceName != null) %7B%0A                return false;%0A            %7D%0A        %7D else if (!
 data
@@ -1708,18 +1708,21 @@
 .equals(
-pk
+other
 .dataSou
@@ -1735,10 +1735,35 @@
 e)) 
-&&
+%7B%0A            return false;
 %0A   
@@ -1767,24 +1767,26 @@
         
+%7D%0A
         
 (null ==
@@ -1781,55 +1781,143 @@
     
-(null == 
+if (userName == null) %7B%0A            if (other.
 user
-n
+N
 ame 
-?
+!=
  null
- == pk.username : 
+) %7B%0A                return false;%0A            %7D%0A        %7D else if (!
 user
-n
+N
 ame.
@@ -1927,21 +1927,51 @@
 als(
-pk
+other
 .user
-n
+N
 ame))
+ %7B%0A            return false
 ;%0A  
@@ -1989,28 +1989,27 @@
      return 
-fals
+tru
 e;%0A    %7D%0A%0A  
@@ -2060,17 +2060,28 @@
     
-int h = 0
+final int prime = 31
 ;%0A  
@@ -2079,34 +2079,82 @@
  = 31;%0A        i
-f 
+nt result = 1;%0A        result = prime * result + (
 (dataSourceName 
@@ -2149,33 +2149,33 @@
 aSourceName 
-!
+=
 = null) 
 %7B%0A          
@@ -2166,26 +2166,13 @@
 ll) 
-%7B%0A            h +=
+? 0 :
  dat
@@ -2185,32 +2185,33 @@
 eName.hashCode()
+)
 ;%0A        %7D%0A    
@@ -2208,40 +2208,54 @@
     
-%7D%0A        if 
+result = prime * result + (
 (user
-n
+N
 ame 
-!
+=
 = null) 
 %7B%0A  
@@ -2254,40 +2254,19 @@
 ll) 
-%7B%0A            h = 29 * h +
+? 0 :
  user
-n
+N
 ame.
@@ -2275,16 +2275,17 @@
 shCode()
+)
 ;%0A      
@@ -2290,26 +2290,21 @@
     
-%7D%0A        
 return 
-h
+result
 ;%0A  
@@ -2456,25 +2456,25 @@
 .append(user
-n
+N
 ame).append(

Use Eclipse generated hashCode() and equals(). Better ivar name.