Class ColumnFormatter.Builder
java.lang.Object
eu.cloudnetservice.utils.base.column.ColumnFormatter.Builder
- Enclosing class:
ColumnFormatter
A builder for a column formatter. By default the builder uses
|as the left bracket- a space as the right bracket
- a space as the left spacer
- an empty string as the right spacer
—for the header spacing.
- Since:
- 4.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Constructs a new column formatter instance from the values supplied to this builder.columnLeftBracket(char columnLeftBracket) Sets the left bracket to apply to the column.columnRightBracket(char columnRightBracket) Sets the right bracket to apply to the column.columnTitles(@NonNull String... columnTitles) Sets the column titles to use for the table.columnTitles(@NonNull List<String> columnTitles) Sets the column titles to use for the table.headerValuesSpacerChar(char headerValuesSpacerChar) Sets the spacer character to apply between the header of a table and the table values.leftSpacer(@NonNull String leftSpacer) Sets the left spacer to apply to the column.rightSpacer(@NonNull String rightSpacer) Sets the right spacer to apply to the column.
-
Field Details
-
leftSpacer
-
rightSpacer
-
columnLeftBracket
private char columnLeftBracket -
columnRightBracket
private char columnRightBracket -
headerValuesSpacerChar
private char headerValuesSpacerChar -
columnTitles
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
leftSpacer
@Contract(value="_ -> this", pure=true) @NonNull public @NonNull ColumnFormatter.Builder leftSpacer(@NonNull @NonNull String leftSpacer) Sets the left spacer to apply to the column. The left spacer is printed after the left bracket. This value defaults to a space.- Parameters:
leftSpacer- the left spacer to use.- Returns:
- the same builder instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given left spacer is null.
-
rightSpacer
@Contract(value="_ -> this", pure=true) @NonNull public @NonNull ColumnFormatter.Builder rightSpacer(@NonNull @NonNull String rightSpacer) Sets the right spacer to apply to the column. The right spacer is printed after the value of entry and before the right bracket. This value defaults to an empty string.- Parameters:
rightSpacer- the right spacer to use.- Returns:
- the same builder instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given right spacer is null.
-
columnLeftBracket
@Contract(value="_ -> this", pure=true) @NonNull public @NonNull ColumnFormatter.Builder columnLeftBracket(char columnLeftBracket) Sets the left bracket to apply to the column. The left bracket is the first char printed in each line. This value defaults to|.- Parameters:
columnLeftBracket- the left bracket to use.- Returns:
- the same builder instance as used to call the method, for chaining.
-
columnRightBracket
@Contract(value="_ -> this", pure=true) @NonNull public @NonNull ColumnFormatter.Builder columnRightBracket(char columnRightBracket) Sets the right bracket to apply to the column. The right bracket is the last char printed in each line. This value defaults to a space.- Parameters:
columnRightBracket- the right bracket to use.- Returns:
- the same builder instance as used to call the method, for chaining.
-
headerValuesSpacerChar
@Contract(value="_ -> this", pure=true) @NonNull public @NonNull ColumnFormatter.Builder headerValuesSpacerChar(char headerValuesSpacerChar) Sets the spacer character to apply between the header of a table and the table values. This value defaults to—.- Parameters:
headerValuesSpacerChar- the spacer char to use.- Returns:
- the same builder instance as used to call the method, for chaining.
-
columnTitles
@Contract(value="_ -> this", pure=true) @NonNull public @NonNull ColumnFormatter.Builder columnTitles(@NonNull @NonNull List<String> columnTitles) Sets the column titles to use for the table. This method copies the given list of titles into this builder, meaning that changes to the given list are not reflected into this builder.- Parameters:
columnTitles- the colum titles.- Returns:
- the same builder instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given column titles list is null.
-
columnTitles
@NonNull public @NonNull ColumnFormatter.Builder columnTitles(@NonNull @NonNull String... columnTitles) Sets the column titles to use for the table. This method copies the given array of titles into this builder, meaning that changes to the given array are not reflected into this builder.- Parameters:
columnTitles- the colum titles.- Returns:
- the same builder instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given column titles array is null.
-
build
Constructs a new column formatter instance from the values supplied to this builder.- Returns:
- a new column formatter instance.
- Throws:
IllegalArgumentException- if no column titles were given to this builder.
-