Class Extent

  • All Implemented Interfaces:
    java.lang.Comparable<Extent>

    public class Extent
    extends java.lang.Object
    implements java.lang.Comparable<Extent>
    A measurement such as a length, area, or volume. All zero extents are considered equal, regardless of the unit of measurement. For this implementation only extents of the same unit and degree should be compared, although consistent, if inaccurate, values will still be obtained otherwise.
    Author:
    Garret Wilson
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Extent ZERO_EXTENT1
      A convenience one-dimensional extent of zero pixels.
    • Constructor Summary

      Constructors 
      Constructor Description
      Extent​(double value)
      Value constructor for a one-dimensional pixel extent.
      Extent​(double value, Unit unit)
      Value and unit constructor with a degree of one.
      Extent​(double value, Unit unit, int degree)
      Value, unit, and degree constructor.
    • Field Detail

      • ZERO_EXTENT1

        public static final Extent ZERO_EXTENT1
        A convenience one-dimensional extent of zero pixels.
    • Constructor Detail

      • Extent

        public Extent​(double value)
        Value constructor for a one-dimensional pixel extent.
        Parameters:
        value - The value of the extent.
      • Extent

        public Extent​(double value,
                      Unit unit)
        Value and unit constructor with a degree of one.
        Parameters:
        value - The value of the extent.
        unit - The unit with which the extent is measured.
        Throws:
        java.lang.NullPointerException - if the given unit is null.
      • Extent

        public Extent​(double value,
                      Unit unit,
                      int degree)
        Value, unit, and degree constructor.
        Parameters:
        value - The value of the extent.
        unit - The unit with which the extent is measured.
        degree - The degree of dimensions of the measurement.
        Throws:
        java.lang.NullPointerException - if the given unit is null.
        java.lang.IllegalArgumentException - if the degree is non-positive.
    • Method Detail

      • getValue

        public double getValue()
        Returns:
        The value of the extent.
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if the extent has a zero value.
      • getUnit

        public Unit getUnit()
        Returns:
        The unit with which the extent is measured.
      • getDegree

        public int getDegree()
        Returns:
        The degree of dimensions of the measurement.
      • hashCode

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

        public boolean equals​(java.lang.Object object)

        This implementation returns whether the object is another extent with identical value, unit, and degree, ignoring the unit if the value is zero.

        Overrides:
        equals in class java.lang.Object
      • compareTo

        public int compareTo​(Extent extent)

        This implementation is meant to compare extents of identical units; non-identical units will be compared by unit ordinal.

        This implementation is meant to compare extents of identical degrees; non-identical degrees will be compared by degrees.

        Specified by:
        compareTo in interface java.lang.Comparable<Extent>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object