Skip to content

Commit

Permalink
Core: Replace .size() > 0 with !.isEmpty() (#8813)
Browse files Browse the repository at this point in the history
Core: Replace .size() > 0` with `!.isEmpty() (#8813)
  • Loading branch information
PickBas authored Oct 13, 2023
1 parent a339f40 commit 2aac636
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected CloseableIterable<ScanTask> doPlanFiles() {
Snapshot snapshot = snapshot();

List<ManifestFile> deleteManifests = findMatchingDeleteManifests(snapshot);
boolean mayHaveEqualityDeletes = deleteManifests.size() > 0 && mayHaveEqualityDeletes(snapshot);
boolean mayHaveEqualityDeletes = !deleteManifests.isEmpty() && mayHaveEqualityDeletes(snapshot);
boolean planDeletesLocally = shouldPlanDeletesLocally(deleteManifests, mayHaveEqualityDeletes);

List<ManifestFile> dataManifests = findMatchingDataManifests(snapshot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private Deque<Snapshot> orderedChangelogSnapshots(Long fromIdExcl, long toIdIncl

for (Snapshot snapshot : SnapshotUtil.ancestorsBetween(table(), toIdIncl, fromIdExcl)) {
if (!snapshot.operation().equals(DataOperations.REPLACE)) {
if (snapshot.deleteManifests(table().io()).size() > 0) {
if (!snapshot.deleteManifests(table().io()).isEmpty()) {
throw new UnsupportedOperationException(
"Delete files are currently not supported in changelog scans");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected void validate(TableMetadata base, Snapshot parent) {
validateDeletedDataFiles(base, startingSnapshotId, filter, parent);
}

if (deletedDataFiles.size() > 0) {
if (!deletedDataFiles.isEmpty()) {
validateNoNewDeletesForDataFiles(
base, startingSnapshotId, conflictDetectionFilter, deletedDataFiles, parent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public BaseRewriteFiles toBranch(String branch) {
@Override
protected void validate(TableMetadata base, Snapshot parent) {
validateReplacedAndAddedFiles();
if (replacedDataFiles.size() > 0) {
if (!replacedDataFiles.isEmpty()) {
// if there are replaced data files, there cannot be any new row-level deletes for those data
// files
validateNoNewDeletesForDataFiles(base, startingSnapshotId, replacedDataFiles, parent);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/apache/iceberg/FastAppend.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private List<ManifestFile> writeNewManifests() throws IOException {
newManifests = null;
}

if (newManifests == null && newFiles.size() > 0) {
if (newManifests == null && !newFiles.isEmpty()) {
RollingManifestWriter<DataFile> writer = newRollingManifestWriter(spec);
try {
newFiles.forEach(writer::add);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ void delete(CharSequence path) {
}

boolean containsDeletes() {
return deletePaths.size() > 0
return !deletePaths.isEmpty()
|| deleteExpression != Expressions.alwaysFalse()
|| dropPartitions.size() > 0;
|| !dropPartitions.isEmpty();
}

/**
Expand Down Expand Up @@ -335,7 +335,7 @@ private boolean canContainDeletedFiles(ManifestFile manifest) {
}

boolean canContainDroppedPartitions;
if (dropPartitions.size() > 0) {
if (!dropPartitions.isEmpty()) {
canContainDroppedPartitions =
ManifestFileUtil.canContainAny(manifest, dropPartitions, specsById);
} else {
Expand All @@ -345,7 +345,7 @@ private boolean canContainDeletedFiles(ManifestFile manifest) {
boolean canContainDroppedFiles;
if (hasPathOnlyDeletes) {
canContainDroppedFiles = true;
} else if (deletePaths.size() > 0) {
} else if (!deletePaths.isEmpty()) {
// because there were no path-only deletes, the set of deleted file partitions is valid
canContainDroppedFiles =
ManifestFileUtil.canContainAny(manifest, deleteFilePartitions, specsById);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ protected boolean deletesDeleteFiles() {
}

protected boolean addsDataFiles() {
return newDataFiles.size() > 0;
return !newDataFiles.isEmpty();
}

protected boolean addsDeleteFiles() {
return newDeleteFilesBySpec.size() > 0;
return !newDeleteFilesBySpec.isEmpty();
}

/** Add a data file to the new snapshot. */
Expand Down Expand Up @@ -937,7 +937,7 @@ protected void cleanUncommitted(Set<ManifestFile> committed) {

private Iterable<ManifestFile> prepareNewDataManifests() {
Iterable<ManifestFile> newManifests;
if (newDataFiles.size() > 0) {
if (!newDataFiles.isEmpty()) {
List<ManifestFile> dataFileManifests = newDataFilesAsManifests();
newManifests = Iterables.concat(dataFileManifests, appendManifests, rewrittenAppendManifests);
} else {
Expand Down Expand Up @@ -987,7 +987,7 @@ private Iterable<ManifestFile> prepareDeleteManifests() {
}

private List<ManifestFile> newDeleteFilesAsManifests() {
if (hasNewDeleteFiles && cachedNewDeleteManifests.size() > 0) {
if (hasNewDeleteFiles && !cachedNewDeleteManifests.isEmpty()) {
for (ManifestFile cachedNewDeleteManifest : cachedNewDeleteManifests) {
deleteFile(cachedNewDeleteManifest.path());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private Schema calculateSchema() {
Types.StringType.get(),
MetadataColumns.FILE_PATH_COLUMN_DOC));

if (partitionType.fields().size() > 0) {
if (!partitionType.fields().isEmpty()) {
return result;
} else {
// avoid returning an empty struct, which is not always supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static Set<String> metadataFileLocations(Table table, boolean recursive)
private static void metadataFileLocations(
TableMetadata metadata, Set<String> metadataFileLocations, FileIO io, boolean recursive) {
List<MetadataLogEntry> metadataLogEntries = metadata.previousFiles();
if (metadataLogEntries.size() > 0) {
if (!metadataLogEntries.isEmpty()) {
for (MetadataLogEntry metadataLogEntry : metadataLogEntries) {
metadataFileLocations.add(metadataLogEntry.file());
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/apache/iceberg/SnapshotSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public Map<String, String> build() {
setIf(trustPartitionMetrics, builder, CHANGED_PARTITION_COUNT_PROP, changedPartitions.size());

if (trustPartitionMetrics && changedPartitions.size() <= maxChangedPartitionsForSummaries) {
setIf(changedPartitions.size() > 0, builder, PARTITION_SUMMARY_PROP, "true");
setIf(!changedPartitions.isEmpty(), builder, PARTITION_SUMMARY_PROP, "true");
for (String key : changedPartitions) {
setIf(
!Strings.isNullOrEmpty(key),
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/apache/iceberg/TableMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ public Builder setPreviousFileLocation(String previousFileLocation) {

private boolean hasChanges() {
return changes.size() != startingChangeCount
|| (discardChanges && changes.size() > 0)
|| (discardChanges && !changes.isEmpty())
|| metadataLocation != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public void start() {
LOG.info("Starting commit service for {}", table);
committerService.execute(
() -> {
while (running.get() || completedRewrites.size() > 0 || inProgressCommits.size() > 0) {
while (running.get() || !completedRewrites.isEmpty() || !inProgressCommits.isEmpty()) {
try {
if (completedRewrites.size() == 0 && inProgressCommits.size() == 0) {
if (completedRewrites.isEmpty() && inProgressCommits.isEmpty()) {
// give other threads a chance to make progress
Thread.sleep(100);
}
Expand All @@ -129,7 +129,7 @@ public void start() {
}

// commit whatever is left once done with writing.
if (!running.get() && completedRewrites.size() > 0) {
if (!running.get() && !completedRewrites.isEmpty()) {
commitReadyCommitGroups();
}
}
Expand Down Expand Up @@ -239,7 +239,7 @@ boolean canCreateCommitGroup() {
// Either we have a full commit group, or we have completed writing and need to commit
// what is left over
boolean fullCommitGroup = completedRewrites.size() >= rewritesPerCommit;
boolean writingComplete = !running.get() && completedRewrites.size() > 0;
boolean writingComplete = !running.get() && !completedRewrites.isEmpty();
return fullCommitGroup || writingComplete;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class RewritePositionDeletesGroup {
private Set<DeleteFile> addedDeleteFiles = Collections.emptySet();

public RewritePositionDeletesGroup(FileGroupInfo info, List<PositionDeletesScanTask> tasks) {
Preconditions.checkArgument(tasks.size() > 0, "Tasks must not be empty");
Preconditions.checkArgument(!tasks.isEmpty(), "Tasks must not be empty");
this.info = info;
this.tasks = tasks;
this.maxRewrittenDataSequenceNumber =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public CharSequenceSet referencedDataFiles() {
}

public boolean referencesDataFiles() {
return referencedDataFiles != null && referencedDataFiles.size() > 0;
return referencedDataFiles != null && !referencedDataFiles.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private PartitionUtil() {}

// add _partition
if (partitionType != null) {
if (partitionType.fields().size() > 0) {
if (!partitionType.fields().isEmpty()) {
StructLike coercedPartition = coercePartition(partitionType, spec, partitionData);
idToConstant.put(
MetadataColumns.PARTITION_COLUMN_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public ViewMetadata.Builder assignUUID(String newUUID) {

public ViewMetadata build() {
Preconditions.checkArgument(null != location, "Invalid location: null");
Preconditions.checkArgument(versions.size() > 0, "Invalid view: no versions were added");
Preconditions.checkArgument(!versions.isEmpty(), "Invalid view: no versions were added");

// when associated with a metadata file, metadata must have no changes so that the metadata
// matches exactly what is in the metadata file, which does not store changes. metadata
Expand Down

0 comments on commit 2aac636

Please sign in to comment.