You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by kk...@apache.org on 2020/11/09 18:27:37 UTC
[tika] branch main updated: Simplify some equals statement by use
Objects.equals
This is an automated email from the ASF dual-hosted git repository.
kkrugler pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/main by this push:
new e8e2c6b Simplify some equals statement by use Objects.equals
new b417bf7 Merge pull request #377 from PeterAlfredLee/simplify-equals
e8e2c6b is described below
commit e8e2c6bdf0ad50d8726df527194e4f104d4c79c0
Author: PeterAlfredLee <pe...@gmail.com>
AuthorDate: Mon Nov 9 09:42:08 2020 +0800
Simplify some equals statement by use Objects.equals
---
.../tika/sax/xpath/NamedAttributeMatcher.java | 9 +++------
.../apache/tika/sax/xpath/NamedElementMatcher.java | 9 +++------
.../java/org/apache/tika/eval/EvalFilePaths.java | 22 +++++++++++++++------
.../main/java/org/apache/tika/eval/db/ColInfo.java | 23 ++++++++++++++++------
.../tika/eval/tools/TopCommonTokenCounter.java | 19 +++++++++++++-----
.../tika/parser/pdf/PDFMarkedContent2XHTML.java | 14 +++++++++----
6 files changed, 63 insertions(+), 33 deletions(-)
diff --git a/tika-core/src/main/java/org/apache/tika/sax/xpath/NamedAttributeMatcher.java b/tika-core/src/main/java/org/apache/tika/sax/xpath/NamedAttributeMatcher.java
index ab0b611..46b65a4 100644
--- a/tika-core/src/main/java/org/apache/tika/sax/xpath/NamedAttributeMatcher.java
+++ b/tika-core/src/main/java/org/apache/tika/sax/xpath/NamedAttributeMatcher.java
@@ -16,6 +16,8 @@
*/
package org.apache.tika.sax.xpath;
+import java.util.Objects;
+
/**
* Final evaluation state of a <code>.../@name</code> XPath expression.
* Matches the named attributes of the current element.
@@ -32,11 +34,6 @@ public class NamedAttributeMatcher extends Matcher {
}
public boolean matchesAttribute(String namespace, String name) {
- return equals(namespace, this.namespace) && name.equals(this.name);
- }
-
- private static boolean equals(String a, String b) {
- return (a == null) ? (b == null) : a.equals(b);
+ return Objects.equals(namespace, this.namespace) && name.equals(this.name);
}
-
}
diff --git a/tika-core/src/main/java/org/apache/tika/sax/xpath/NamedElementMatcher.java b/tika-core/src/main/java/org/apache/tika/sax/xpath/NamedElementMatcher.java
index d46643d..e304789 100644
--- a/tika-core/src/main/java/org/apache/tika/sax/xpath/NamedElementMatcher.java
+++ b/tika-core/src/main/java/org/apache/tika/sax/xpath/NamedElementMatcher.java
@@ -16,6 +16,8 @@
*/
package org.apache.tika.sax.xpath;
+import java.util.Objects;
+
/**
* Intermediate evaluation state of a <code>.../name...</code> XPath
* expression. Matches nothing, but specifies the evaluation state
@@ -34,15 +36,10 @@ public class NamedElementMatcher extends ChildMatcher {
}
public Matcher descend(String namespace, String name) {
- if (equals(namespace, this.namespace) && name.equals(this.name)) {
+ if (Objects.equals(namespace, this.namespace) && name.equals(this.name)) {
return super.descend(namespace, name);
} else {
return FAIL;
}
}
-
- private static boolean equals(String a, String b) {
- return (a == null) ? (b == null) : a.equals(b);
- }
-
}
diff --git a/tika-eval/src/main/java/org/apache/tika/eval/EvalFilePaths.java b/tika-eval/src/main/java/org/apache/tika/eval/EvalFilePaths.java
index 1a3d29c..a760b86 100644
--- a/tika-eval/src/main/java/org/apache/tika/eval/EvalFilePaths.java
+++ b/tika-eval/src/main/java/org/apache/tika/eval/EvalFilePaths.java
@@ -22,6 +22,7 @@ import static org.apache.tika.eval.AbstractProfiler.NON_EXISTENT_FILE_LENGTH;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.Objects;
/**
* Simple struct to keep track of relative path of source file (
@@ -74,16 +75,25 @@ class EvalFilePaths {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
EvalFilePaths that = (EvalFilePaths) o;
- if (sourceFileLength != that.sourceFileLength) return false;
- if (extractFileLength != that.extractFileLength) return false;
- if (relativeSourceFilePath != null ? !relativeSourceFilePath.equals(that.relativeSourceFilePath) : that.relativeSourceFilePath != null)
+ if (sourceFileLength != that.sourceFileLength) {
+ return false;
+ }
+ if (extractFileLength != that.extractFileLength) {
+ return false;
+ }
+ if (!Objects.equals(relativeSourceFilePath, that.relativeSourceFilePath)) {
return false;
- return extractFile != null ? extractFile.equals(that.extractFile) : that.extractFile == null;
+ }
+ return Objects.equals(extractFile, that.extractFile);
}
diff --git a/tika-eval/src/main/java/org/apache/tika/eval/db/ColInfo.java b/tika-eval/src/main/java/org/apache/tika/eval/db/ColInfo.java
index a32f874..369cb0a 100644
--- a/tika-eval/src/main/java/org/apache/tika/eval/db/ColInfo.java
+++ b/tika-eval/src/main/java/org/apache/tika/eval/db/ColInfo.java
@@ -18,6 +18,7 @@ package org.apache.tika.eval.db;
import java.sql.Types;
+import java.util.Objects;
public class ColInfo {
private final Cols name;
@@ -93,15 +94,25 @@ public class ColInfo {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
ColInfo colInfo = (ColInfo) o;
- if (type != colInfo.type) return false;
- if (name != colInfo.name) return false;
- if (precision != null ? !precision.equals(colInfo.precision) : colInfo.precision != null) return false;
- return !(constraints != null ? !constraints.equals(colInfo.constraints) : colInfo.constraints != null);
+ if (type != colInfo.type) {
+ return false;
+ }
+ if (name != colInfo.name) {
+ return false;
+ }
+ if (!Objects.equals(precision, colInfo.precision)) {
+ return false;
+ }
+ return Objects.equals(constraints, colInfo.constraints);
}
diff --git a/tika-eval/src/main/java/org/apache/tika/eval/tools/TopCommonTokenCounter.java b/tika-eval/src/main/java/org/apache/tika/eval/tools/TopCommonTokenCounter.java
index 539980e..b63546b 100644
--- a/tika-eval/src/main/java/org/apache/tika/eval/tools/TopCommonTokenCounter.java
+++ b/tika-eval/src/main/java/org/apache/tika/eval/tools/TopCommonTokenCounter.java
@@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
@@ -333,14 +334,22 @@ public class TopCommonTokenCounter {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
TokenDFTF tokenDFTF = (TokenDFTF) o;
- if (df != tokenDFTF.df) return false;
- if (tf != tokenDFTF.tf) return false;
- return token != null ? token.equals(tokenDFTF.token) : tokenDFTF.token == null;
+ if (df != tokenDFTF.df) {
+ return false;
+ }
+ if (tf != tokenDFTF.tf) {
+ return false;
+ }
+ return Objects.equals(token, tokenDFTF.token);
}
@Override
diff --git a/tika-parser-modules/tika-parser-pdf-module/src/main/java/org/apache/tika/parser/pdf/PDFMarkedContent2XHTML.java b/tika-parser-modules/tika-parser-pdf-module/src/main/java/org/apache/tika/parser/pdf/PDFMarkedContent2XHTML.java
index cc14ae5..c99ce53 100644
--- a/tika-parser-modules/tika-parser-pdf-module/src/main/java/org/apache/tika/parser/pdf/PDFMarkedContent2XHTML.java
+++ b/tika-parser-modules/tika-parser-pdf-module/src/main/java/org/apache/tika/parser/pdf/PDFMarkedContent2XHTML.java
@@ -495,13 +495,19 @@ public class PDFMarkedContent2XHTML extends PDF2XHTML {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
HtmlTag htmlTag = (HtmlTag) o;
- if (tag != null ? !tag.equals(htmlTag.tag) : htmlTag.tag != null) return false;
- return clazz != null ? clazz.equals(htmlTag.clazz) : htmlTag.clazz == null;
+ if (!Objects.equals(tag, htmlTag.tag)) {
+ return false;
+ }
+ return Objects.equals(clazz, htmlTag.clazz);
}
@Override