Class ElementFormatter
java.lang.Object
io.jenkins.plugins.coverage.metrics.model.ElementFormatter
A localized formatter for coverages, metrics, baselines, etc.
- Author:
- Florian Orendi
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionformat
(edu.hm.hafner.coverage.Value value) Formats a generic value using a specific rendering method.Formats a generic value using a specific rendering method.formatAdditionalInformation
(edu.hm.hafner.coverage.Value value) Formats additional information for a generic value using a specific rendering method.formatDelta
(edu.hm.hafner.coverage.Metric metric, edu.hm.hafner.coverage.Value value, Locale locale) Formats a delta percentage to its plain text representation with a leading sign and rounds the value to two decimals.formatDelta
(edu.hm.hafner.coverage.Value value, Locale locale) Formats a delta percentage to its plain text representation with a leading sign and rounds the value to two decimals.formatDetailedValueWithMetric
(edu.hm.hafner.coverage.Value value) Returns a formatted and localized String representation of the specified value prefixed with the metric name.formatDetails
(edu.hm.hafner.coverage.Value value) Formats a generic value using a specific rendering method.formatPercentage
(int covered, int total, Locale locale) Formats a coverage given by covered and total elements as a percentage number.formatPercentage
(edu.hm.hafner.coverage.Coverage coverage, Locale locale) Formats a coverage as a percentage number.formatValue
(edu.hm.hafner.coverage.Value value) Returns a formatted and localized String representation of the specified value (without metric).formatValueWithMetric
(edu.hm.hafner.coverage.Value value) Returns a formatted and localized String representation of the specified value prefixed with the metric name.getBackgroundColorFillPercentage
(edu.hm.hafner.coverage.Value value) Returns the fill percentage for the specified value.getBackgroundColorFillPercentage
(String percentage) Transforms percentages with a ',' decimal separator to a representation using a '.' in order to use the percentage for styling HTML tags.Returns all available baselines as aListBoxModel
.getDisplayColors
(Baseline baseline, edu.hm.hafner.coverage.Value value) Provides the colors to render a given coverage percentage.getDisplayName
(edu.hm.hafner.coverage.Metric metric) Returns a localized human-readable name for the specified metric.getDisplayName
(Baseline baseline) Returns a localized human-readable name for the specified baseline.getFormattedValues
(Stream<? extends edu.hm.hafner.coverage.Value> values, Locale locale) Formats a stream of values to their display representation by using the given locale.getLabel
(edu.hm.hafner.coverage.Metric metric) Returns a localized human-readable label for the specified metric.Returns all available metrics as aListBoxModel
.Gets the display names of the existingcoverage metrics
, sorted by the metrics ordinal.getTooltip
(edu.hm.hafner.coverage.Value value) Formats a generic value using a specific rendering method.boolean
showColors
(edu.hm.hafner.coverage.Value value) Returns whether the value should be rendered by using a color badge.
-
Constructor Details
-
ElementFormatter
public ElementFormatter()
-
-
Method Details
-
getTooltip
Formats a generic value using a specific rendering method. The type of the givenValue
instance is used to select the best matching rendering method. This non-object-oriented approach is required since theValue
instances are provided by a library that is not capable of localizing these values for the user.- Parameters:
value
- the value to format- Returns:
- the formatted value as plain text
-
format
Formats a generic value using a specific rendering method. The type of the givenValue
instance is used to select the best matching rendering method. This non-object-oriented approach is required since theValue
instances are provided by a library that is not capable of localizing these values for the user.- Parameters:
value
- the value to format- Returns:
- the formatted value as plain text
-
format
Formats a generic value using a specific rendering method. The type of the givenValue
instance is used to select the best matching rendering method. This non-object-oriented approach is required since theValue
instances are provided by a library that is not capable of localizing these values for the user.- Parameters:
value
- the value to formatlocale
- the locale to use to render the values- Returns:
- the formatted value as plain text
-
formatDetails
Formats a generic value using a specific rendering method. The type of the givenValue
instance is used to select the best matching rendering method. This non-object-oriented approach is required since theValue
instances are provided by a library that is not capable of localizing these values for the user.- Parameters:
value
- the value to format- Returns:
- the formatted value as plain text
-
formatAdditionalInformation
Formats additional information for a generic value using a specific rendering method. This information can be added as a tooltip. The type of the givenValue
instance is used to select the best matching rendering method. This non-object-oriented approach is required since theValue
instances are provided by a library that is not capable of localizing these values for the user.- Parameters:
value
- the value to format- Returns:
- the formatted value as plain text
-
showColors
public boolean showColors(edu.hm.hafner.coverage.Value value) Returns whether the value should be rendered by using a color badge.- Parameters:
value
- the value to render- Returns:
true
if the value should be rendered by using a color badge,false
otherwise
-
getDisplayColors
public ColorProvider.DisplayColors getDisplayColors(Baseline baseline, edu.hm.hafner.coverage.Value value) Provides the colors to render a given coverage percentage.- Parameters:
baseline
- the baseline to showvalue
- the value to format- Returns:
- the display colors to use
-
formatValue
Returns a formatted and localized String representation of the specified value (without metric).- Parameters:
value
- the value to format- Returns:
- the value formatted as a string
-
formatValueWithMetric
Returns a formatted and localized String representation of the specified value prefixed with the metric name.- Parameters:
value
- the value to format- Returns:
- the value formatted as a string
-
formatDetailedValueWithMetric
Returns a formatted and localized String representation of the specified value prefixed with the metric name. The value will be printed with all details (number of covered and missed items).- Parameters:
value
- the value to format- Returns:
- the value formatted as a string
-
getBackgroundColorFillPercentage
Transforms percentages with a ',' decimal separator to a representation using a '.' in order to use the percentage for styling HTML tags.- Parameters:
percentage
- The text representation of a percentage- Returns:
- the formatted percentage string
-
getBackgroundColorFillPercentage
Returns the fill percentage for the specified value.- Parameters:
value
- the value to format- Returns:
- the percentage string
-
formatPercentage
Formats a coverage as a percentage number. The shown value is multiplied by 100 and rounded by two decimals.- Parameters:
coverage
- the coverage to formatlocale
- the locale to use to render the values- Returns:
- the formatted percentage as plain text
-
formatPercentage
Formats a coverage given by covered and total elements as a percentage number. The shown value is multiplied by 100 and * rounded by two decimals.- Parameters:
covered
- the number of covered itemstotal
- the number of total itemslocale
- the locale to use to render the values- Returns:
- the formatted percentage as plain text
-
formatDelta
public String formatDelta(edu.hm.hafner.coverage.Metric metric, edu.hm.hafner.coverage.Value value, Locale locale) Formats a delta percentage to its plain text representation with a leading sign and rounds the value to two decimals.- Parameters:
metric
- the metric of the valuevalue
- the value of the deltalocale
- the locale to use to render the values- Returns:
- the formatted delta percentage as plain text with a leading sign
-
formatDelta
Formats a delta percentage to its plain text representation with a leading sign and rounds the value to two decimals.- Parameters:
value
- the value of the deltalocale
- the locale to use to render the values- Returns:
- the formatted delta percentage as plain text with a leading sign
-
getDisplayName
Returns a localized human-readable name for the specified metric.- Parameters:
metric
- the metric to get the name for- Returns:
- the display name
-
getSortedCoverageDisplayNames
Gets the display names of the existingcoverage metrics
, sorted by the metrics ordinal.- Returns:
- the sorted metric display names
-
getFormattedValues
public List<String> getFormattedValues(Stream<? extends edu.hm.hafner.coverage.Value> values, Locale locale) Formats a stream of values to their display representation by using the given locale.- Parameters:
values
- The values to be formattedlocale
- The locale to be used for formatting- Returns:
- the formatted values in the origin order of the stream
-
getLabel
Returns a localized human-readable label for the specified metric.- Parameters:
metric
- the metric to get the label for- Returns:
- the display name
-
getDisplayName
Returns a localized human-readable name for the specified baseline.- Parameters:
baseline
- the baseline to get the name for- Returns:
- the display name
-
getMetricItems
Returns all available metrics as aListBoxModel
.- Returns:
- the metrics in a
ListBoxModel
-
getBaselineItems
Returns all available baselines as aListBoxModel
.- Returns:
- the baselines in a
ListBoxModel
-