Class CopyOnWriteTextStore

java.lang.Object
aQute.bnd.properties.CopyOnWriteTextStore
All Implemented Interfaces:
ITextStore

public class CopyOnWriteTextStore extends Object implements ITextStore
Copy-on-write ITextStore wrapper.

This implementation uses an unmodifiable text store for the initial content. Upon first modification attempt, the unmodifiable store is replaced with a modifiable instance which must be supplied in the constructor.

This class is not intended to be subclassed.

Since:
3.2 @noextend This class is not intended to be subclassed by clients.
  • Field Details

    • fTextStore

      protected ITextStore fTextStore
      The underlying "real" text store
    • fModifiableTextStore

      private final ITextStore fModifiableTextStore
      A modifiable ITextStore instance
  • Constructor Details

    • CopyOnWriteTextStore

      public CopyOnWriteTextStore(ITextStore modifiableTextStore)
      Creates an empty text store. The given text store will be used upon first modification attempt.
      Parameters:
      modifiableTextStore - a modifiable ITextStore instance, may not be null
  • Method Details

    • get

      public char get(int offset)
      Description copied from interface: ITextStore
      Returns the character at the specified offset.
      Specified by:
      get in interface ITextStore
      Parameters:
      offset - the offset in this text store
      Returns:
      the character at this offset
    • get

      public String get(int offset, int length)
      Description copied from interface: ITextStore
      Returns the text of the specified character range.
      Specified by:
      get in interface ITextStore
      Parameters:
      offset - the offset of the range
      length - the length of the range
      Returns:
      the text of the range
    • getLength

      public int getLength()
      Description copied from interface: ITextStore
      Returns number of characters stored in this text store.
      Specified by:
      getLength in interface ITextStore
      Returns:
      the number of characters stored in this text store
    • replace

      public void replace(int offset, int length, String text)
      Description copied from interface: ITextStore
      Replaces the specified character range with the given text. replace(getLength(), 0, "some text") is a valid call and appends text to the end of the text store.
      Specified by:
      replace in interface ITextStore
      Parameters:
      offset - the offset of the range to be replaced
      length - the number of characters to be replaced
      text - the substitution text
    • set

      public void set(String text)
      Description copied from interface: ITextStore
      Replace the content of the text store with the given text. Convenience method for replace(0, getLength(), text.
      Specified by:
      set in interface ITextStore
      Parameters:
      text - the new content of the text store