Interface IColoredString<T>

Type Parameters:
T - The type of colors;
All Superinterfaces:
Iterable<IColoredString.Bucket<T>>
All Known Implementing Classes:
IColoredString.Impl

public interface IColoredString<T>
extends Iterable<IColoredString.Bucket<T>>
A String divided in chunks of different colors. Use the Iterable interface to get the pieces.
Author:
smelC
  • Method Details

    • append

      void append​(char c)
      A convenience alias for append(c, null).
      Parameters:
      c - the char to append
    • append

      void append​(char c, T color)
      Mutates this by appending c to it.
      Parameters:
      c - The text to append.
      color - text's color. Or null to let the panel decide.
    • append

      void append​(String text)
      A convenience alias for append(text, null).
      Parameters:
      text -
    • append

      void append​(String text, T color)
      Mutates this by appending text to it. Does nothing if text is null.
      Parameters:
      text - The text to append.
      color - text's color. Or null to let the panel decide.
    • appendInt

      void appendInt​(int i, T color)
      Mutates this by appending i to it.
      Parameters:
      i - The int to append.
      color - text's color. Or null to let the panel decide.
    • appendFloat

      void appendFloat​(float f, T color)
      Mutates this by appending f to it.
      Parameters:
      f - The float to append.
      color - text's color. Or null to let the panel decide.
    • append

      void append​(IColoredString<T> other)
      Mutates this by appending other to it.
      Parameters:
      other -
    • replaceColor

      void replaceColor​(T old, T new_)
      Replace color old by new_ in all buckets of this.
      Parameters:
      old - The color to replace.
      new_ - The replacing color.
    • setColor

      void setColor​(T color)
      Set color in all buckets.
      Parameters:
      color -
    • setLength

      void setLength​(int len)
      Deletes all content after index len (if any).
      Parameters:
      len -
    • isEmpty

      boolean isEmpty()
      Returns:
      true if present() is "".
    • wrap

      List<IColoredString<T>> wrap​(int width)
      Parameters:
      width - A positive integer
      Returns:
      this split in pieces that would fit in a display with width columns (if all words in this are smaller or equal in length to width, otherwise wrapping will fail for these words).
    • wrap

      List<IColoredString<T>> wrap​(int width, List<IColoredString<T>> buf)
      Parameters:
      width - A positive integer
      buf - A List of IColoredString with the same T type as this; will have the wrapped contents appended to it. Cannot be null, and if it has existing contents, they will be left as-is.
      Returns:
      buf containing this split in pieces that would fit in a display with width columns (if all words in this are smaller or equal in length to width, otherwise wrapping will fail for these words).
    • justify

      IColoredString<T> justify​(int width)
      This method does NOT guarantee that the result's length is width. It is impossible to do correct justifying if this's length is greater than width or if this has no space character.
      Parameters:
      width -
      Returns:
      A variant of this where spaces have been introduced in-between words, so that this's length is as close as possible to width. Or this itself if unaffected.
    • clear

      void clear()
      Empties this.
    • lastColor

      This method is typically more efficient than colorAt(int).
      Returns:
      The color of the last bucket, if any.
    • colorAt

      T colorAt​(int index)
      Parameters:
      index -
      Returns:
      The color at index, if any.
      Throws:
      NoSuchElementException - If index equals or is greater to length().
    • charAt

      char charAt​(int index)
      Parameters:
      index -
      Returns:
      The character at index, if any.
      Throws:
      NoSuchElementException - If index equals or is greater to length().
    • length

      int length()
      Returns:
      The length of text.
    • present

      Returns:
      The text that this represents.
    • presentWithMarkup

      Given some way of converting from a T value to an in-line markup tag, returns a string representation of this IColoredString with in-line markup representing colors.
      Parameters:
      markup - an IMarkup implementation
      Returns:
      a String with markup inserted inside.
    • getFragments

      Gets the Buckets as an ArrayList, allowing access by index instead of by Iterable.iterator().
      Returns:
      the Buckets that would be returned by Iterable.iterator(), but in an ArrayList.