Skip to content

Commit

Permalink
OPENNLP-1597 Use isEmpty instead of equals comparison against empty s…
Browse files Browse the repository at this point in the history
…tring
  • Loading branch information
mawiesne authored and rzo1 committed Jul 16, 2024
1 parent 689e7ac commit 1d64c7c
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static void usage() {
final StringBuilder sb = new StringBuilder("where TOOL is one of: \n\n");
for (CmdLineTool tool : toolLookupMap.values()) {

sb.append(" " + tool.getName());
sb.append(" ").append(tool.getName());
sb.append(" ".repeat(Math.max(0, StrictMath.abs(
tool.getName().length() - numberOfSpaces))));
sb.append(tool.getShortDescription()).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ChunkSample read() throws IOException {
List<String> tags = new ArrayList<>();
List<String> preds = new ArrayList<>();

for (String line = samples.read(); line != null && !line.equals(""); line = samples.read()) {
for (String line = samples.read(); line != null && !line.isEmpty(); line = samples.read()) {
String[] parts = line.split(" ");
if (parts.length != 3) {
logger.error("Skipping corrupt line: {}", line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static synchronized EntityLinker<?> getLinker(String entityType, EntityLi

String linkerImplFullName = properties.getProperty("linker." + entityType, "");

if (linkerImplFullName == null || linkerImplFullName.equals("")) {
if (linkerImplFullName == null || linkerImplFullName.isEmpty()) {
throw new IllegalArgumentException("linker." + entityType + " property must be set!");
}

Expand All @@ -83,7 +83,7 @@ public static synchronized EntityLinker<?> getLinker(EntityLinkerProperties prop

String linkerImplFullName = properties.getProperty("linker", "");

if (linkerImplFullName == null || linkerImplFullName.equals("")) {
if (linkerImplFullName == null || linkerImplFullName.isEmpty()) {
throw new IllegalArgumentException("\"linker\" property must be set!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public LemmaSample read() throws IOException {
List<String> tags = new ArrayList<>();
List<String> preds = new ArrayList<>();

for (String line = samples.read(); line != null && !line.equals(""); line = samples.read()) {
for (String line = samples.read(); line != null && !line.isEmpty(); line = samples.read()) {
String[] parts = line.split("\t");
if (parts.length != 3) {
logger.warn("Skipping corrupt line: {}", line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected void collectFeatures(String prefix, String suffix, String previous,
buf.append(prefix);
collectFeats.add(buf.toString());
buf.setLength(0);
if (!prefix.equals("")) {
if (!prefix.isEmpty()) {
collectFeats.add(Integer.toString(prefix.length()));
if (isFirstUpper(prefix)) {
collectFeats.add("xcap");
Expand All @@ -189,7 +189,7 @@ protected void collectFeatures(String prefix, String suffix, String previous,
buf.append(previous);
collectFeats.add(buf.toString());
buf.setLength(0);
if (!previous.equals("")) {
if (!previous.isEmpty()) {
if (isFirstUpper(previous)) {
collectFeats.add("vcap");
}
Expand All @@ -202,7 +202,7 @@ protected void collectFeatures(String prefix, String suffix, String previous,
buf.append(suffix);
collectFeats.add(buf.toString());
buf.setLength(0);
if (!suffix.equals("")) {
if (!suffix.isEmpty()) {
if (isFirstUpper(suffix)) {
collectFeats.add("scap");
}
Expand All @@ -215,7 +215,7 @@ protected void collectFeatures(String prefix, String suffix, String previous,
buf.append(next);
collectFeats.add(buf.toString());
buf.setLength(0);
if (!next.equals("")) {
if (!next.isEmpty()) {
if (isFirstUpper(next)) {
collectFeats.add("ncap");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/


package opennlp.tools.sentdetect;

import java.io.IOException;
Expand Down Expand Up @@ -48,7 +47,7 @@ public SentenceSample read() throws IOException {
List<Span> sentenceSpans = new LinkedList<>();

String sentence;
while ((sentence = samples.read()) != null && !sentence.equals("")) {
while ((sentence = samples.read()) != null && !sentence.isEmpty()) {
int begin = sentencesString.length();
sentence = sentence.trim();
sentence = replaceNewLineEscapeTags(sentence);
Expand All @@ -58,9 +57,8 @@ public SentenceSample read() throws IOException {
sentencesString.append(' ');
}

if (sentenceSpans.size() > 0) {
return new SentenceSample(sentencesString.toString(),
sentenceSpans.toArray(new Span[0]));
if (!sentenceSpans.isEmpty()) {
return new SentenceSample(sentencesString.toString(), sentenceSpans.toArray(new Span[0]));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String read() throws IOException {
// The last paragraph in the input might not
// be terminated well with a new line at the end.

if (line == null || line.equals("")) {
if (line == null || line.isEmpty()) {
if (paragraph.length() > 0) {
return paragraph.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ChunkSample read() throws IOException {
List<String> chunkTags = new ArrayList<>();
List<String> predictedChunkTags = new ArrayList<>();

for (String line = samples.read(); line != null && !line.equals(""); line = samples
for (String line = samples.read(); line != null && !line.isEmpty(); line = samples
.read()) {
String[] parts = line.split(" ");
if (parts.length != 4) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public LemmaSample read() throws IOException {
List<String> predictedLemmas = new ArrayList<>();

for (String line = samples.read(); line != null
&& !line.equals(""); line = samples.read()) {
&& !line.isEmpty(); line = samples.read()) {
String[] parts = line.split("\t");
if (parts.length != 4) {
logger.warn("Skipping corrupt line {}: {}", count, line);
Expand Down

0 comments on commit 1d64c7c

Please sign in to comment.