Skip to content

Commit

Permalink
Replace .size() > 0 with .isNotEmpty() (#8819)
Browse files Browse the repository at this point in the history
* [ISSUE #8810] aliyun/*: replaced .size() > 0 with isEmpty()

* [ISSUE #8810] mr/*: replaced .size() > 0 with isEmpty()

* [ISSUE #8810] flink/*: replaced .size() > 0 with isEmpty()

* [ISSUE #8810] delta-lake/*: replaced .size() > 0 with isEmpty()

* [ISSUE #8810] hive3/*: replaced .size() > 0 with isEmpty()

* [ISSUE #8810] api/*: replaced .size() > 0 with isEmpty()

* [ISSUE #8810] aws/*: replaced .size() > 0 with isEmpty()

* Simplified assertion

* [ISSUE #8810] parquet/*: replaced .size() > 0 with isEmpty()

* [ISSUE #8810] data/*: replaced .size() > 0 with isEmpty()

* Updated indentation

Co-authored-by: Fokko Driesprong <[email protected]>

---------

Co-authored-by: Fokko Driesprong <[email protected]>
  • Loading branch information
PickBas and Fokko authored Oct 13, 2023
1 parent 8463d66 commit 2268bd8
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Bucket getBucket(String bucketName) {
findBucketsByFilter(
file -> Files.isDirectory(file) && file.getFileName().endsWith(bucketName));

return buckets.size() > 0 ? buckets.get(0) : null;
return !buckets.isEmpty() ? buckets.get(0) : null;
}

void deleteBucket(String bucketName) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static ResidualEvaluator unpartitioned(Expression expr) {
* @return a residual evaluator for the expression
*/
public static ResidualEvaluator of(PartitionSpec spec, Expression expr, boolean caseSensitive) {
if (spec.fields().size() > 0) {
if (!spec.fields().isEmpty()) {
return new ResidualEvaluator(spec, expr, caseSensitive);
} else {
return unpartitioned(expr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testNamespaceExists() {
public void testListNamespace() {
String namespace = createNamespace();
List<Namespace> namespaceList = glueCatalog.listNamespaces();
Assert.assertTrue(namespaceList.size() > 0);
Assert.assertFalse(namespaceList.isEmpty());
Assert.assertTrue(namespaceList.contains(Namespace.of(namespace)));
namespaceList = glueCatalog.listNamespaces(Namespace.of(namespace));
Assert.assertTrue(namespaceList.isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ private boolean shouldReadOrc(Expression expression, boolean caseSensitive) {
.filter(expression)
.caseSensitive(caseSensitive)
.build()) {
return Lists.newArrayList(reader).size() > 0;
return !Lists.newArrayList(reader).isEmpty();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private boolean shouldReadOrc(Object value) {
.createReaderFunc(fileSchema -> GenericOrcReader.buildReader(SCHEMA, fileSchema))
.filter(Expressions.equal(column, value))
.build()) {
return Lists.newArrayList(reader).size() > 0;
return !Lists.newArrayList(reader).isEmpty();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,18 @@ private void commitDeltaVersionLogToIcebergTransaction(
migratedDataFilesBuilder.add(dataFile.path().toString());
}

if (filesToAdd.size() > 0 && filesToRemove.size() > 0) {
if (!filesToAdd.isEmpty() && !filesToRemove.isEmpty()) {
// OverwriteFiles case
OverwriteFiles overwriteFiles = transaction.newOverwrite();
filesToAdd.forEach(overwriteFiles::addFile);
filesToRemove.forEach(overwriteFiles::deleteFile);
overwriteFiles.commit();
} else if (filesToAdd.size() > 0) {
} else if (!filesToAdd.isEmpty()) {
// AppendFiles case
AppendFiles appendFiles = transaction.newAppend();
filesToAdd.forEach(appendFiles::appendFile);
appendFiles.commit();
} else if (filesToRemove.size() > 0) {
} else if (!filesToRemove.isEmpty()) {
// DeleteFiles case
DeleteFiles deleteFiles = transaction.newDelete();
filesToRemove.forEach(deleteFiles::deleteFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private String operatorName(String suffix) {
@VisibleForTesting
List<Integer> checkAndGetEqualityFieldIds() {
List<Integer> equalityFieldIds = Lists.newArrayList(table.schema().identifierFieldIds());
if (equalityFieldColumns != null && equalityFieldColumns.size() > 0) {
if (equalityFieldColumns != null && !equalityFieldColumns.isEmpty()) {
Set<Integer> equalityFieldSet =
Sets.newHashSetWithExpectedSize(equalityFieldColumns.size());
for (String column : equalityFieldColumns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private String operatorName(String suffix) {
@VisibleForTesting
List<Integer> checkAndGetEqualityFieldIds() {
List<Integer> equalityFieldIds = Lists.newArrayList(table.schema().identifierFieldIds());
if (equalityFieldColumns != null && equalityFieldColumns.size() > 0) {
if (equalityFieldColumns != null && !equalityFieldColumns.isEmpty()) {
Set<Integer> equalityFieldSet =
Sets.newHashSetWithExpectedSize(equalityFieldColumns.size());
for (String column : equalityFieldColumns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private String operatorName(String suffix) {
@VisibleForTesting
List<Integer> checkAndGetEqualityFieldIds() {
List<Integer> equalityFieldIds = Lists.newArrayList(table.schema().identifierFieldIds());
if (equalityFieldColumns != null && equalityFieldColumns.size() > 0) {
if (equalityFieldColumns != null && !equalityFieldColumns.isEmpty()) {
Set<Integer> equalityFieldSet =
Sets.newHashSetWithExpectedSize(equalityFieldColumns.size());
for (String column : equalityFieldColumns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private void unregisterSubtaskGateway(int subtaskIndex, int attemptNumber) {

private OperatorCoordinator.SubtaskGateway getSubtaskGateway(int subtaskIndex) {
Preconditions.checkState(
gateways[subtaskIndex].size() > 0,
!gateways[subtaskIndex].isEmpty(),
"Coordinator of %s subtask %d is not ready yet to receive events",
operatorName,
subtaskIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public long getFileLength() {
* @return true if is ACID
*/
public boolean isAcid() {
return hasBase || deltas.size() > 0;
return hasBase || !deltas.isEmpty();
}

public long getProjectedColumnsUncompressedSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void abortJob(JobContext originalContext, int status) throws IOException
dataFiles(fileExecutor, table.location(), jobContext, table.io(), false);

// Check if we have files already committed and remove data files if there are any
if (dataFiles.size() > 0) {
if (!dataFiles.isEmpty()) {
Tasks.foreach(dataFiles)
.retry(3)
.suppressFailureWhenFinished()
Expand Down Expand Up @@ -327,7 +327,7 @@ private void commitTable(

Collection<DataFile> dataFiles = dataFiles(executor, location, jobContext, io, true);

if (dataFiles.size() > 0) {
if (!dataFiles.isEmpty()) {
// Appending data files to the table
AppendFiles append = table.newAppend();
dataFiles.forEach(append::appendFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private boolean eval(
Binder.boundReferences(schema.asStruct(), ImmutableList.of(expr), caseSensitive);
// If the filter's column set doesn't overlap with any bloom filter columns, exit early with
// ROWS_MIGHT_MATCH
if (filterRefs.size() > 0 && Sets.intersection(fieldsWithBloomFilter, filterRefs).isEmpty()) {
if (!filterRefs.isEmpty() && Sets.intersection(fieldsWithBloomFilter, filterRefs).isEmpty()) {
return ROWS_MIGHT_MATCH;
}

Expand Down

0 comments on commit 2268bd8

Please sign in to comment.