Class SizeLong

java.lang.Object
com.helger.base.dimension.SizeLong
All Implemented Interfaces:
IHasDimensionLong, IHasHeightLong, IHasWidthLong

@Immutable public class SizeLong extends Object implements IHasDimensionLong
This class represents an object having width and height.
Author:
Philip Helger
  • Constructor Details

    • SizeLong

      public SizeLong(@NonNull IHasDimensionInt aObj)
      Constructor copying from an existing int dimension object.
      Parameters:
      aObj - The dimension object to copy from. May not be null.
    • SizeLong

      public SizeLong(@NonNull IHasDimensionLong aObj)
      Constructor copying from an existing long dimension object.
      Parameters:
      aObj - The dimension object to copy from. May not be null.
    • SizeLong

      public SizeLong(@Nonnegative long nWidth, @Nonnegative long nHeight)
      Constructor with width and height.
      Parameters:
      nWidth - The width. Must be ≥ 0.
      nHeight - The height. Must be ≥ 0.
  • Method Details

    • getWidth

      @Nonnegative public long getWidth()
      Specified by:
      getWidth in interface IHasWidthLong
      Returns:
      The width of an object
    • getHeight

      @Nonnegative public long getHeight()
      Specified by:
      getHeight in interface IHasHeightLong
      Returns:
      The height of an object
    • getBestMatchingSize

      @CheckReturnValue public @NonNull SizeLong getBestMatchingSize(@Nonnegative long nMaxWidth, @Nonnegative long nMaxHeight)
      Return the scaled width and height relative to a maximum size.
      Parameters:
      nMaxWidth - Maximum width. Must be > 0.
      nMaxHeight - Maximum height. Must be > 0.
      Returns:
      An array with 2 elements, where the first element is the width, and the second is the height.
    • getScaledToWidth

      @CheckReturnValue public @NonNull SizeLong getScaledToWidth(@Nonnegative long nNewWidth)
      Get a new size that is scaled to the specified width, keeping the aspect ratio.
      Parameters:
      nNewWidth - The new width. Must be > 0.
      Returns:
      A new SizeLong with the scaled dimensions. Never null.
    • getScaledToHeight

      @CheckReturnValue public @NonNull SizeLong getScaledToHeight(@Nonnegative long nNewHeight)
      Get a new size that is scaled to the specified height, keeping the aspect ratio.
      Parameters:
      nNewHeight - The new height. Must be > 0.
      Returns:
      A new SizeLong with the scaled dimensions. Never null.
    • getAdded

      @CheckReturnValue public @NonNull SizeLong getAdded(@NonNull IHasDimensionLong aToAdd)
      Get a new size with the dimensions of the provided object added.
      Parameters:
      aToAdd - The dimension to add. May not be null.
      Returns:
      A new SizeLong. Never null.
    • getSubtracted

      @CheckReturnValue public @NonNull SizeLong getSubtracted(@NonNull IHasDimensionLong aToSubtract)
      Get a new size with the dimensions of the provided object subtracted.
      Parameters:
      aToSubtract - The dimension to subtract. May not be null.
      Returns:
      A new SizeLong. Never null.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object