Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPENNLP-1597 Use isEmpty instead of equals comparison against empty string #639

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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