Class SizeWithUnit

java.lang.Object
io.jmix.ui.component.SizeWithUnit
All Implemented Interfaces:
Serializable

public class SizeWithUnit extends Object implements Serializable
A class for representing a value-unit pair. Also contains utility methods for parsing such pairs from a string.
See Also:
  • Field Details

    • SIZE_PATTERN_STRING

      public static final String SIZE_PATTERN_STRING
      See Also:
    • SIZE_PATTERN

      public static final Pattern SIZE_PATTERN
    • size

      protected float size
    • unit

      protected SizeUnit unit
  • Constructor Details

    • SizeWithUnit

      public SizeWithUnit(float size, SizeUnit unit)
      Constructs a new SizeWithUnit object representing the pair (size, unit).
      Parameters:
      size - a numeric value
      unit - a unit
  • Method Details

    • getSize

      public float getSize()
      Returns the numeric value stored in this object.
      Returns:
      the numeric value stored in this object
    • getUnit

      public SizeUnit getUnit()
      Returns the size unit stored in this object.
      Returns:
      the size unit stored in this object
    • stringValue

      public String stringValue()
    • parseStringSize

      public static SizeWithUnit parseStringSize(@Nullable String sizeString, @Nullable SizeUnit defaultUnit)
      Returns an object whose numeric value and unit are taken from the string sizeString. If sizeString does not specify a unit and defaultUnit is not null, defaultUnit is used as the unit. Null, empty or 'AUTO' string will produce {-1, SizeUnit#PIXELS}.
      Parameters:
      sizeString - the string to be parsed
      defaultUnit - The unit to be used if sizeString does not contain any unit. Use null for no default unit.
      Returns:
      an object containing the parsed value and unit
    • parseStringSize

      public static SizeWithUnit parseStringSize(@Nullable String size)
      Returns an object whose numeric value and unit are taken from the string size. Null, empty or 'AUTO' string will produce {-1, SizeUnit#PIXELS}.
      Parameters:
      size - the string to be parsed
      Returns:
      an object containing the parsed value and unit