Class PrintStyleBuilder
- java.lang.Object
-
- net.obvj.performetrics.util.print.PrintStyleBuilder
-
public class PrintStyleBuilder extends Object
A builder for creatingPrintStyleobjects. Example:PrintStyle printStyle = new PrintStyleBuilder() .withHeader() .withRowFormat("%-15s %19s") .withDurationFormat(DurationFormat.FULL) .withoutLegends() .withSimpleLine('-', 36) .build();- Since:
- 2.2.1
- Author:
- oswaldo.bapvic.jr
- See Also:
PrintFormat
-
-
Constructor Summary
Constructors Constructor Description PrintStyleBuilder(PrintFormat printFormat)Creates an empty PrintStyle builder.PrintStyleBuilder(PrintStyle source)Creates a new PrintStyle builder with the same attributes of an existing PrintStyle.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PrintStylebuild()Builds the PrintStyle.static StringgenerateLine(char character, int length)Generates a string using the specified character repeated to a given length.static booleanisEmpty(String string)Returnstrueif the specified string is either null or empty.PrintStyleBuilderresetCustomCounterNames()Resets any preset custom counter names in the targetPrintStyle.PrintStyleBuilderwithAllTypes()Removes any type exclusion configuration at the target print style.PrintStyleBuilderwithAlternativeLine(char character, int length)Defines an alternative line, to be generated using the specified character repeated to a given length.PrintStyleBuilderwithAlternativeLine(String string)Defines an alternative line.PrintStyleBuilderwithCustomCounterName(Counter.Type type, String name)Defines a custom counter name for a specific counter type.PrintStyleBuilderwithDurationFormat(DurationFormat format)Defines theDurationFormatto be applied on all rows containing a time duration.PrintStyleBuilderwithHeader()Enables the header row, to be formatted using the same general row format and preset column names.PrintStyleBuilderwithHeader(String format)Enables the header row and defines a specific format string in printf-style to be applied.PrintStyleBuilderwithLegends()Enables printing legends after time durations.PrintStyleBuilderwithoutHeader()Explicitly disables the header row.PrintStyleBuilderwithoutLegends()Explicitly disables legends after time durations.PrintStyleBuilderwithoutSectionSummary()Explicitly disables the section summary row.PrintStyleBuilderwithoutSectionTrailer()Explicitly disables the section trailer row.PrintStyleBuilderwithoutTrailer()Explicitly disables the trailer row.PrintStyleBuilderwithoutTypes(Counter.Type... excludedTypes)Removes the specified type(s) from the output, if present in the stopwatch.PrintStyleBuilderwithRowFormat(String format)Defines a format string in printf-style to be applied for all rows.PrintStyleBuilderwithSectionHeader(String format)Defines a format string in printf-style to the applied for the section headers.PrintStyleBuilderwithSectionSummary(String format)Enables the section summary row and defines the format string in printf-style to be applied.PrintStyleBuilderwithSectionTrailer(String format)Enables the section trailer row and defines the format string in printf-style to be applied.PrintStyleBuilderwithSimpleLine(char character, int length)Defines a simple line, to be generated using the specified character repeated to a given length.PrintStyleBuilderwithSimpleLine(String string)Defines a simple line.PrintStyleBuilderwithTrailer(String format)Enables the trailer row and defines a specific format string in printf-style to be applied.
-
-
-
Constructor Detail
-
PrintStyleBuilder
public PrintStyleBuilder(PrintFormat printFormat)
Creates an empty PrintStyle builder.- Parameters:
printFormat- the targetPrintFormat, not null- Throws:
NullPointerException- if the specified PrintFormat is null- Since:
- 2.2.2
-
PrintStyleBuilder
public PrintStyleBuilder(PrintStyle source)
Creates a new PrintStyle builder with the same attributes of an existing PrintStyle.- Parameters:
source- the PrintStyle whose attributes are to be copied- Throws:
NullPointerException- if the specified PrintStyle is null
-
-
Method Detail
-
withRowFormat
public PrintStyleBuilder withRowFormat(String format)
Defines a format string in printf-style to be applied for all rows.The position of fields must be defined according to the target
PrintFormat:-
SUMMARIZED
- Counter type (e.g.: "Wall-clock time")
- Elapsed time
-
DETAILED
- Sequential timing session identifier
- Elapsed time
- Elapsed time (accumulated)
- (Optional) Counter type (e.g.: "Wall-clock time")
For example: considering the
PrintFormat.SUMMARIZEDandDurationFormat.FULL, the format string"%1$s %2$s"produces"Wall-clock time 0:00:00.049085700", while the format string"%2$s %1$s"produces"0:00:00.049085700 Wall-clock time".Not all fields are mandatory, so the format string
"%2$s"is also valid, and produces"0:00:00.049085700".- Parameters:
format- the format string to be applied- Returns:
- a reference to this builder object for chained calls
- See Also:
Formatter,PrintStyle
-
-
withHeader
public PrintStyleBuilder withHeader()
Enables the header row, to be formatted using the same general row format and preset column names.To specify a different format for the header row, use
withHeader(String).- Returns:
- a reference to this builder object for chained calls
-
withHeader
public PrintStyleBuilder withHeader(String format)
Enables the header row and defines a specific format string in printf-style to be applied.The number and sequence of string positions must be defined according to the target stopwatch formatter:
-
SUMMARIZED
- Counter type
- Elapsed time
-
DETAILED
- Sequential timing session identifier
- Elapsed time
- Elapsed time (accumulated)
- (Optional) Counter type
To enable the header without specifying a custom format, use the zero-argument option
withHeader().- Parameters:
format- the format string to be applied for the header row- Returns:
- a reference to this builder object for chained calls
- See Also:
Formatter,PrintStyle
-
-
withoutHeader
public PrintStyleBuilder withoutHeader()
Explicitly disables the header row.- Returns:
- a reference to this builder object for chained calls
-
withTrailer
public PrintStyleBuilder withTrailer(String format)
Enables the trailer row and defines a specific format string in printf-style to be applied.The number and sequence of string positions must be defined according to the target stopwatch formatter:
-
SUMMARIZED
- Counter type
- Elapsed time
-
DETAILED
- Sequential timing session identifier
- Elapsed time
- Elapsed time (accumulated)
- (Optional) Counter type
- Parameters:
format- the format string to be applied for the trailer row- Returns:
- a reference to this builder object for chained calls
- Since:
- 2.3.0
- See Also:
Formatter,PrintStyle
-
-
withoutTrailer
public PrintStyleBuilder withoutTrailer()
Explicitly disables the trailer row.- Returns:
- a reference to this builder object for chained calls
- Since:
- 2.3.0
-
withSectionHeader
public PrintStyleBuilder withSectionHeader(String format)
Defines a format string in printf-style to the applied for the section headers.- Parameters:
format- the format string to be applied for each section header row- Returns:
- a reference to this builder object for chained calls
-
withoutSectionSummary
public PrintStyleBuilder withoutSectionSummary()
Explicitly disables the section summary row.- Returns:
- a reference to this builder object for chained calls
-
withSectionSummary
public PrintStyleBuilder withSectionSummary(String format)
Enables the section summary row and defines the format string in printf-style to be applied.Note: The property modified by this method is only applicable for the detailed stopwatch formatter.
- Parameters:
format- the format string to be applied for the section summary row- Returns:
- a reference to this builder object for chained calls
-
withoutSectionTrailer
public PrintStyleBuilder withoutSectionTrailer()
Explicitly disables the section trailer row.- Returns:
- a reference to this builder object for chained calls
- Since:
- 2.3.0
-
withSectionTrailer
public PrintStyleBuilder withSectionTrailer(String format)
Enables the section trailer row and defines the format string in printf-style to be applied.Note: The property modified by this method is only applicable for the detailed stopwatch formatter.
- Parameters:
format- the format string to be applied for the section trailer row- Returns:
- a reference to this builder object for chained calls
- Since:
- 2.3.0
-
withSimpleLine
public PrintStyleBuilder withSimpleLine(char character, int length)
Defines a simple line, to be generated using the specified character repeated to a given length.- Parameters:
character- a character to compose the stringlength- number of times to repeat the character; must be > 0- Returns:
- a reference to this builder object for chained calls
-
withSimpleLine
public PrintStyleBuilder withSimpleLine(String string)
Defines a simple line.- Parameters:
string- the string to be used as the simple line- Returns:
- a reference to this builder object for chained calls
-
withAlternativeLine
public PrintStyleBuilder withAlternativeLine(char character, int length)
Defines an alternative line, to be generated using the specified character repeated to a given length.- Parameters:
character- a character to compose the stringlength- number of times to repeat the character; must be > 0- Returns:
- a reference to this builder object for chained calls
-
withAlternativeLine
public PrintStyleBuilder withAlternativeLine(String string)
Defines an alternative line.- Parameters:
string- the string to be used as the alternative line- Returns:
- a reference to this builder object for chained calls
-
withDurationFormat
public PrintStyleBuilder withDurationFormat(DurationFormat format)
Defines theDurationFormatto be applied on all rows containing a time duration.- Parameters:
format- theDurationFormatto be applied- Returns:
- a reference to this builder object for chained calls
-
withLegends
public PrintStyleBuilder withLegends()
Enables printing legends after time durations.- Returns:
- a reference to this builder object for chained calls
-
withoutLegends
public PrintStyleBuilder withoutLegends()
Explicitly disables legends after time durations.- Returns:
- a reference to this builder object for chained calls
-
withoutTypes
public PrintStyleBuilder withoutTypes(Counter.Type... excludedTypes)
Removes the specified type(s) from the output, if present in the stopwatch.- Parameters:
excludedTypes- one or more types to exclude- Returns:
- a reference to this builder object for chained calls
- Since:
- 2.4.0
-
withAllTypes
public PrintStyleBuilder withAllTypes()
Removes any type exclusion configuration at the target print style.- Returns:
- a reference to this builder object for chained calls
- Since:
- 2.4.0
-
withCustomCounterName
public PrintStyleBuilder withCustomCounterName(Counter.Type type, String name)
Defines a custom counter name for a specific counter type.Subsequent calls to this method will add new pairs of type and custom name to the target map.
If a counter type is not specified, the default counter name (determined by
Counter.Type.toString()) will be applied in the output generated by the targetPrintStyle.- Parameters:
type- the counter type to be specifiedname- the custom name to be associated with the counter type- Returns:
- a reference to this builder object for chained calls
- Since:
- 2.4.0
-
resetCustomCounterNames
public PrintStyleBuilder resetCustomCounterNames()
Resets any preset custom counter names in the targetPrintStyle.- Returns:
- a reference to this builder object for chained calls
- Since:
- 2.4.0
-
build
public PrintStyle build()
Builds the PrintStyle.- Returns:
- an immutable
PrintStyle; not null
-
isEmpty
public static boolean isEmpty(String string)
Returnstrueif the specified string is either null or empty.- Parameters:
string- the string to be checked- Returns:
- true if the specified string is either null or empty.
-
generateLine
public static String generateLine(char character, int length)
Generates a string using the specified character repeated to a given length.- Parameters:
character- a character to compose the stringlength- number of times to repeat the character; must be > 0- Returns:
- a string with repeated character
-
-