Class Percentage
- java.lang.Object
-
- com.parasoft.findings.jenkins.coverage.model.Percentage
-
- All Implemented Interfaces:
Serializable
public final class Percentage extends Object implements 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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Percentage
ZERO
null value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
String
formatDeltaPercentage(Locale locale)
Formats a delta percentage to its plain text representation with a leading sign and rounds the value to two decimals.String
formatPercentage(Locale locale)
Formats a percentage to plain text and rounds the value to two decimals.int
getItems()
int
getTotal()
int
hashCode()
String
serializeToString()
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].String
toString()
static Percentage
valueOf(int items, int total)
Creates an instance ofPercentage
from the two number items and total.static Percentage
valueOf(String stringRepresentation)
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 Detail
-
ZERO
public static final Percentage ZERO
null value.
-
-
Method Detail
-
valueOf
public 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]. 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
public static Percentage valueOf(int items, int total)
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
public static Percentage valueOf(String stringRepresentation)
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
public String formatPercentage(Locale locale)
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
public org.apache.commons.lang3.math.Fraction subtract(Percentage subtrahend)
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
public String formatDeltaPercentage(Locale locale)
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()
-
serializeToString
public String 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
-
-