Class Appendables

java.lang.Object
com.globalmentor.java.Appendables

public class Appendables extends Object
Utilities for working with Appendable objects.
Author:
Garret Wilson
See Also:
  • Method Details

    • append

      public static <A extends Appendable> A append(@Nonnull A appendable, char character, int count) throws IOException
      Appends a given repetition of characters to an appendable.
      Type Parameters:
      A - The type of appendable.
      Parameters:
      appendable - The appendable to which the characters should be appended.
      character - The character to append.
      count - The number of repetitions of the character.
      Returns:
      The appendable with the appended repetitions of the character.
      Throws:
      NullPointerException - if the given appendable is null.
      IOException - if there is an error appending to the appendable.
    • appendJoined

      public static <A extends Appendable> A appendJoined(@Nonnull A appendable, char delimiter, @Nonnull CharSequence... elements) throws IOException
      Appends character sequences by joining them using the given delimiter character. As with Appendable.append(CharSequence), if any element is null, the four letters "null" will be appended.
      API Note:
      This method is similar to String.join(CharSequence, CharSequence...), but is expected to be more efficient as it does not require the unnecessary creation of an intermediate string.
      Type Parameters:
      A - The type of appendable.
      Parameters:
      appendable - The appendable to append to.
      delimiter - The delimiter that separates each element.
      elements - The elements to join together.
      Returns:
      The given appendable with the joined content appended.
      Throws:
      NullPointerException - if the given appendable and/or the elements is null.
      IOException - if there is an error appending to the appendable.
      See Also:
    • appendJoined

      public static <A extends Appendable> A appendJoined(@Nonnull A appendable, char delimiter, @Nonnull Iterable<? extends CharSequence> elements) throws IOException
      Appends character sequences by joining them using the given delimiter character. As with Appendable.append(CharSequence), if any element is null, the four letters "null" will be appended.
      API Note:
      This method is similar to String.join(CharSequence, CharSequence...), but is expected to be more efficient as it does not require the unnecessary creation of an intermediate string.
      Type Parameters:
      A - The type of appendable.
      Parameters:
      appendable - The appendable to append to.
      delimiter - The delimiter that separates each element.
      elements - The elements to join together.
      Returns:
      The given appendable with the joined content appended.
      Throws:
      NullPointerException - if the given appendable and/or the elements is null.
      IOException - if there is an error appending to the appendable.
      See Also:
    • appendJoined

      public static <A extends Appendable> A appendJoined(@Nonnull A appendable, @Nullable CharSequence delimiter, @Nonnull CharSequence... elements) throws IOException
      Appends character sequences by joining them using the given delimiter character sequence. As with Appendable.append(CharSequence), if any element is null, the four letters "null" will be appended.
      API Note:
      This method is similar to String.join(CharSequence, CharSequence...), but is expected to be more efficient as it does not require the unnecessary creation of an intermediate string.
      Type Parameters:
      A - The type of appendable.
      Parameters:
      appendable - The appendable to append to.
      delimiter - The delimiter that separates each element.
      elements - The elements to join together.
      Returns:
      The given appendable with the joined content appended.
      Throws:
      NullPointerException - if the given appendable, delimiter, and/or the elements is null.
      IOException - if there is an error appending to the appendable.
      See Also:
    • appendJoined

      public static <A extends Appendable> A appendJoined(@Nonnull A appendable, @Nullable CharSequence delimiter, @Nonnull Iterable<? extends CharSequence> elements) throws IOException
      Appends character sequences by joining them using the given delimiter character sequence. As with Appendable.append(CharSequence), if any element is null, the four letters "null" will be appended.
      API Note:
      This method is similar to String.join(CharSequence, CharSequence...), but is expected to be more efficient as it does not require the unnecessary creation of an intermediate string.
      Type Parameters:
      A - The type of appendable.
      Parameters:
      appendable - The appendable to append to.
      delimiter - The delimiter that separates each element.
      elements - The elements to join together.
      Returns:
      The given appendable with the joined content appended.
      Throws:
      NullPointerException - if the given appendable, delimiter, and/or the elements is null.
      IOException - if there is an error appending to the appendable.
      See Also: