Class PrintStyleBuilder


  • public class PrintStyleBuilder
    extends Object
    A builder for creating PrintStyle objects. 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 Detail

      • PrintStyleBuilder

        public PrintStyleBuilder​(PrintFormat printFormat)
        Creates an empty PrintStyle builder.
        Parameters:
        printFormat - the target PrintFormat, 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

          1. Counter type (e.g.: "Wall-clock time")
          2. Elapsed time
        • DETAILED

          1. Sequential timing session identifier
          2. Elapsed time
          3. Elapsed time (accumulated)
          4. (Optional) Counter type (e.g.: "Wall-clock time")

        For example: considering the PrintFormat.SUMMARIZED and DurationFormat.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

          1. Counter type
          2. Elapsed time
        • DETAILED

          1. Sequential timing session identifier
          2. Elapsed time
          3. Elapsed time (accumulated)
          4. (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

          1. Counter type
          2. Elapsed time
        • DETAILED

          1. Sequential timing session identifier
          2. Elapsed time
          3. Elapsed time (accumulated)
          4. (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 string
        length - 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 string
        length - 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
      • 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 target PrintStyle.

        Parameters:
        type - the counter type to be specified
        name - 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 target PrintStyle.
        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)
        Returns true if 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 string
        length - number of times to repeat the character; must be > 0
        Returns:
        a string with repeated character