jaragunde commented on code in PR #1561:
URL: https://github.com/apache/poi/pull/1561#discussion_r4552692352
##########
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java:
##########
@@ -1226,6 +1226,113 @@ public void addBreak(BreakClear clear) {
br.setClear(STBrClear.Enum.forInt(clear.getValue()));
}
+ /**
+ * Returns the number of breaks in the run content.
+ *
+ * @return number of break elements in this run
+ * @see #getBreak(int)
+ * @since 6.1.0
+ */
+ public int getNumberOfBreaks() {
+ return run.sizeOfBrArray();
+ }
+
+ /**
+ * Get the type of the break at the given position in the run content.
+ * <p>
+ * A run may contain any number of breaks, mixed with text, tabs and other
+ * run content. The position only counts break elements, in document
+ * order: it is not related to the positions used by text-related methods
+ * such as {@link #getText(int)}, so it does not tell where the break is
+ * placed relative to the text of the run.
+ * </p>
+ * <p>
+ * If the break does not specify a type, {@link BreakType#TEXT_WRAPPING}
+ * is returned, as that is the default value defined by the specification.
+ * </p>
+ *
+ * @param pos the 0-based position of the break among the breaks of this
+ * run, lower than {@link #getNumberOfBreaks()}
+ * @return the type of the break at the given position, or {@code null} if
+ * there is no break at that position
+ * @see #addBreak(BreakType)
+ * @since 6.1.0
+ */
+ public BreakType getBreak(int pos) {
+ if (pos < 0 || pos >= run.sizeOfBrArray()) {
+ return null;
+ }
+ return toBreakType(run.getBrArray(pos));
+ }
+
+ /**
+ * Get the types of all the breaks in the run content.
+ * <p>
+ * The types are returned in the same order as the breaks are stored in
+ * the run, so the element at position {@code i} is the same as
+ * {@link #getBreak(int) getBreak(i)}. As with {@link #getBreak(int)}, the
+ * list only contains breaks: it does not tell where each break is placed
+ * relative to the text of the run.
+ * </p>
+ * <p>
+ * Breaks that do not specify a type are returned as
+ * {@link BreakType#TEXT_WRAPPING}, as that is the default value defined
+ * by the specification.
+ * </p>
+ * <p>
+ * The returned list is unmodifiable, and it is not updated when breaks
+ * are later added to the run.
+ * </p>
+ *
+ * @return an unmodifiable list with the types of the breaks in this run,
+ * which is empty if the run contains no breaks
+ * @see #getBreak(int)
+ * @see #getNumberOfBreaks()
+ * @since 6.1.0
+ */
+ public List<BreakType> getBreaks() {
Review Comment:
I kind of like this convenience method (to allow for something like
`getBreaks().contains(PAGE_BREAK)`) but, on the other hand, I was also worried
to be adding too many methods for just one attribute. After your advice, I'm
removing it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]