Class SpanSet<E>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess, SequencedCollection<E>

@Experimental public class SpanSet<E> extends ArrayList<E>
A cached set of spans. Caches the result of Spanned.getSpans(int, int, Class, java.util.List) and then provides faster access to Spanned.nextSpanTransition(int, int, Class). Also retrieves spanStart, spanEnd, spanFlags simultaneously with constant complexity.
  • Fields are public for a convenient direct access (read only).
  • Empty spans are ignored by default.
  • Cannot be used as normal ArrayList (you can only consume this object after init).
See Also:
  • Field Details

    • spanStarts

      public int[] spanStarts
    • spanEnds

      public int[] spanEnds
    • spanFlags

      public int[] spanFlags
  • Constructor Details

    • SpanSet

      public SpanSet(@NonNull Class<? extends E> type)
    • SpanSet

      public SpanSet(@NonNull Class<? extends E> type, boolean ignoreEmptySpans)
  • Method Details

    • init

      public boolean init(@NonNull Spanned spanned, int start, int limit)
      Returns:
      true if non-empty
    • getSpanStart

      public int getSpanStart(int index)
    • getSpanEnd

      public int getSpanEnd(int index)
    • getSpanFlags

      public int getSpanFlags(int index)
    • hasSpansIntersecting

      public boolean hasSpansIntersecting(int start, int end)
      Returns true if there are spans intersecting the given interval.
      Parameters:
      end - must be strictly greater than start
    • getNextTransition

      public int getNextTransition(int start, int limit)
    • recycle

      public void recycle()
      Removes all internal references to the spans to avoid memory leaks.