Class BasedSequenceImpl

java.lang.Object
com.vladsch.flexmark.util.sequence.IRichSequenceBase<BasedSequence>
com.vladsch.flexmark.util.sequence.BasedSequenceImpl
All Implemented Interfaces:
BasedOptionsHolder, BasedSequence, IRichSequence<BasedSequence>, SequenceUtils, CharSequence, Comparable<CharSequence>
Direct Known Subclasses:
BasedSequence.EmptyBasedSequence, CharSubSequence, MappedBasedSequence, PrefixedSubSequence, SegmentedSequence, SubSequence

public abstract class BasedSequenceImpl extends IRichSequenceBase<BasedSequence> implements BasedSequence
Implementation of BaseSequence
  • Constructor Details

    • BasedSequenceImpl

      public BasedSequenceImpl(int hash)
  • Method Details

    • firstNonNull

      public static BasedSequence firstNonNull(BasedSequence... sequences)
    • emptyArray

      @NotNull public @NotNull BasedSequence[] emptyArray()
      Specified by:
      emptyArray in interface IRichSequence<BasedSequence>
    • nullSequence

      @NotNull public @NotNull BasedSequence nullSequence()
      Specified by:
      nullSequence in interface IRichSequence<BasedSequence>
    • sequenceOf

      @NotNull public @NotNull BasedSequence sequenceOf(@Nullable @Nullable CharSequence charSequence, int startIndex, int endIndex)
      Description copied from interface: IRichSequence
      Factory function
      Specified by:
      sequenceOf in interface IRichSequence<BasedSequence>
      Parameters:
      charSequence - char sequence from which to construct a rich char sequence
      startIndex - start index of the sequence to use
      endIndex - end index of the sequence to use
      Returns:
      rich char sequence from given inputs
    • getBuilder

      @NotNull public @NotNull SequenceBuilder getBuilder()
      Description copied from interface: IRichSequence
      Get a sequence builder for this sequence type
      Specified by:
      getBuilder in interface BasedSequence
      Specified by:
      getBuilder in interface IRichSequence<BasedSequence>
      Returns:
      builder which can build this type of sequence
    • addSegments

      public void addSegments(@NotNull @NotNull IBasedSegmentBuilder<?> builder)
      Description copied from interface: BasedSequence
      Add segments for this sequence, replacing out of base characters with strings
      Specified by:
      addSegments in interface BasedSequence
      Parameters:
      builder - builder
    • getSegmentTree

      @NotNull public @NotNull SegmentTree getSegmentTree()
      Get the segment tree for this sequence or null if sequence is contiguous from startOffset to endOffset
      Specified by:
      getSegmentTree in interface BasedSequence
      Returns:
      null for contiguous sequences, else segment tree for this sequence
    • toMapped

      @NotNull public @NotNull BasedSequence toMapped(CharMapper mapper)
      Specified by:
      toMapped in interface IRichSequence<BasedSequence>
    • baseSubSequence

      @NotNull public final @NotNull BasedSequence baseSubSequence(int startIndex)
      Description copied from interface: BasedSequence
      Get a portion of the original sequence that this sequence is based on
      Specified by:
      baseSubSequence in interface BasedSequence
      Parameters:
      startIndex - offset from 0 of original sequence
      Returns:
      based sequence from startIndex to the endIndex
    • baseSubSequence

      @NotNull public @NotNull BasedSequence baseSubSequence(int startIndex, int endIndex)
      Description copied from interface: BasedSequence
      Get a portion of this sequence's base sequence

      NOTE: this means that if this sequence applies modifications to the original sequence then these modifications are NOT be applied to the returned sequence.

      NOTE: It should only be implemented in classes which provide base sequences such as CharSubSequence and SubSequence others use inherited implementation of BasedSequenceImpl

      Specified by:
      baseSubSequence in interface BasedSequence
      Parameters:
      startIndex - offset from 0 of original sequence
      endIndex - offset from 0 of original sequence
      Returns:
      based sequence whose contents reflect the selected portion
    • safeCharAt

      public char safeCharAt(int index)
      Description copied from interface: IRichSequence
      return char at index or '\0' if index <0 or >=length()
      Specified by:
      safeCharAt in interface IRichSequence<BasedSequence>
      Overrides:
      safeCharAt in class IRichSequenceBase<BasedSequence>
      Parameters:
      index - index
      Returns:
      char or '\0'
    • safeBaseCharAt

      public char safeBaseCharAt(int index)
      Description copied from interface: BasedSequence
      Safe, if index out of range but based sequence has characters will return those, else returns '\0'

      Allows peeking into preceding/following characters to the ones contained in this sequence

      Specified by:
      safeBaseCharAt in interface BasedSequence
      Parameters:
      index - index in string
      Returns:
      character or '\0' if index out of base sequence
    • isBaseCharAt

      public boolean isBaseCharAt(int index, @NotNull @NotNull CharPredicate predicate)
      Description copied from interface: BasedSequence
      Safe, if index out of range but based sequence has characters will return those, else returns '\0'

      Allows peeking into preceding/following characters to the ones contained in this sequence

      Specified by:
      isBaseCharAt in interface BasedSequence
      Parameters:
      index - index in string
      predicate - character set predicate
      Returns:
      true if character at index tests true
    • getEmptyPrefix

      @NotNull public @NotNull BasedSequence getEmptyPrefix()
      Description copied from interface: BasedSequence
      Get empty prefix to this sequence
      Specified by:
      getEmptyPrefix in interface BasedSequence
      Returns:
      same as subSequence(0,0)
    • getEmptySuffix

      @NotNull public @NotNull BasedSequence getEmptySuffix()
      Description copied from interface: BasedSequence
      Get empty suffix to this sequence
      Specified by:
      getEmptySuffix in interface BasedSequence
      Returns:
      same as subSequence(length())
    • toStringOrNull

      @Nullable public @Nullable String toStringOrNull()
      Description copied from interface: IRichSequence
      Return string or null if BaseSequence.NULL
      Specified by:
      toStringOrNull in interface IRichSequence<BasedSequence>
      Overrides:
      toStringOrNull in class IRichSequenceBase<BasedSequence>
      Returns:
      string or null if BaseSequence.NULL
    • unescape

      @NotNull public @NotNull String unescape()
      Description copied from interface: BasedSequence
      Get the unescaped string of this sequence content
      Specified by:
      unescape in interface BasedSequence
      Returns:
      unescaped text
    • unescapeNoEntities

      @NotNull public @NotNull String unescapeNoEntities()
      Description copied from interface: BasedSequence
      Get the unescaped string of this sequence content without unescaping entities
      Specified by:
      unescapeNoEntities in interface BasedSequence
      Returns:
      unescaped text
    • unescape

      @NotNull public @NotNull BasedSequence unescape(@NotNull @NotNull ReplacedTextMapper textMapper)
      Description copied from interface: BasedSequence
      Get the unescaped string of this sequence content
      Specified by:
      unescape in interface BasedSequence
      Parameters:
      textMapper - replaced text mapper which will be uses to map unescaped index to original source index
      Returns:
      unescaped text in based sequence
    • normalizeEOL

      @NotNull public @NotNull BasedSequence normalizeEOL(@NotNull @NotNull ReplacedTextMapper textMapper)
      Description copied from interface: BasedSequence
      replace any \r\n and \r by \n
      Specified by:
      normalizeEOL in interface BasedSequence
      Parameters:
      textMapper - replaced text mapper which will be uses to map unescaped index to original source index
      Returns:
      based sequence with only \n for line separators
    • normalizeEndWithEOL

      @NotNull public @NotNull BasedSequence normalizeEndWithEOL(@NotNull @NotNull ReplacedTextMapper textMapper)
      Description copied from interface: BasedSequence
      replace any \r\n and \r by \n, append terminating EOL if one is not present
      Specified by:
      normalizeEndWithEOL in interface BasedSequence
      Parameters:
      textMapper - replaced text mapper which will be uses to map unescaped index to original source index
      Returns:
      based sequence with only \n for line separators and terminated by \n
    • isContinuedBy

      public boolean isContinuedBy(@NotNull @NotNull BasedSequence other)
      Description copied from interface: BasedSequence
      Test if the given sequence is a continuation of this sequence in original source text
      Specified by:
      isContinuedBy in interface BasedSequence
      Parameters:
      other - sequence to test
      Returns:
      true if the given sequence is a continuation of this one in the original text
    • isContinuationOf

      public boolean isContinuationOf(@NotNull @NotNull BasedSequence other)
      Description copied from interface: BasedSequence
      Test if this sequence is a continuation of the given sequence in original source text
      Specified by:
      isContinuationOf in interface BasedSequence
      Parameters:
      other - sequence to test
      Returns:
      true if this sequence is a continuation of the given sequence in original source text
    • spliceAtEnd

      @NotNull public @NotNull BasedSequence spliceAtEnd(@NotNull @NotNull BasedSequence other)
      Description copied from interface: BasedSequence
      Splice the given sequence to the end of this one and return a BasedSequence of the result. Does not copy anything, creates a new based sequence of the original text but one that spans characters of this sequence and other
      Specified by:
      spliceAtEnd in interface BasedSequence
      Parameters:
      other - sequence to append to end of this one
      Returns:
      based sequence that contains the span from start of this sequence and end of other

      assertion will fail if the other sequence is not a continuation of this one

    • containsAllOf

      public boolean containsAllOf(@NotNull @NotNull BasedSequence other)
      Description copied from interface: BasedSequence
      start/end offset based containment, not textual
      Specified by:
      containsAllOf in interface BasedSequence
      Parameters:
      other - based sequence from the same base
      Returns:
      true if other is contained in this
    • containsSomeOf

      public boolean containsSomeOf(@NotNull @NotNull BasedSequence other)
      Description copied from interface: BasedSequence
      start/end offset based containment, not textual
      Specified by:
      containsSomeOf in interface BasedSequence
      Parameters:
      other - based sequence from the same base
      Returns:
      true if other is contained in this
    • intersect

      @NotNull public @NotNull BasedSequence intersect(@NotNull @NotNull BasedSequence other)
      Description copied from interface: BasedSequence
      start/end offset based intersection, not textual
      Specified by:
      intersect in interface BasedSequence
      Parameters:
      other - based sequence from the same parent
      Returns:
      sequence which is the intersection of the range of this and other
    • containsSomeIn

      public boolean containsSomeIn(@NotNull @NotNull CharPredicate charSet)
      Description copied from interface: BasedSequence
      Test for line containing some of the characters in the set
      Specified by:
      containsSomeIn in interface BasedSequence
      Parameters:
      charSet - set of characters to be tested
      Returns:
      true if line contains some characters in the set
    • containsSomeNotIn

      public boolean containsSomeNotIn(@NotNull @NotNull CharPredicate charSet)
      Description copied from interface: BasedSequence
      Test for line containing some characters not in the set
      Specified by:
      containsSomeNotIn in interface BasedSequence
      Parameters:
      charSet - set of characters to be tested
      Returns:
      true if line contains some characters not in the set
    • containsOnlyIn

      public boolean containsOnlyIn(@NotNull @NotNull CharPredicate charSet)
      Description copied from interface: BasedSequence
      Test for line contains only characters from the set
      Specified by:
      containsOnlyIn in interface BasedSequence
      Parameters:
      charSet - set of characters to be tested
      Returns:
      true if line contains some characters from the set
    • containsOnlyNotIn

      public boolean containsOnlyNotIn(@NotNull @NotNull CharPredicate charSet)
      Description copied from interface: BasedSequence
      Test for line containing only characters not in the set
      Specified by:
      containsOnlyNotIn in interface BasedSequence
      Parameters:
      charSet - set of characters to be tested
      Returns:
      true if line contains some characters from the set
    • extendByAny

      @NotNull public @NotNull BasedSequence extendByAny(@NotNull @NotNull CharPredicate charSet)
      Specified by:
      extendByAny in interface BasedSequence
    • extendByOneOfAny

      @NotNull public @NotNull BasedSequence extendByOneOfAny(@NotNull @NotNull CharPredicate charSet)
      Specified by:
      extendByOneOfAny in interface BasedSequence
    • extendByAny

      @NotNull public @NotNull BasedSequence extendByAny(@NotNull @NotNull CharPredicate charSet, int maxCount)
      Description copied from interface: BasedSequence
      Extend this based sequence to include characters from underlying based sequence
      Specified by:
      extendByAny in interface BasedSequence
      Parameters:
      charSet - set of characters to include
      maxCount - maximum extra characters to include
      Returns:
      sequence which
    • extendByAnyNot

      @NotNull public @NotNull BasedSequence extendByAnyNot(@NotNull @NotNull CharPredicate charSet)
      Specified by:
      extendByAnyNot in interface BasedSequence
    • extendByOneOfAnyNot

      @NotNull public @NotNull BasedSequence extendByOneOfAnyNot(@NotNull @NotNull CharPredicate charSet)
      Specified by:
      extendByOneOfAnyNot in interface BasedSequence
    • extendByAnyNot

      @NotNull public @NotNull BasedSequence extendByAnyNot(@NotNull @NotNull CharPredicate charSet, int maxCount)
      Description copied from interface: BasedSequence
      Extend this based sequence to include characters from underlying based sequence not in character set
      Specified by:
      extendByAnyNot in interface BasedSequence
      Parameters:
      charSet - set of characters to include
      maxCount - maximum extra characters to include
      Returns:
      sequence which
    • extendToEndOfLine

      @NotNull public final @NotNull BasedSequence extendToEndOfLine(@NotNull @NotNull CharPredicate eolChars)
      Specified by:
      extendToEndOfLine in interface BasedSequence
    • extendToEndOfLine

      @NotNull public final @NotNull BasedSequence extendToEndOfLine(boolean includeEol)
      Specified by:
      extendToEndOfLine in interface BasedSequence
    • extendToEndOfLine

      @NotNull public final @NotNull BasedSequence extendToEndOfLine()
      Specified by:
      extendToEndOfLine in interface BasedSequence
    • extendToStartOfLine

      @NotNull public final @NotNull BasedSequence extendToStartOfLine(@NotNull @NotNull CharPredicate eolChars)
      Specified by:
      extendToStartOfLine in interface BasedSequence
    • extendToStartOfLine

      @NotNull public final @NotNull BasedSequence extendToStartOfLine(boolean includeEol)
      Specified by:
      extendToStartOfLine in interface BasedSequence
    • extendToStartOfLine

      @NotNull public final @NotNull BasedSequence extendToStartOfLine()
      Specified by:
      extendToStartOfLine in interface BasedSequence
    • extendToEndOfLine

      @NotNull public final @NotNull BasedSequence extendToEndOfLine(@NotNull @NotNull CharPredicate eolChars, boolean includeEol)
      Description copied from interface: BasedSequence
      Extend in contained based sequence
      Specified by:
      extendToEndOfLine in interface BasedSequence
      Parameters:
      eolChars - characters to consider as EOL, note IRichSequence.eolStartLength(int) IRichSequence.eolEndLength(int) should report length of EOL found if length > 1
      includeEol - if to include the eol in the string
      Returns:
      resulting sequence after extension. If already spanning the line then this sequence is returned. if the last character of this sequence are found in eolChars then no extension will be performed since it already includes the line end
    • extendToStartOfLine

      @NotNull public @NotNull BasedSequence extendToStartOfLine(@NotNull @NotNull CharPredicate eolChars, boolean includeEol)
      Description copied from interface: BasedSequence
      Extend in contained based sequence
      Specified by:
      extendToStartOfLine in interface BasedSequence
      Parameters:
      eolChars - characters to consider as EOL, note IRichSequence.eolStartLength(int) IRichSequence.eolEndLength(int) should report length of EOL found if length > 1
      includeEol - if to include the eol in the string
      Returns:
      resulting sequence after extension. If already spanning the line then this sequence is returned. if the first character of this sequence are found in eolChars then no extension will be performed since it already includes the line end
    • prefixWith

      @NotNull public @NotNull BasedSequence prefixWith(@Nullable @Nullable CharSequence prefix)
      Description copied from interface: IRichSequence
      Prefix this sequence with a char sequence
      Specified by:
      prefixWith in interface IRichSequence<BasedSequence>
      Overrides:
      prefixWith in class IRichSequenceBase<BasedSequence>
      Parameters:
      prefix - char sequence
      Returns:
      resulting sequence
    • prefixWithIndent

      @NotNull public final @NotNull BasedSequence prefixWithIndent()
      Specified by:
      prefixWithIndent in interface BasedSequence
    • prefixWithIndent

      @NotNull public @NotNull BasedSequence prefixWithIndent(int maxColumns)
      Description copied from interface: BasedSequence
      Extend this based sequence to include characters from underlying based sequence taking tab expansion to 4th spaces into account
      Specified by:
      prefixWithIndent in interface BasedSequence
      Parameters:
      maxColumns - maximum columns to include, default Integer.MAX_VALUE
      Returns:
      sequence which
    • prefixOf

      @NotNull public @NotNull BasedSequence prefixOf(@NotNull @NotNull BasedSequence other)
      Description copied from interface: BasedSequence
      Get the prefix part of this from other, start/end offset based containment, not textual
      Specified by:
      prefixOf in interface BasedSequence
      Parameters:
      other - based sequence from the same base
      Returns:
      prefix part of this as compared to other, start/end offset based, not content
    • suffixOf

      @NotNull public @NotNull BasedSequence suffixOf(@NotNull @NotNull BasedSequence other)
      Description copied from interface: BasedSequence
      Get the suffix part of this from other, start/end offset based containment, not textual
      Specified by:
      suffixOf in interface BasedSequence
      Parameters:
      other - based sequence from the same base
      Returns:
      suffix part of this as compared to other, start/end offset based, not content
    • baseLineRangeAtIndex

      @NotNull public @NotNull Range baseLineRangeAtIndex(int index)
      Specified by:
      baseLineRangeAtIndex in interface BasedSequence
    • baseLineColumnAtIndex

      @NotNull public @NotNull Pair<Integer,Integer> baseLineColumnAtIndex(int index)
      Specified by:
      baseLineColumnAtIndex in interface BasedSequence
    • baseEndOfLine

      public int baseEndOfLine(int index)
      Specified by:
      baseEndOfLine in interface BasedSequence
    • baseEndOfLineAnyEOL

      public int baseEndOfLineAnyEOL(int index)
      Specified by:
      baseEndOfLineAnyEOL in interface BasedSequence
    • baseStartOfLine

      public int baseStartOfLine(int index)
      Specified by:
      baseStartOfLine in interface BasedSequence
    • baseStartOfLineAnyEOL

      public int baseStartOfLineAnyEOL(int index)
      Specified by:
      baseStartOfLineAnyEOL in interface BasedSequence
    • baseColumnAtIndex

      public int baseColumnAtIndex(int index)
      Specified by:
      baseColumnAtIndex in interface BasedSequence
    • baseEndOfLine

      public int baseEndOfLine()
      Specified by:
      baseEndOfLine in interface BasedSequence
    • baseEndOfLineAnyEOL

      public int baseEndOfLineAnyEOL()
      Specified by:
      baseEndOfLineAnyEOL in interface BasedSequence
    • baseColumnAtEnd

      public int baseColumnAtEnd()
      Specified by:
      baseColumnAtEnd in interface BasedSequence
    • baseLineRangeAtEnd

      @NotNull public @NotNull Range baseLineRangeAtEnd()
      Specified by:
      baseLineRangeAtEnd in interface BasedSequence
    • baseLineColumnAtEnd

      @NotNull public @NotNull Pair<Integer,Integer> baseLineColumnAtEnd()
      Specified by:
      baseLineColumnAtEnd in interface BasedSequence
    • baseStartOfLine

      public int baseStartOfLine()
      Specified by:
      baseStartOfLine in interface BasedSequence
    • baseStartOfLineAnyEOL

      public int baseStartOfLineAnyEOL()
      Specified by:
      baseStartOfLineAnyEOL in interface BasedSequence
    • baseColumnAtStart

      public int baseColumnAtStart()
      Specified by:
      baseColumnAtStart in interface BasedSequence
    • baseLineRangeAtStart

      @NotNull public @NotNull Range baseLineRangeAtStart()
      Specified by:
      baseLineRangeAtStart in interface BasedSequence
    • baseLineColumnAtStart

      @NotNull public @NotNull Pair<Integer,Integer> baseLineColumnAtStart()
      Specified by:
      baseLineColumnAtStart in interface BasedSequence
    • create

      static BasedSequence create(@Nullable @Nullable CharSequence charSequence)