diff --git a/src/main/java/org/qortal/account/SelfSponsorshipAlgoV1.java b/src/main/java/org/qortal/account/SelfSponsorshipAlgoV1.java index 65092602..de8663a9 100644 --- a/src/main/java/org/qortal/account/SelfSponsorshipAlgoV1.java +++ b/src/main/java/org/qortal/account/SelfSponsorshipAlgoV1.java @@ -340,7 +340,7 @@ public class SelfSponsorshipAlgoV1 { return true; } transactionDataList.removeIf(t -> t.getTimestamp() >= this.snapshotTimestamp); - return transactionDataList.size() == 0; + return transactionDataList.isEmpty(); } private static List fetchTransactions(Repository repository, List txTypes, String address, boolean reverse) throws DataException { diff --git a/src/main/java/org/qortal/account/SelfSponsorshipAlgoV3.java b/src/main/java/org/qortal/account/SelfSponsorshipAlgoV3.java index 80c1ba2f..3010b39d 100644 --- a/src/main/java/org/qortal/account/SelfSponsorshipAlgoV3.java +++ b/src/main/java/org/qortal/account/SelfSponsorshipAlgoV3.java @@ -344,7 +344,7 @@ public class SelfSponsorshipAlgoV3 { return true; } transactionDataList.removeIf(t -> t.getTimestamp() <= this.snapshotTimestampV1 || t.getTimestamp() >= this.snapshotTimestampV3); - return transactionDataList.size() == 0; + return transactionDataList.isEmpty(); } private static List fetchTransactions(Repository repository, List txTypes, String address, boolean reverse) throws DataException { diff --git a/src/main/java/org/qortal/api/ApiRequest.java b/src/main/java/org/qortal/api/ApiRequest.java index 59bd791a..8036c8d9 100644 --- a/src/main/java/org/qortal/api/ApiRequest.java +++ b/src/main/java/org/qortal/api/ApiRequest.java @@ -141,7 +141,7 @@ public class ApiRequest { } String resultString = result.toString(); - return resultString.length() > 0 ? resultString.substring(0, resultString.length() - 1) : resultString; + return !resultString.isEmpty() ? resultString.substring(0, resultString.length() - 1) : resultString; } /** diff --git a/src/main/java/org/qortal/api/gateway/resource/GatewayResource.java b/src/main/java/org/qortal/api/gateway/resource/GatewayResource.java index 7169fd4a..a6ec61b6 100644 --- a/src/main/java/org/qortal/api/gateway/resource/GatewayResource.java +++ b/src/main/java/org/qortal/api/gateway/resource/GatewayResource.java @@ -140,7 +140,7 @@ public class GatewayResource { } String prefix = StringUtils.join(prefixParts, "/"); - if (prefix != null && prefix.length() > 0) { + if (prefix != null && !prefix.isEmpty()) { prefix = "/" + prefix; } diff --git a/src/main/java/org/qortal/arbitrary/ArbitraryDataBuilder.java b/src/main/java/org/qortal/arbitrary/ArbitraryDataBuilder.java index f438cef6..34130742 100644 --- a/src/main/java/org/qortal/arbitrary/ArbitraryDataBuilder.java +++ b/src/main/java/org/qortal/arbitrary/ArbitraryDataBuilder.java @@ -104,7 +104,7 @@ public class ArbitraryDataBuilder { if (latestPut.getMethod() != Method.PUT) { throw new DataException("Expected PUT but received PATCH"); } - if (transactionDataList.size() == 0) { + if (transactionDataList.isEmpty()) { throw new DataException(String.format("No transactions found for name %s, service %s, " + "identifier: %s, since %d", name, service, this.identifierString(), latestPut.getTimestamp())); } @@ -176,7 +176,7 @@ public class ArbitraryDataBuilder { } private void findLatestSignature() throws DataException { - if (this.transactions.size() == 0) { + if (this.transactions.isEmpty()) { throw new DataException("Unable to find latest signature from empty transaction list"); } diff --git a/src/main/java/org/qortal/arbitrary/ArbitraryDataFile.java b/src/main/java/org/qortal/arbitrary/ArbitraryDataFile.java index 1bba1a73..6e1ca0b9 100644 --- a/src/main/java/org/qortal/arbitrary/ArbitraryDataFile.java +++ b/src/main/java/org/qortal/arbitrary/ArbitraryDataFile.java @@ -354,7 +354,7 @@ public class ArbitraryDataFile { public boolean join() { // Ensure we have chunks - if (this.chunks != null && this.chunks.size() > 0) { + if (this.chunks != null && !this.chunks.isEmpty()) { // Create temporary path for joined file // Use the user-specified temp dir, as it is deterministic, and is more likely to be located on reusable storage hardware @@ -439,7 +439,7 @@ public class ArbitraryDataFile { boolean success = false; // Delete the individual chunks - if (this.chunks != null && this.chunks.size() > 0) { + if (this.chunks != null && !this.chunks.isEmpty()) { Iterator iterator = this.chunks.iterator(); while (iterator.hasNext()) { ArbitraryDataFileChunk chunk = (ArbitraryDataFileChunk) iterator.next(); @@ -709,7 +709,7 @@ public class ArbitraryDataFile { } public byte[] chunkHashes() throws DataException { - if (this.chunks != null && this.chunks.size() > 0) { + if (this.chunks != null && !this.chunks.isEmpty()) { // Return null if we only have one chunk, with the same hash as the parent if (Arrays.equals(this.digest(), this.chunks.get(0).digest())) { return null; @@ -736,7 +736,7 @@ public class ArbitraryDataFile { public List chunkHashList() { List chunks = new ArrayList<>(); - if (this.chunks != null && this.chunks.size() > 0) { + if (this.chunks != null && !this.chunks.isEmpty()) { // Return null if we only have one chunk, with the same hash as the parent if (Arrays.equals(this.digest(), this.chunks.get(0).digest())) { return null; @@ -820,7 +820,7 @@ public class ArbitraryDataFile { String outputString = ""; if (this.chunkCount() > 0) { for (ArbitraryDataFileChunk chunk : this.chunks) { - if (outputString.length() > 0) { + if (!outputString.isEmpty()) { outputString = outputString.concat(","); } outputString = outputString.concat(chunk.digest58()); diff --git a/src/main/java/org/qortal/block/Block.java b/src/main/java/org/qortal/block/Block.java index caaa0c76..bacff5b4 100644 --- a/src/main/java/org/qortal/block/Block.java +++ b/src/main/java/org/qortal/block/Block.java @@ -1086,7 +1086,7 @@ public class Block { // Online accounts should only be included in designated blocks; all others must be empty if (!this.isOnlineAccountsBlock()) { - if (this.blockData.getOnlineAccountsCount() != 0 || accountIndexes.size() != 0) { + if (this.blockData.getOnlineAccountsCount() != 0 || !accountIndexes.isEmpty()) { return ValidationResult.ONLINE_ACCOUNTS_INVALID; } // Not a designated online accounts block and account count is 0. Everything is correct so no need to validate further. diff --git a/src/main/java/org/qortal/controller/Synchronizer.java b/src/main/java/org/qortal/controller/Synchronizer.java index e15db208..5cffdbd4 100644 --- a/src/main/java/org/qortal/controller/Synchronizer.java +++ b/src/main/java/org/qortal/controller/Synchronizer.java @@ -258,7 +258,7 @@ public class Synchronizer extends Thread { peers.removeIf(Controller.hasNoRecentBlock); final int peersRemoved = peersBeforeComparison - peers.size(); - if (peersRemoved > 0 && peers.size() > 0) + if (peersRemoved > 0 && !peers.isEmpty()) LOGGER.debug(String.format("Ignoring %d peers on inferior chains. Peers remaining: %d", peersRemoved, peers.size())); if (peers.isEmpty()) @@ -392,7 +392,7 @@ public class Synchronizer extends Thread { private boolean checkRecoveryModeForPeers(List qualifiedPeers) { List handshakedPeers = Network.getInstance().getImmutableHandshakedPeers(); - if (handshakedPeers.size() > 0) { + if (!handshakedPeers.isEmpty()) { // There is at least one handshaked peer if (qualifiedPeers.isEmpty()) { // There are no 'qualified' peers - i.e. peers that have a recent block we can sync to @@ -445,7 +445,7 @@ public class Synchronizer extends Thread { try (final Repository repository = RepositoryManager.getRepository()) { try { - if (peers.size() == 0) + if (peers.isEmpty()) return SynchronizationResult.NOTHING_TO_DO; // If our latest block is very old, it's best that we don't try and determine the best peers to sync to. @@ -701,7 +701,7 @@ public class Synchronizer extends Thread { // Reduce minChainLength if needed. If we don't have any blocks, this peer will be excluded from chain weight comparisons later in the process, so we shouldn't update minChainLength List peerBlockSummaries = peer.getCommonBlockData().getBlockSummariesAfterCommonBlock(); - if (peerBlockSummaries != null && peerBlockSummaries.size() > 0) + if (peerBlockSummaries != null && !peerBlockSummaries.isEmpty()) if (peerBlockSummaries.size() < minChainLength) minChainLength = peerBlockSummaries.size(); } @@ -728,7 +728,7 @@ public class Synchronizer extends Thread { // Calculate our chain weight BigInteger ourChainWeight = BigInteger.valueOf(0); - if (ourBlockSummaries.size() > 0) + if (!ourBlockSummaries.isEmpty()) ourChainWeight = Block.calcChainWeight(commonBlockSummary.getHeight(), commonBlockSummary.getSignature(), ourBlockSummaries, maxHeightForChainWeightComparisons); LOGGER.debug(String.format("Our chain weight based on %d blocks is %s", (usingSameLengthChainWeight ? minChainLength : ourBlockSummaries.size()), accurateFormatter.format(ourChainWeight))); @@ -780,7 +780,7 @@ public class Synchronizer extends Thread { } // Now that we have selected the best peers, compare them against each other and remove any with lower weights - if (superiorPeersForComparison.size() > 0) { + if (!superiorPeersForComparison.isEmpty()) { BigInteger bestChainWeight = null; for (Peer peer : superiorPeersForComparison) { // Increase bestChainWeight if needed @@ -1290,7 +1290,7 @@ public class Synchronizer extends Thread { cachedCommonBlockData.setBlockSummariesAfterCommonBlock(null); // If we have already received newer blocks from this peer that what we have already, go ahead and apply them - if (peerBlocks.size() > 0) { + if (!peerBlocks.isEmpty()) { final BlockData ourLatestBlockData = repository.getBlockRepository().getLastBlock(); final Block peerLatestBlock = peerBlocks.get(peerBlocks.size() - 1); final Long minLatestBlockTimestamp = Controller.getMinimumLatestBlockTimestamp(); @@ -1352,7 +1352,7 @@ public class Synchronizer extends Thread { if (retryCount >= maxRetries) { // If we have already received newer blocks from this peer that what we have already, go ahead and apply them - if (peerBlocks.size() > 0) { + if (!peerBlocks.isEmpty()) { final BlockData ourLatestBlockData = repository.getBlockRepository().getLastBlock(); final Block peerLatestBlock = peerBlocks.get(peerBlocks.size() - 1); final Long minLatestBlockTimestamp = Controller.getMinimumLatestBlockTimestamp(); diff --git a/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataFileListManager.java b/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataFileListManager.java index 5ed8df21..1d5e4149 100644 --- a/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataFileListManager.java +++ b/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataFileListManager.java @@ -605,7 +605,7 @@ public class ArbitraryDataFileListManager { } // Add the chunk hashes - if (arbitraryDataFile.getChunkHashes().size() > 0) { + if (!arbitraryDataFile.getChunkHashes().isEmpty()) { requestedHashes.addAll(arbitraryDataFile.getChunkHashes()); } // Add complete file if there are no hashes @@ -641,7 +641,7 @@ public class ArbitraryDataFileListManager { } // We should only respond if we have at least one hash - if (hashes.size() > 0) { + if (!hashes.isEmpty()) { // Firstly we should keep track of the requesting peer, to allow for potential direct connections later ArbitraryDataFileManager.getInstance().addRecentDataRequest(requestingPeer); diff --git a/src/main/java/org/qortal/controller/repository/NamesDatabaseIntegrityCheck.java b/src/main/java/org/qortal/controller/repository/NamesDatabaseIntegrityCheck.java index 698ad487..35981976 100644 --- a/src/main/java/org/qortal/controller/repository/NamesDatabaseIntegrityCheck.java +++ b/src/main/java/org/qortal/controller/repository/NamesDatabaseIntegrityCheck.java @@ -207,7 +207,7 @@ public class NamesDatabaseIntegrityCheck { // FUTURE: check database integrity for names that have been updated and then the original name re-registered else if (Objects.equals(updateNameTransactionData.getName(), registeredName)) { String newName = updateNameTransactionData.getNewName(); - if (newName == null || newName.length() == 0) { + if (newName == null || newName.isEmpty()) { // If new name is blank (or maybe null, just to be safe), it means that it stayed the same newName = registeredName; } diff --git a/src/main/java/org/qortal/crosschain/Bitcoiny.java b/src/main/java/org/qortal/crosschain/Bitcoiny.java index 1ae70fe9..7f624e20 100644 --- a/src/main/java/org/qortal/crosschain/Bitcoiny.java +++ b/src/main/java/org/qortal/crosschain/Bitcoiny.java @@ -757,7 +757,7 @@ public abstract class Bitcoiny implements ForeignBlockchain { Address address = Address.fromKey(this.params, keyChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS), ScriptType.P2PKH); // if zero transactions, return address - if( 0 == getAddressTransactions(ScriptBuilder.createOutputScript(address).getProgram(), true).size() ) + if(getAddressTransactions(ScriptBuilder.createOutputScript(address).getProgram(), true).isEmpty()) return address.toString(); // else try the next receive funds address diff --git a/src/main/java/org/qortal/network/Network.java b/src/main/java/org/qortal/network/Network.java index b42ab450..0e5885ad 100644 --- a/src/main/java/org/qortal/network/Network.java +++ b/src/main/java/org/qortal/network/Network.java @@ -810,7 +810,7 @@ public class Network { .filter(peer -> peer.hasReachedMaxConnectionAge()) .collect(Collectors.toList()); - if (peersToDisconnect != null && peersToDisconnect.size() > 0) { + if (peersToDisconnect != null && !peersToDisconnect.isEmpty()) { for (Peer peer : peersToDisconnect) { LOGGER.debug("Forcing disconnection of peer {} because connection age ({} ms) " + "has reached the maximum ({} ms)", peer, peer.getConnectionAge(), peer.getMaxConnectionAge()); diff --git a/src/main/java/org/qortal/network/Peer.java b/src/main/java/org/qortal/network/Peer.java index 821f368c..fc28ea87 100644 --- a/src/main/java/org/qortal/network/Peer.java +++ b/src/main/java/org/qortal/network/Peer.java @@ -859,7 +859,7 @@ public class Peer { } } - if (logStats && this.receivedMessageStats.size() > 0) { + if (logStats && !this.receivedMessageStats.isEmpty()) { StringBuilder statsBuilder = new StringBuilder(1024); statsBuilder.append("peer ").append(this).append(" message stats:\n=received="); appendMessageStats(statsBuilder, this.receivedMessageStats); diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java index eaa7be2a..c49074c5 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBArbitraryRepository.java @@ -1024,7 +1024,7 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository { String tag5 = null; if (tags != null) { - if (tags.size() > 0) tag1 = tags.get(0); + if (!tags.isEmpty()) tag1 = tags.get(0); if (tags.size() > 1) tag2 = tags.get(1); if (tags.size() > 2) tag3 = tags.get(2); if (tags.size() > 3) tag4 = tags.get(3); diff --git a/src/main/java/org/qortal/transaction/ChatTransaction.java b/src/main/java/org/qortal/transaction/ChatTransaction.java index 3004b5b9..a255e781 100644 --- a/src/main/java/org/qortal/transaction/ChatTransaction.java +++ b/src/main/java/org/qortal/transaction/ChatTransaction.java @@ -168,7 +168,7 @@ public class ChatTransaction extends Transaction { // Check for blocked author by registered name List names = this.repository.getNameRepository().getNamesByOwner(this.chatTransactionData.getSender()); - if (names != null && names.size() > 0) { + if (names != null && !names.isEmpty()) { for (NameData nameData : names) { if (nameData != null && nameData.getName() != null) { if (ListUtils.isNameBlocked(nameData.getName())) { diff --git a/src/main/java/org/qortal/utils/Base58.java b/src/main/java/org/qortal/utils/Base58.java index 8fa9ddad..f2ad611c 100644 --- a/src/main/java/org/qortal/utils/Base58.java +++ b/src/main/java/org/qortal/utils/Base58.java @@ -111,7 +111,7 @@ public class Base58 { // // Nothing to do if we have an empty string // - if (string.length() == 0) + if (string.isEmpty()) return null; // // Convert the input string to a byte sequence diff --git a/src/main/java/org/qortal/utils/BlockArchiveUtils.java b/src/main/java/org/qortal/utils/BlockArchiveUtils.java index 33482fc6..99670614 100644 --- a/src/main/java/org/qortal/utils/BlockArchiveUtils.java +++ b/src/main/java/org/qortal/utils/BlockArchiveUtils.java @@ -59,7 +59,7 @@ public class BlockArchiveUtils { if (firstBlock == null || firstBlock.getBlockData().getHeight() != startHeight) { throw new IllegalStateException("Non matching first block when importing from archive"); } - if (blockInfoList.size() > 0) { + if (!blockInfoList.isEmpty()) { BlockTransformation lastBlock = blockInfoList.get(blockInfoList.size() - 1); if (lastBlock == null || lastBlock.getBlockData().getHeight() != endHeight) { throw new IllegalStateException("Non matching last block when importing from archive"); diff --git a/src/main/java/org/qortal/utils/Unicode.java b/src/main/java/org/qortal/utils/Unicode.java index c3e282ce..9b837a07 100644 --- a/src/main/java/org/qortal/utils/Unicode.java +++ b/src/main/java/org/qortal/utils/Unicode.java @@ -141,7 +141,7 @@ public abstract class Unicode { while ((line = bufferedReader.readLine()) != null) { line = line.trim(); - if (line.startsWith("#") || line.length() == 0) + if (line.startsWith("#") || line.isEmpty()) continue; String[] charCodes = line.split(",");