Class Size


  • public class Size
    extends java.lang.Object

    Class that represents a size that is based on a width and height of type Length.

    Constructs from standard paper sizes, generates a string representation, and provides conversions to portrait and landscape mode.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Size.PaperSizes  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      double getAspectRatio()
      Calculate ratio between height and width.
      Length getHeight()
      Gets the height (vertical size) as Length object.
      Length getWidth()
      Gets the width (horizontal size) as Length object.
      int hashCode()  
      static Size parse​(java.lang.String value)
      Create a Size object from a string representation.
      Size toLandscape()
      Switches width and height if the absolute value of height is greater than the the absolute value of width.
      Size toPortrait()
      Switches width and height if the absolute value of the width is greater than the absolute value of the height.
      java.lang.String toString()
      Creates a string representation as width-height-pair with associated suitable metric units, "m", "cm" or "mm".
      java.lang.String toString​(Length.Units unit)
      Creates a string representation as width-height-pair with the specified unit.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Size

        public Size​(Length width,
                    Length height)
        Construct Size object from width and height.
        Parameters:
        width - as Length type
        height - as Length type
      • Size

        public Size​(double width,
                    double height,
                    Length.Units unit)
        Construct Size object from width, height and a common unit.
        Parameters:
        width - as numerical value
        height - as numerical value
        unit - the unit
    • Method Detail

      • parse

        public static Size parse​(java.lang.String value)

        Create a Size object from a string representation.

        Allowed are value-unit pairs of the form "<width_value><width_unit> <height_value><height_unit>" or the name of a standard paper size.

        Examples: "12.3cm 23.9mm" or "A4"

        Parameters:
        value - the string value
        Returns:
      • toString

        public java.lang.String toString()
        Creates a string representation as width-height-pair with associated suitable metric units, "m", "cm" or "mm".
        Overrides:
        toString in class java.lang.Object
      • toString

        public java.lang.String toString​(Length.Units unit)
        Creates a string representation as width-height-pair with the specified unit.
      • toPortrait

        public Size toPortrait()
        Switches width and height if the absolute value of the width is greater than the absolute value of the height.
      • toLandscape

        public Size toLandscape()
        Switches width and height if the absolute value of height is greater than the the absolute value of width.
      • getAspectRatio

        public double getAspectRatio()
        Calculate ratio between height and width.
      • getWidth

        public Length getWidth()
        Gets the width (horizontal size) as Length object.
      • getHeight

        public Length getHeight()
        Gets the height (vertical size) as Length object.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object