This is an automated email from the ASF dual-hosted git repository. mawiesne pushed a commit to branch OPENNLP-1671-Convert-while-loops-with-duplicated-code-to-do-while-loops in repository https://gitbox.apache.org/repos/asf/opennlp.git
commit 7ff0dc5250caef4fb2dc5116007f95c1c47c8143 Author: Martin Wiesner <[email protected]> AuthorDate: Thu Dec 19 19:37:44 2024 +0100 OPENNLP-1671 Convert while loops with duplicated code to do-while loops --- .../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.
