Replaced size() == / > 0 with isEmpty()

This commit is contained in:
AlphaX-Projects 2024-06-29 11:54:41 +02:00
parent 95d42db773
commit 61ede811cd
18 changed files with 31 additions and 31 deletions

View File

@ -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<TransactionData> fetchTransactions(Repository repository, List<TransactionType> txTypes, String address, boolean reverse) throws DataException {

View File

@ -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<TransactionData> fetchTransactions(Repository repository, List<TransactionType> txTypes, String address, boolean reverse) throws DataException {

View File

@ -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;
}
/**

View File

@ -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;
}

View File

@ -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");
}

View File

@ -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<byte[]> chunkHashList() {
List<byte[]> 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());

View File

@ -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.

View File

@ -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<Peer> qualifiedPeers) {
List<Peer> 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 <BlockSummaryData> 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();

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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());

View File

@ -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);

View File

@ -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);

View File

@ -168,7 +168,7 @@ public class ChatTransaction extends Transaction {
// Check for blocked author by registered name
List<NameData> 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())) {

View File

@ -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

View File

@ -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");

View File

@ -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(",");