Record Class ScaleConstraint

java.lang.Object
java.lang.Record
is.galia.image.ScaleConstraint

public record ScaleConstraint(Rational rational) extends Record

A scale-constrained image can be thought of as a virtually downscaled source image. In contrast to a Scale, the dimensions of a scale-constrained image appear (to the client) to be the dimensions resulting from the constraint, so any scaling-related operations expressed by the client are relative to the scale-constrained image.

Scale constraints are used for providing access to limited-resolution versions of images depending on authorization status. An unauthorized client may only be able to access a 1/2 scaled image, for example.

Scale constraints are expressed as fractions, mainly in order to avoid repeating decimals, which would make for URIs that are hard to canonicalize.

  • Constructor Details

    • ScaleConstraint

      public ScaleConstraint(Rational rational)
      Creates an instance of a ScaleConstraint record class.
      Parameters:
      rational - the value for the rational record component
    • ScaleConstraint

      public ScaleConstraint()
      Initializes a no-op (1:1) constraint.
    • ScaleConstraint

      public ScaleConstraint(long numerator, long denominator)
      Parameters:
      numerator - Scale numerator.
      denominator - Scale denominator.
      Throws:
      IllegalArgumentException - if the numerator or denominator is not positive or if the numerator is greater than the denominator.
  • Method Details

    • getConstrainedSize

      public Size getConstrainedSize(Size fullSize)
      Parameters:
      fullSize - Full image dimensions.
      Returns:
      Virtual full size after applying the constraint described by the instance.
    • reduced

      public ScaleConstraint reduced()
      Returns:
      Instance reduced to lowest terms.
    • getResultingSize

      public Size getResultingSize(Size fullSize)
      Parameters:
      fullSize - Full source image size.
      Returns:
      New downscaled instance.
    • hasEffect

      public boolean hasEffect()
      Returns:
      Whether the instance's numerator and denominator are unequal.
    • toMap

      public Map<String,Long> toMap()
      Returns:
      Map with numerator and denominator keys.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • rational

      public Rational rational()
      Returns the value of the rational record component.
      Returns:
      the value of the rational record component