Skip to content

Commit

Permalink
Use JDK7+ Objects.hash() and equals() rather than the Guava variants.
Browse files Browse the repository at this point in the history
The Guava variants are “deprecated” for JDK7+.

(cherry picked from commit 686a10ccd2c6bd06a7c785e1c637b611a6b8c0d0)
Signed-off-by: HashEngineering <[email protected]>
  • Loading branch information
msgilligan authored and HashEngineering committed Jun 25, 2024
1 parent ed21434 commit 252eef5
Show file tree
Hide file tree
Showing 34 changed files with 90 additions and 91 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.bitcoinj.script.Script.ScriptType;
import org.bitcoinj.script.ScriptPattern;

import com.google.common.base.Objects;
import java.util.Objects;

/**
* <p>A Bitcoin address looks like 1MsScoe2fTJoq4ZPdQgqyhgWeoNamYPevy and is derived from an elliptic curve public key
Expand Down Expand Up @@ -284,7 +284,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), p2sh);
return Objects.hash(super.hashCode(), p2sh);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/BloomFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import org.bitcoinj.script.ScriptPattern;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.Math.*;
Expand Down Expand Up @@ -373,7 +373,7 @@ public synchronized boolean equals(Object o) {

@Override
public synchronized int hashCode() {
return Objects.hashCode(hashFuncs, nTweak, Arrays.hashCode(data));
return Objects.hash(hashFuncs, nTweak, Arrays.hashCode(data));
}

public final byte[] getData() {
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/org/bitcoinj/core/ECKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedBytes;
import org.bitcoin.NativeSecp256k1;
Expand Down Expand Up @@ -62,6 +61,7 @@
import java.security.SignatureException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;

import static com.google.common.base.Preconditions.*;

Expand Down Expand Up @@ -611,7 +611,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(r, s);
return Objects.hash(r, s);
}
}

Expand Down Expand Up @@ -1340,11 +1340,11 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof ECKey)) return false;
ECKey other = (ECKey) o;
return Objects.equal(this.priv, other.priv)
&& Objects.equal(this.pub, other.pub)
&& Objects.equal(this.creationTimeSeconds, other.creationTimeSeconds)
&& Objects.equal(this.keyCrypter, other.keyCrypter)
&& Objects.equal(this.encryptedPrivateKey, other.encryptedPrivateKey);
return Objects.equals(this.priv, other.priv)
&& Objects.equals(this.pub, other.pub)
&& Objects.equals(this.creationTimeSeconds, other.creationTimeSeconds)
&& Objects.equals(this.keyCrypter, other.keyCrypter)
&& Objects.equals(this.encryptedPrivateKey, other.encryptedPrivateKey);
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/bitcoinj/core/FilteredBlock.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 java.io.IOException;
import java.io.OutputStream;
import java.util.*;
Expand Down Expand Up @@ -136,7 +135,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(associatedTransactions, header, merkleTree);
return Objects.hash(associatedTransactions, header, merkleTree);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/GetUTXOsMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Objects;

/**
* <p>This command is supported only by <a href="http://github.com/bitcoinxt/bitcoinxt">Bitcoin XT</a> nodes, which
Expand Down Expand Up @@ -100,6 +100,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(includeMempool, outPoints);
return Objects.hash(includeMempool, outPoints);
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/InventoryItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;
import java.util.Objects;

public class InventoryItem {

Expand Down Expand Up @@ -86,6 +86,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(type, hash);
return Objects.hash(type, hash);
}
}
6 changes: 4 additions & 2 deletions core/src/main/java/org/bitcoinj/core/NetworkParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package org.bitcoinj.core;

import org.bitcoinj.core.Block;
import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.core.VerificationException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import org.bitcoinj.net.discovery.*;
import org.bitcoinj.params.*;
import org.bitcoinj.script.*;
Expand Down Expand Up @@ -298,7 +300,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(getId());
return Objects.hash(getId());
}

/** Returns the network parameters for the given string ID or NULL if not recognized. */
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/PartialMerkleTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static org.bitcoinj.core.Utils.*;
import com.google.common.base.Objects;

