com.vaadin.server.

Class 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.

    Since:

    7.4

    Author:

    Vaadin Ltd

    See Also:

    Serialized Form

    • Constructor Detail

      • SizeWithUnit

        public SizeWithUnit​(float size,
                            Sizeable.Unit unit)

        Constructs a new SizeWithUnit object representing the pair (size, unit).

        Parameters:

        size - a numeric value

        unit - a unit

    • Method Detail

      • getSize

        public float getSize()

        Returns the numeric value stored in this object.

        Returns:

        the value of this (value, unit) pair

      • getUnit

        public Sizeable.Unit getUnit()

        Returns the unit stored in this object.

        Returns:

        the unit of this (value, unit) pair

      • parseStringSize

        public static SizeWithUnit parseStringSize​(String s,
                                                   Sizeable.Unit defaultUnit)

        Returns an object whose numeric value and unit are taken from the string s. If s does not specify a unit and defaultUnit is not null, defaultUnit is used as the unit. If defaultUnit is null and s is a nonempty string representing a unitless number, an exception is thrown. Null or empty string will produce {-1,Unit#PIXELS}.

        Parameters:

        s - the string to be parsed

        defaultUnit - The unit to be used if s 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​(String s)

        Returns an object whose numeric value and unit are taken from the string s. Null or empty string will produce {-1,Unit#PIXELS}. An exception is thrown if s specifies a number without a unit.

        Parameters:

        s - the string to be parsed

        Returns:

        an object containing the parsed value and unit