Skip to content

Commit

Permalink
Add standard hashCode and equals method
Browse files Browse the repository at this point in the history
  • Loading branch information
ManfredKarrer committed Apr 21, 2017
1 parent b81d7b0 commit b9d840c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions core/src/main/java/org/bitcoinj/core/PeerAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;
import com.google.common.net.InetAddresses;
import org.bitcoinj.net.AddressChecker;
import org.bitcoinj.net.OnionCat;
Expand Down Expand Up @@ -302,14 +301,29 @@ public String toString() {

@Override
public boolean equals(Object o) {
return o.toString().equals(this.toString());
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

PeerAddress that = (PeerAddress) o;

if (port != that.port) return false;
if (time != that.time) return false;
if (addr != null ? !addr.equals(that.addr) : that.addr != null) return false;
if (hostname != null ? !hostname.equals(that.hostname) : that.hostname != null) return false;
return !(services != null ? !services.equals(that.services) : that.services != null);

}

@Override
public int hashCode() {
return Objects.hashCode(this.toString());
int result = addr != null ? addr.hashCode() : 0;
result = 31 * result + (hostname != null ? hostname.hashCode() : 0);
result = 31 * result + port;
result = 31 * result + (services != null ? services.hashCode() : 0);
result = 31 * result + (int) (time ^ (time >>> 32));
return result;
}

public InetSocketAddress toSocketAddress() {
// Reconstruct the InetSocketAddress properly
if (hostname != null) {
Expand Down

0 comments on commit b9d840c

Please sign in to comment.