Class Percentage
java.lang.Object
com.parasoft.findings.jenkins.coverage.model.Percentage
- All Implemented Interfaces:
Serializable
Represents a coverage percentage value which can be used in order to show and serialize coverage values. The class
can also be used for transforming a coverage fraction into its percentage representation. The percentage is
represented by a numerator and a denominator.
- Author:
- Florian Orendi
- See Also:
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
formatDeltaPercentage
(Locale locale) Formats a delta percentage to its plain text representation with a leading sign and rounds the value to two decimals.formatPercentage
(Locale locale) Formats a percentage to plain text and rounds the value to two decimals.int
getItems()
int
getTotal()
int
hashCode()
Returns a string representation for thisPercentage
that can be used to serialize this instance in a simple but still readable way.org.apache.commons.lang3.math.Fraction
subtract
(Percentage subtrahend) Subtracts the other percentage from this percentage, returning the result as aFraction
.double
toDouble()
Returns this percentage as a double value in the interval [0, 100].toString()
static Percentage
valueOf
(int items, int total) Creates an instance ofPercentage
from the two number items and total.static Percentage
Creates a newPercentage
instance from the provided string representation.static Percentage
valueOf
(org.apache.commons.lang3.math.Fraction fraction) Creates an instance ofPercentage
in the range [0,100] from afraction
within the range [0,1].
-
Field Details
-
ZERO
null value.
-
-
Method Details
-
valueOf
Creates an instance ofPercentage
in the range [0,100] from afraction
within the range [0,1]. I.e., a percentage is a fraction value multiplied by one hundert.- Parameters:
fraction
- the value as a fraction within the range [0,1]- Returns:
- the created instance
-
valueOf
Creates an instance ofPercentage
from the two number items and total. The percentage is calculated as value (items / total) * 100.- Parameters:
items
- the number of items in the range [0,total]total
- the total number of items available- Returns:
- the created instance
- Throws:
IllegalArgumentException
- if the denominator is zero or items are greater than total
-
valueOf
Creates a newPercentage
instance from the provided string representation. The string representation is expected to contain the numerator and the denominator - separated by a slash, e.g. "300/345", or "1/100". Whitespace characters will be ignored.- Parameters:
stringRepresentation
- string representation to convert from- Returns:
- the created
Percentage
- Throws:
IllegalArgumentException
- if the string is not a valid Percentage instance
-
toDouble
public double toDouble()Returns this percentage as a double value in the interval [0, 100].- Returns:
- the coverage percentage
-
formatPercentage
Formats a percentage to plain text and rounds the value to two decimals.- Parameters:
locale
- the used locale- Returns:
- the formatted percentage as plain text
-
subtract
Subtracts the other percentage from this percentage, returning the result as aFraction
.- Parameters:
subtrahend
- the percentage to subtract- Returns:
- a
Fraction
instance with the resulting values
-
formatDeltaPercentage
Formats a delta percentage to its plain text representation with a leading sign and rounds the value to two decimals.- Parameters:
locale
- the used locale- Returns:
- the formatted delta percentage as plain text with a leading sign
-
getItems
public int getItems() -
getTotal
public int getTotal() -
equals
-
hashCode
public int hashCode() -
serializeToString
Returns a string representation for thisPercentage
that can be used to serialize this instance in a simple but still readable way. The serialization contains the numerator and the denominator - separated by a slash, e.g. "100/345", or "0/1".- Returns:
- a string representation for this
Percentage
-
toString
-