/** * Returns an array of {@link StyleRange} resulting from applying all * associated stylers for this string builder. * * @return an array of all {@link StyleRange} resulting from applying the * stored stylers to this string. */ public StyleRange[] getStyleRanges() { if (hasRuns()) { ArrayList<StyleRange> res = new ArrayList<>(); List<StyleRun> styleRuns = getStyleRuns(); int offset = 0; Styler style = null; for (int i = 0; i < styleRuns.size(); i++) { StyleRun curr = styleRuns.get(i); if (isDifferentStyle(curr.style, style)) { if (curr.offset > offset && style != null) { res.add(createStyleRange(offset, curr.offset, style)); } offset = curr.offset; style = curr.style; } } if (fBuffer.length() > offset && style != null) { res.add(createStyleRange(offset, fBuffer.length(), style)); } return res.toArray(new StyleRange[res.size()]); } return EMPTY; }
/** * Returns an array of {@link StyleRange} resulting from applying all * associated stylers for this string builder. * * @return an array of all {@link StyleRange} resulting from applying the * stored stylers to this string. */ public StyleRange[] getStyleRanges() { if (hasRuns()) { ArrayList res = new ArrayList(); List styleRuns = getStyleRuns(); int offset = 0; Styler style = null; for (int i = 0; i < styleRuns.size(); i++) { StyleRun curr = (StyleRun) styleRuns.get(i); if (isDifferentStyle(curr.style, style)) { if (curr.offset > offset && style != null) { res.add(createStyleRange(offset, curr.offset, style)); } offset = curr.offset; style = curr.style; } } if (fBuffer.length() > offset && style != null) { res.add(createStyleRange(offset, fBuffer.length(), style)); } return (StyleRange[]) res.toArray(new StyleRange[res.size()]); } return EMPTY; }