Class UnitSuffixProviders
- java.lang.Object
-
- com.pervasivecode.utils.time.UnitSuffixProviders
-
public class UnitSuffixProviders extends Object
Factory methods for UnitSuffixProvider instances that behave in ways that are appropriate for most locales.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static UnitSuffixProvider
fixedSuffixPerUnit(Map<ChronoUnit,String> unitSuffixes)
Get a UnitSuffixProvider that provides unit suffixes that are fixed regardless of the magnitude of the value being formatted.static UnitSuffixProvider
singularAndPlural(Map<ChronoUnit,String> singularUnitSuffixes, Map<ChronoUnit,String> pluralUnitSuffixes)
Get a UnitSuffixProvider that provides unit suffixes that are either singluar or plural.static UnitSuffixProvider
singularAndPlural(Map<ChronoUnit,String> singularUnitSuffixes, Map<ChronoUnit,String> pluralUnitSuffixes, boolean negativeOneIsSingular)
Get a UnitSuffixProvider that provides unit suffixes that are either singluar or plural, with a configurable definition of whether negative one is considered to be singular.
-
-
-
Method Detail
-
fixedSuffixPerUnit
public static UnitSuffixProvider fixedSuffixPerUnit(Map<ChronoUnit,String> unitSuffixes)
Get a UnitSuffixProvider that provides unit suffixes that are fixed regardless of the magnitude of the value being formatted.Example: Durations in units of seconds formatted as 30s, 1s, and 0.5s all use the same "s" suffix regardless of their magnitude.
- Parameters:
unitSuffixes
- A map of units of time to the suffix to use when formatting values in those units.- Returns:
- A UnitSuffixProvider that simply returns the appropriate value from unitSuffixes.
-
singularAndPlural
public static UnitSuffixProvider singularAndPlural(Map<ChronoUnit,String> singularUnitSuffixes, Map<ChronoUnit,String> pluralUnitSuffixes)
Get a UnitSuffixProvider that provides unit suffixes that are either singluar or plural.Singular is defined here as "equal to one". All other values are considered to be plural.
Example: Durations in units of seconds formatted as 30 seconds, 1 second, and 0.5 seconds use either "second" or "seconds" suffixes. Negative one will be formatted as a plural value, so with this example set of suffixes, it would be formatted as "-1 seconds".
- Parameters:
singularUnitSuffixes
- A map of units of time to the suffix to use when formatting singular values in those units.pluralUnitSuffixes
- A map of units of time to the suffix to use when formatting plural values in those units.- Returns:
- A UnitSuffixProvider that returns the appropriate value from unitSuffixes.
-
singularAndPlural
public static UnitSuffixProvider singularAndPlural(Map<ChronoUnit,String> singularUnitSuffixes, Map<ChronoUnit,String> pluralUnitSuffixes, boolean negativeOneIsSingular)
Get a UnitSuffixProvider that provides unit suffixes that are either singluar or plural, with a configurable definition of whether negative one is considered to be singular.Singular is defined here as "equal to one" or (if the
negativeOneIsSingular
parameter is true) "equal to positive one or negative one". All other values are considered to be plural.Example: Durations in units of seconds formatted as 30 seconds, 1 second, and 0.5 seconds use either "second" or "seconds" suffixes. If the
negativeOneIsSingular
parameter is true, negative one will be formatted as a singular value, so with this example set of suffixes, it would be formatted as "-1 second".- Parameters:
singularUnitSuffixes
- A map of units of time to the suffix to use when formatting singular values in those units.pluralUnitSuffixes
- A map of units of time to the suffix to use when formatting plural values in those units.negativeOneIsSingular
- If true, the value negative one (-1) will be treated as a singular value. Otherwise, it will be treated as plural (exactly assingularAndPlural(Map, Map)
does).- Returns:
- A UnitSuffixProvider that returns the appropriate value from unitSuffixes.
-
-