Class DataSize

java.lang.Object
io.airlift.units.DataSize
All Implemented Interfaces:
Comparable<DataSize>

public final class DataSize extends Object implements Comparable<DataSize>
  • Constructor Details

    • DataSize

      @Deprecated public DataSize(double size, DataSize.Unit unit)
      Deprecated.
      Use of(long, Unit) instead. The imprecise nature of using doubles for DataSize is deprecated for removal
  • Method Details

    • of

      public static DataSize of(long size, DataSize.Unit unit) throws IllegalArgumentException
      Creates a DataSize instance with the provided quantity of the provided DataSize.Unit. This value is immediately converted to bytes which might overflow.
      Parameters:
      size - The quantity of the supplied unit
      unit - The unit to use as the default unit for the constructed instance and to convert the size to bytes
      Throws:
      IllegalArgumentException - If the provided size would overflow a long value when converting to bytes
    • ofBytes

      public static DataSize ofBytes(long bytes)
    • succinctBytes

      public static DataSize succinctBytes(long bytes)
      Prefer ofBytes(long) when conversion to the most 'succinct' unit is not necessary or desirable
    • succinctDataSize

      @Deprecated public static DataSize succinctDataSize(double size, DataSize.Unit unit)
      Deprecated.
      use succinctBytes(long) instead, double values are imprecise
      Prefer of(long, Unit) when conversion to the most 'succinct' unit is not necessary or desirable. Otherwise, use succinctBytes(long) since it will not incur rounding and loss of precision.
    • toBytes

      public long toBytes()
    • getValue

      @Deprecated public double getValue()
      Deprecated.
      Use toBytes() instead to avoid floating point precision semantics
    • getUnit

      public DataSize.Unit getUnit()
    • getValue

      @Deprecated public double getValue(DataSize.Unit unit)
      Deprecated.
      Use toBytes() instead to avoid floating point precision semantics
    • roundTo

      @Deprecated public long roundTo(DataSize.Unit unit)
      Deprecated.
      Use toBytes() instead. This method uses floating point semantics to compute the rounded value which can yield to unexpected loss of precision beyond the intended rounding
    • convertTo

      @Deprecated public DataSize convertTo(DataSize.Unit unit)
      Deprecated.
      Use to(Unit) instead. No conversion occurs when calling this method, only the unit used for the default string representation is changed. This has no effect on the unit used during JSON serialization
    • to

      public DataSize to(DataSize.Unit unit)
    • succinct

      public DataSize succinct()
    • convertToMostSuccinctDataSize

      @Deprecated public DataSize convertToMostSuccinctDataSize()
      Deprecated.
      Use succinct() instead. No conversion occurs when calling this method, only the unit used for the default string representation is changed. This has no effect on the unit used during JSON serialization
    • toBytesValueString

      public String toBytesValueString()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • valueOf

      public static DataSize valueOf(String size) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • compareTo

      public int compareTo(DataSize o)
      Specified by:
      compareTo in interface Comparable<DataSize>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object