Class SubSequence

All Implemented Interfaces:
BasedOptionsHolder, BasedSequence, IRichSequence<BasedSequence>, SequenceUtils, CharSequence, Comparable<CharSequence>

public final class SubSequence extends BasedSequenceImpl
A BasedSequence implementation which wraps original CharSequence to provide a BasedSequence for all its subsequences, a subSequence() returns a SubSequence from the original base sequence.

NOTE: '\0' changed to '�' use NullEncoder.decodeNull mapper to get original null chars.

  • Field Details

    • charSequence

      @NotNull private final @NotNull CharSequence charSequence
    • baseSeq

      @NotNull private final @NotNull SubSequence baseSeq
    • startOffset

      private final int startOffset
    • endOffset

      private final int endOffset
  • Constructor Details

    • SubSequence

      private SubSequence(@NotNull @NotNull CharSequence charSequence)
    • SubSequence

      private SubSequence(@NotNull @NotNull SubSequence subSequence, int startIndex, int endIndex)
  • Method Details

    • getBaseSequence

      @NotNull public @NotNull SubSequence getBaseSequence()
      Description copied from interface: BasedSequence
      Get the base sequence for the text
      Returns:
      base sequence
    • getOptionFlags

      public int getOptionFlags()
      Description copied from interface: BasedOptionsHolder
      Options test for options for this sequence

      default reports true for global default options (if any) , variation available on BasedSequenceWithOptions

      Returns:
      option flags for this sequence
    • allOptions

      public boolean allOptions(int options)
      Description copied from interface: BasedOptionsHolder
      Options test for options for this sequence

      default reports true for global default options (if any) , variation available on BasedSequenceWithOptions

      Parameters:
      options - option flags
      Returns:
      true if all option flags passed are set for this sequence
    • anyOptions

      public boolean anyOptions(int options)
      Description copied from interface: BasedOptionsHolder
      Options test for options for this sequence

      default reports true for global default options (if any) , variation available on BasedSequenceWithOptions

      Parameters:
      options - option flags
      Returns:
      true if any option flags passed are set for this sequence
    • getOption

      public <T> T getOption(@NotNull @NotNull DataKeyBase<T> dataKey)
      Description copied from interface: BasedOptionsHolder
      Options holder, default has none, only available on BasedSequenceWithOptions
      Type Parameters:
      T - type of value held by key
      Parameters:
      dataKey - in options
      Returns:
      true if data key is available
    • getOptions

      @Nullable public @Nullable DataHolder getOptions()
      Description copied from interface: BasedOptionsHolder
      Options holder, default has none, only available on BasedSequenceWithOptions
      Returns:
      data holder with options or null if none for this sequence
    • getBase

      @NotNull public @NotNull CharSequence getBase()
      Description copied from interface: BasedSequence
      Get the underlying object on which this sequence contents are based
      Returns:
      underlying object containing original text
    • getStartOffset

      public int getStartOffset()
      Description copied from interface: BasedSequence
      Get the start offset of this sequence into BasedSequence.getBaseSequence() and BasedSequence.getBase() original text source.
      Returns:
      start offset in original text
    • getEndOffset

      public int getEndOffset()
      Description copied from interface: BasedSequence
      Get the end offset of this sequence into BasedSequence.getBaseSequence() and BasedSequence.getBase() original text source.
      Returns:
      end offset in original text
    • 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
      Overrides:
      addSegments in class BasedSequenceImpl
      Parameters:
      builder - builder
    • length

      public int length()
    • getSourceRange

      @NotNull public @NotNull Range getSourceRange()
      Description copied from interface: BasedSequence
      Get the range of this sequence in original BasedSequence.getBaseSequence() and BasedSequence.getBase() original text source.
      Returns:
      Range of start offset and end offset
    • getIndexOffset

      public int getIndexOffset(int index)
      Description copied from interface: BasedSequence
      Get the offset of index in this sequence mapped to offset into BasedSequence.getBaseSequence() and BasedSequence.getBase() original text source. NOTE: if the character at given index does not equal the corresponding character in the base sequence then this method should return -1 otherwise segmented based sequence will be created for original base character
      Parameters:
      index - index for which to get the offset in original source
      Returns:
      offset of index of this sequence in original text
    • charAt

      public char charAt(int index)
    • subSequence

      @NotNull public @NotNull SubSequence subSequence(int startIndex, int endIndex)
      Description copied from interface: BasedSequence
      Get a portion of this sequence
      Parameters:
      startIndex - offset from startIndex of this sequence
      endIndex - offset from startIndex of this sequence
      Returns:
      based sequence which represents the requested range of this sequence.
    • baseSubSequence

      @NotNull public @NotNull SubSequence 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
      Overrides:
      baseSubSequence in class BasedSequenceImpl
      Parameters:
      startIndex - offset from 0 of original sequence
      endIndex - offset from 0 of original sequence
      Returns:
      based sequence whose contents reflect the selected portion
    • create

      static BasedSequence create(@Nullable @Nullable CharSequence charSequence)
    • of

      @Deprecated public static BasedSequence of(@Nullable @Nullable CharSequence charSequence)
      Deprecated.
    • of

      @Deprecated public static BasedSequence of(@Nullable @Nullable CharSequence charSequence, int startIndex)
      Deprecated.
    • of

      @Deprecated public static BasedSequence of(@Nullable @Nullable CharSequence charSequence, int startIndex, int endIndex)
      Deprecated.