Package com.norconex.commons.lang.unit

# Class DataUnitFormatter

java.lang.Object
com.norconex.commons.lang.unit.DataUnitFormatter

All Implemented Interfaces:
  `Serializable`

public class DataUnitFormatter extends Object implements Serializable

Formats a data unit to a human-readable string.

As of 2.0.0, a distinction is made between decimal (default) and binary units. Also, units are now supported up to yotta (10008) or yobi (10248).

Since:
  1.4.0
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DataUnitFormatter()`
  Creates a new DataUnit formatter using decimal notation, with default system locale, and without decimals.
  `DataUnitFormatter(DataUnitFormatter formatter)`
  Copy constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected boolean`
  `canEqual(Object other)`
  `boolean`
  `equals(Object o)`
  `String`
  `format(double amount, DataUnit unit)`
  Formats a data amount of the given unit to a human-readable representation.
  `String`
  `format(BigDecimal amount, DataUnit unit)`
  Formats a data amount of the given unit to a human-readable representation.
  `int`
  `getDecimalPrecision()`
  `Locale`
  `getLocale()`
  `RoundingMode`
  `getRoundingMode()`
  `int`
  `hashCode()`
  `boolean`
  `isBinaryNotation()`
  `boolean`
  `isFixedUnit()`
  `DataUnitFormatter`
  `setBinaryNotation(boolean binaryNotation)`
  `DataUnitFormatter`
  `setDecimalPrecision(int decimalPrecision)`
  `DataUnitFormatter`
  `setFixedUnit(boolean fixedUnit)`
  `DataUnitFormatter`
  `setLocale(Locale locale)`
  `DataUnitFormatter`
  `setRoundingMode(RoundingMode roundingMode)`
  `String`
  `toString()`
  `DataUnitFormatter`
  `withBinaryNotation(boolean binaryNotation)`
  `DataUnitFormatter`
  `withDecimalPrecision(int decimalPrecision)`
  `DataUnitFormatter`
  `withFixedUnit(boolean fixedUnit)`
  `DataUnitFormatter`
  `withLocale(Locale locale)`
  `DataUnitFormatter`
  `withRoundingMode(RoundingMode roundingMode)`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### DataUnitFormatter

    public DataUnitFormatter()
    Creates a new DataUnit formatter using decimal notation, with default system locale, and without decimals.

  - ### DataUnitFormatter

    public DataUnitFormatter(DataUnitFormatter formatter)
    Copy constructor. Passing a `null` formatter is the same as invoking `DataUnitFormatter()` without arguments
    Parameters:
      `formatter` - formatter to copy

- ## Method Details

  - ### getLocale

    public Locale getLocale()

  - ### setLocale

    public DataUnitFormatter setLocale(Locale locale)

  - ### withLocale

    public DataUnitFormatter withLocale(Locale locale)

  - ### getDecimalPrecision

    public int getDecimalPrecision()

  - ### setDecimalPrecision

    public DataUnitFormatter setDecimalPrecision(int decimalPrecision)

  - ### withDecimalPrecision

    public DataUnitFormatter withDecimalPrecision(int decimalPrecision)

  - ### isFixedUnit

    public boolean isFixedUnit()

  - ### setFixedUnit

    public DataUnitFormatter setFixedUnit(boolean fixedUnit)

  - ### withFixedUnit

    public DataUnitFormatter withFixedUnit(boolean fixedUnit)

  - ### isBinaryNotation

    public boolean isBinaryNotation()

  - ### setBinaryNotation

    public DataUnitFormatter setBinaryNotation(boolean binaryNotation)

  - ### withBinaryNotation

    public DataUnitFormatter withBinaryNotation(boolean binaryNotation)

  - ### getRoundingMode

    public RoundingMode getRoundingMode()

  - ### setRoundingMode

    public DataUnitFormatter setRoundingMode(RoundingMode roundingMode)

  - ### withRoundingMode

    public DataUnitFormatter withRoundingMode(RoundingMode roundingMode)

  - ### format

    public String format(double amount, DataUnit unit)
    Formats a data amount of the given unit to a human-readable representation.
    Parameters:
      `amount` - the amount to format
      `unit` - the data unit type of the amount
    Returns:
      formatted string

  - ### format

    public String format(BigDecimal amount, DataUnit unit)
    Formats a data amount of the given unit to a human-readable representation.
    Parameters:
      `amount` - the amount to format
      `unit` - the data unit type of the amount
    Returns:
      formatted string

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### canEqual

    protected boolean canEqual(Object other)

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`