Skip to content

Commit fb3b3f7

Browse files
authored
OPENNLP-1671: Convert while loops with duplicated code to do-while loops (#712)
1 parent 9ba57ce commit fb3b3f7

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,9 @@ public Sentence parse(String sentenceString, int para, boolean isTitle, boolean
156156
sentence.setText(text);
157157
sentence.setMetadata(meta);
158158
// now we look for the root node
159-
160-
// skip lines starting with ###
161-
line = reader.readLine();
162-
while (line != null && line.startsWith("###")) {
159+
do {
163160
line = reader.readLine();
164-
}
161+
} while (line != null && line.startsWith("###")); // skip lines starting with ###
165162

166163
// got the root. Add it to the stack
167164
Stack<Node> nodeStack = new Stack<>();

opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static String escapeChar(Character c) {
8383
return "<CR>";
8484
}
8585

86-
return new String(new char[]{c});
86+
return String.valueOf(c);
8787
}
8888

8989
@Override
@@ -232,15 +232,15 @@ private static boolean isFirstUpper(String s) {
232232
/**
233233
* Finds the index of the nearest space before a specified index which is not itself preceded by a space.
234234
*
235-
* @param sb The string buffer which contains the text being examined.
235+
* @param sb The {@link CharSequence} which contains the text being examined.
236236
* @param seek The index to begin searching from.
237237
* @return The index which contains the nearest space.
238238
*/
239239
private static int previousSpaceIndex(CharSequence sb, int seek) {
240-
seek--;
241-
while (seek > 0 && !StringUtil.isWhitespace(sb.charAt(seek))) {
240+
do {
242241
seek--;
243-
}
242+
} while (seek > 0 && !StringUtil.isWhitespace(sb.charAt(seek)));
243+
244244
if (seek > 0 && StringUtil.isWhitespace(sb.charAt(seek))) {
245245
while (seek > 0 && StringUtil.isWhitespace(sb.charAt(seek - 1)))
246246
seek--;
@@ -252,7 +252,7 @@ private static int previousSpaceIndex(CharSequence sb, int seek) {
252252
/**
253253
* Finds the index of the nearest space after a specified index.
254254
*
255-
* @param sb The string buffer which contains the text being examined.
255+
* @param sb The {@link CharSequence} which contains the text being examined.
256256
* @param seek The index to begin searching from.
257257
* @param lastIndex The highest index of the StringBuffer sb.
258258
* @return The index which contains the nearest space.

0 commit comments

Comments
 (0)