/**
* <p>A data structure that contains proofs of block inclusion for one or more transactions, in an efficient manner.</p>
Expand Down Expand Up @@ -275,7 +275,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(transactionCount, hashes, Arrays.hashCode(matchedChildBits));
return Objects.hash(transactionCount, hashes, Arrays.hashCode(matchedChildBits));
}

@Override
Expand Down
9 changes: 4 additions & 5 deletions core/src/main/java/org/bitcoinj/core/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;
import com.google.common.collect.Lists;

import org.bitcoinj.coinjoin.CoinJoinQueue;
import org.bitcoinj.core.listeners.*;
import org.bitcoinj.evolution.SimplifiedMasternodeListDiff;
Expand All @@ -42,10 +39,12 @@
import org.bitcoinj.wallet.Wallet;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
Expand Down Expand Up @@ -1764,7 +1763,7 @@ private void blockChainDownloadLocked(Sha256Hash toHash) {
StoredBlock chainHead = blockChain.getChainHead();
Sha256Hash chainHeadHash = chainHead.getHeader().getHash();
// Did we already make this request? If so, don't do it again.
if (Objects.equal(lastGetBlocksBegin, chainHeadHash) && Objects.equal(lastGetBlocksEnd, toHash)) {
if (Objects.equals(lastGetBlocksBegin, chainHeadHash) && Objects.equals(lastGetBlocksEnd, toHash)) {
log.info("blockChainDownloadLocked({}): ignoring duplicated request: {}", toHash, chainHeadHash);
for (Sha256Hash hash : pendingBlockDownloads)
log.info("Pending block download: {}", hash);
Expand Down Expand Up @@ -1841,7 +1840,7 @@ private void blockChainHeaderDownloadLocked(Sha256Hash toHash) {
StoredBlock chainHead = headerChain.getChainHead();
Sha256Hash chainHeadHash = chainHead.getHeader().getHash();
// Did we already make this request? If so, don't do it again.
if (Objects.equal(lastGetHeadersBegin, chainHeadHash) && Objects.equal(lastGetHeadersEnd, toHash)) {
if (Objects.equals(lastGetHeadersBegin, chainHeadHash) && Objects.equals(lastGetHeadersEnd, toHash)) {
log.info("blockChainDownloadLocked({}): ignoring duplicated request: {}", toHash, chainHeadHash);
for (Sha256Hash hash : pendingBlockDownloads)
log.info("Pending block download: {}", hash);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/PeerAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkNotNull;

Expand Down Expand Up @@ -209,7 +209,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(addr, port, time, services);
return Objects.hash(addr, port, time, services);
}

public InetSocketAddress toSocketAddress() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Objects;

import com.google.common.base.Objects;
import com.google.common.primitives.UnsignedBytes;
import static com.google.common.base.Preconditions.checkNotNull;

Expand Down Expand Up @@ -59,7 +59,7 @@ public final NetworkParameters getParameters() {

@Override
public int hashCode() {
return Objects.hashCode(params, Arrays.hashCode(bytes));
return Objects.hash(params, Arrays.hashCode(bytes));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/RejectMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Objects;

/**
* <p>A message sent by nodes when a message we sent was rejected (ie a transaction had too little fee/was invalid/etc).</p>
Expand Down Expand Up @@ -164,6 +164,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(message, code, reason, messageHash);
return Objects.hash(message, code, reason, messageHash);
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/StoredBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.BlockStoreException;
import com.google.common.base.Objects;

import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.Locale;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkState;

Expand Down Expand Up @@ -91,7 +91,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(header, chainWork, height);
return Objects.hash(header, chainWork, height);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/TransactionInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
import org.bitcoinj.wallet.RedeemData;

import com.google.common.base.Joiner;
import com.google.common.base.Objects;

import javax.annotation.Nullable;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;
Expand Down Expand Up @@ -505,7 +505,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(sequence, outpoint, Arrays.hashCode(scriptBytes));
return Objects.hash(sequence, outpoint, Arrays.hashCode(scriptBytes));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/TransactionOutPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.bitcoinj.core;

import com.google.common.base.Objects;
import org.bitcoinj.script.*;
import org.bitcoinj.wallet.*;

import javax.annotation.*;
import java.io.*;
import java.util.Objects;

import static com.google.common.base.Preconditions.*;

Expand Down Expand Up @@ -223,6 +223,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(getIndex(), getHash());
return Objects.hash(getIndex(), getHash());
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/TransactionOutput.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 org.bitcoinj.script.*;
import org.bitcoinj.wallet.Wallet;
import org.slf4j.*;
Expand All @@ -26,6 +25,7 @@
import java.io.*;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static com.google.common.base.Preconditions.*;

Expand Down Expand Up @@ -408,6 +408,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hashCode(value, parent, Arrays.hashCode(scriptBytes));
return Objects.hash(value, parent, Arrays.hashCode(scriptBytes));
}
}
Loading

0 comments on commit 252eef5

Please sign in to comment.