This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp.git
The following commit(s) were added to refs/heads/main by this push:
new fb3b3f7d OPENNLP-1671: Convert while loops with duplicated code to
do-while loops (#712)
fb3b3f7d is described below
commit fb3b3f7d8ca7f5de860f552c3a01a614e3cd274e
Author: Martin Wiesner <[email protected]>
AuthorDate: Fri Dec 20 07:35:32 2024 +0100
OPENNLP-1671: Convert while loops with duplicated code to do-while loops
(#712)
---
.../main/java/opennlp/tools/formats/ad/ADSentenceStream.java | 7 ++-----
.../opennlp/tools/sentdetect/DefaultSDContextGenerator.java | 12 ++++++------
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git
a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java
b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java
index 36cfd4e0..27e91749 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java
@@ -156,12 +156,9 @@ public class ADSentenceStream extends
FilterObjectStream<String, ADSentenceStrea
sentence.setText(text);
sentence.setMetadata(meta);
// now we look for the root node
-
- // skip lines starting with ###
- line = reader.readLine();
- while (line != null && line.startsWith("###")) {
+ do {
line = reader.readLine();
- }
+ } while (line != null && line.startsWith("###")); // skip lines
starting with ###
// got the root. Add it to the stack
Stack<Node> nodeStack = new Stack<>();
diff --git
a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
index f4f17d77..6cd80d9a 100644
---
a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
+++
b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
@@ -83,7 +83,7 @@ public class DefaultSDContextGenerator implements
SDContextGenerator {
return "<CR>";
}
- return new String(new char[]{c});
+ return String.valueOf(c);
}
@Override
@@ -232,15 +232,15 @@ public class DefaultSDContextGenerator implements
SDContextGenerator {
/**
* Finds the index of the nearest space before a specified index which is
not itself preceded by a space.
*
- * @param sb The string buffer which contains the text being examined.
+ * @param sb The {@link CharSequence} which contains the text being
examined.
* @param seek The index to begin searching from.
* @return The index which contains the nearest space.
*/
private static int previousSpaceIndex(CharSequence sb, int seek) {
- seek--;
- while (seek > 0 && !StringUtil.isWhitespace(sb.charAt(seek))) {
+ do {
seek--;
- }
+ } while (seek > 0 && !StringUtil.isWhitespace(sb.charAt(seek)));
+
if (seek > 0 && StringUtil.isWhitespace(sb.charAt(seek))) {
while (seek > 0 && StringUtil.isWhitespace(sb.charAt(seek - 1)))
seek--;
@@ -252,7 +252,7 @@ public class DefaultSDContextGenerator implements
SDContextGenerator {
/**
* Finds the index of the nearest space after a specified index.
*
- * @param sb The string buffer which contains the text being examined.
+ * @param sb The {@link CharSequence} which contains the text being examined.
* @param seek The index to begin searching from.
* @param lastIndex The highest index of the StringBuffer sb.
* @return The index which contains the nearest space.