
com.pervasivecode.utils.measure.ScalingFormatters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of measurement-utils-jsr363 Show documentation
Show all versions of measurement-utils-jsr363 Show documentation
Classes for using and formatting data and data-rate values in the JSR 363 Units of Measurement API.
The newest version!
package com.pervasivecode.utils.measure;
import java.text.NumberFormat;
import java.util.Locale;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import systems.uom.unicode.CLDR;
/**
* This class contains factory methods for formatters using commonly-used data size and data rate
* formats, suitable for use in the {@link Locale#US US} locale.
*/
public class ScalingFormatters {
private ScalingFormatters() {}
/**
* Get a formatter that presents data amounts measured in bytes scaled with IEC binary prefixes
* and formatted as appropriate for the {@link Locale#US US} locale.
*
* @return The formatter.
*/
public static ScalingFormatter dataAmountInIecBinaryBytesUs() {
return new ScalingFormatter(CLDR.BYTE, new IecBinaryPrefixSelector(),
NumberFormat.getInstance(Locale.US), SimpleUnitLabelProviders.getUsInformationLabeler());
}
/**
* Get a formatter that presents data amounts measured in bits scaled with SI prefixes and
* formatted as appropriate for the {@link Locale#US US} locale.
*
* @return The formatter.
*/
public static ScalingFormatter dataAmountInSiBitsUs() {
return new ScalingFormatter(CLDR.BIT, new SiPrefixSelector(),
NumberFormat.getInstance(Locale.US), SimpleUnitLabelProviders.getUsInformationLabeler());
}
/**
* Get a formatter that presents data rates measured in bytes per second scaled with IEC binary
* prefixes and formatted as appropriate for the {@link Locale#US US} locale.
*
* @return The formatter.
*/
public static ScalingFormatter dataRateInIecBinaryBytesPerSecondUs() {
return new ScalingFormatter(InformationRateUnits.BYTES_PER_SECOND,
new IecBinaryPrefixSelector(), NumberFormat.getInstance(Locale.US),
SimpleUnitLabelProviders.getUsInformationRateLabeler());
}
/**
* Get a formatter that presents data amounts measured in bits per second scaled with SI prefixes
* and formatted as appropriate for the {@link Locale#US US} locale.
*
* @return The formatter.
*/
public static ScalingFormatter dataRateInSiBitsPerSecondUs() {
return new ScalingFormatter(InformationRateUnits.BITS_PER_SECOND,
new SiPrefixSelector(), NumberFormat.getInstance(Locale.US),
SimpleUnitLabelProviders.getUsInformationRateLabeler());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy