Package com.globalmentor.java
Class Appendables
java.lang.Object
com.globalmentor.java.Appendables
Utilities for working with
Appendable
objects.- Author:
- Garret Wilson
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A extends Appendable>
Aappend
(A appendable, char character, int count) Appends a given repetition of characters to an appendable.static <A extends Appendable>
AappendJoined
(A appendable, char delimiter, CharSequence... elements) Appends character sequences by joining them using the given delimiter character.static <A extends Appendable>
AappendJoined
(A appendable, char delimiter, Iterable<? extends CharSequence> elements) Appends character sequences by joining them using the given delimiter character.static <A extends Appendable>
AappendJoined
(A appendable, CharSequence delimiter, CharSequence... elements) Appends character sequences by joining them using the given delimiter character sequence.static <A extends Appendable>
AappendJoined
(A appendable, CharSequence delimiter, Iterable<? extends CharSequence> elements) Appends character sequences by joining them using the given delimiter character sequence.
-
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 isnull
.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 withAppendable.append(CharSequence)
, if any element isnull
, 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 isnull
.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 withAppendable.append(CharSequence)
, if any element isnull
, 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 isnull
.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 withAppendable.append(CharSequence)
, if any element isnull
, 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 isnull
.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 withAppendable.append(CharSequence)
, if any element isnull
, 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 isnull
.IOException
- if there is an error appending to the appendable.- See Also:
-