Class HCollector.StringJoinCollector
- java.lang.Object
-
- com.g2forge.alexandria.java.core.helpers.HCollector.StringJoinCollector
-
- Enclosing class:
- HCollector
public static class HCollector.StringJoinCollector extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected StringBuilder
builder
The current set of elements, the prefix and the separators.protected int
lastSeparatorIndex
The index inbuilder
of the most recently appended separator or-1
if none has been appended.protected @NonNull CharSequence
prefix
Prefix to be used before any elements.protected @NonNull CharSequence
separatorLast
Last separator, to be used between the final two elements.protected @NonNull CharSequence
separatorNormal
Normal separator, to be used between all pairs of elements, except the last two.protected @NonNull CharSequence
suffix
Suffix to be used after all elements.
-
Constructor Summary
Constructors Constructor Description StringJoinCollector(@NonNull CharSequence prefix, @NonNull CharSequence separatorNormal, @NonNull CharSequence separatorLast, @NonNull CharSequence suffix)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HCollector.StringJoinCollector
add(CharSequence element)
Add a new element.HCollector.StringJoinCollector
combine(HCollector.StringJoinCollector that)
protected StringBuilder
getBuilder()
The current set of elements, the prefix and the separators.protected StringBuilder
getBuilderNext()
protected int
getLastSeparatorIndex()
The index inbuilder
of the most recently appended separator or-1
if none has been appended.protected @NonNull CharSequence
getPrefix()
Prefix to be used before any elements.protected @NonNull CharSequence
getSeparatorLast()
Last separator, to be used between the final two elements.protected @NonNull CharSequence
getSeparatorNormal()
Normal separator, to be used between all pairs of elements, except the last two.protected @NonNull CharSequence
getSuffix()
Suffix to be used after all elements.protected void
setBuilder(StringBuilder builder)
The current set of elements, the prefix and the separators.protected void
setLastSeparatorIndex(int lastSeparatorIndex)
The index inbuilder
of the most recently appended separator or-1
if none has been appended.String
toString()
-
-
-
Field Detail
-
prefix
@NonNull protected final @NonNull CharSequence prefix
Prefix to be used before any elements.
-
separatorNormal
@NonNull protected final @NonNull CharSequence separatorNormal
Normal separator, to be used between all pairs of elements, except the last two.
-
separatorLast
@NonNull protected final @NonNull CharSequence separatorLast
Last separator, to be used between the final two elements.
-
suffix
@NonNull protected final @NonNull CharSequence suffix
Suffix to be used after all elements.
-
builder
protected StringBuilder builder
The current set of elements, the prefix and the separators. The suffix is never added to this builder, nor is the last separator.
-
lastSeparatorIndex
protected int lastSeparatorIndex
The index inbuilder
of the most recently appended separator or-1
if none has been appended.
-
-
Constructor Detail
-
StringJoinCollector
@ConstructorProperties({"prefix","separatorNormal","separatorLast","suffix"}) public StringJoinCollector(@NonNull @NonNull CharSequence prefix, @NonNull @NonNull CharSequence separatorNormal, @NonNull @NonNull CharSequence separatorLast, @NonNull @NonNull CharSequence suffix)
-
-
Method Detail
-
add
public HCollector.StringJoinCollector add(CharSequence element)
Add a new element.- Parameters:
element
- The element to add.- Returns:
this
-
combine
public HCollector.StringJoinCollector combine(HCollector.StringJoinCollector that)
-
getBuilderNext
protected StringBuilder getBuilderNext()
-
getPrefix
@NonNull protected @NonNull CharSequence getPrefix()
Prefix to be used before any elements.- Returns:
- The prefix to be used before any elements.
-
getSeparatorNormal
@NonNull protected @NonNull CharSequence getSeparatorNormal()
Normal separator, to be used between all pairs of elements, except the last two.- Returns:
- The normal separator, to be used between all pairs of elements, except the last two.
-
getSeparatorLast
@NonNull protected @NonNull CharSequence getSeparatorLast()
Last separator, to be used between the final two elements.- Returns:
- The last separator, to be used between the final two elements.
-
getSuffix
@NonNull protected @NonNull CharSequence getSuffix()
Suffix to be used after all elements.- Returns:
- The suffix to be used after all elements.
-
getBuilder
protected StringBuilder getBuilder()
The current set of elements, the prefix and the separators. The suffix is never added to this builder, nor is the last separator.- Returns:
- The current working result.
-
getLastSeparatorIndex
protected int getLastSeparatorIndex()
The index inbuilder
of the most recently appended separator or-1
if none has been appended.- Returns:
- The index in
getBuilder()
of the most recently appended separator or-1
if none has been appended.
-
setBuilder
protected void setBuilder(StringBuilder builder)
The current set of elements, the prefix and the separators. The suffix is never added to this builder, nor is the last separator.- Parameters:
builder
- The new working result to replace the current one completely.
-
setLastSeparatorIndex
protected void setLastSeparatorIndex(int lastSeparatorIndex)
The index inbuilder
of the most recently appended separator or-1
if none has been appended.- Parameters:
lastSeparatorIndex
- The new index value.
-
-