Documentation of 'edu.princeton.cs.algs4.Interval1D' Java class
Interval1D
edu.princeton.cs.algs4

Class Interval1D



  • public class Interval1D
    extends java.lang.Object
    The Interval1D class represents a one-dimensional interval. The interval is closed—it contains both endpoints. Intervals are immutable: their values cannot be changed after they are created. The class Interval1D includes methods for checking whether an interval contains a point and determining whether two intervals intersect.

    For additional documentation, see Section 1.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • Constructor Summary

      Constructors 
      Constructor and Description
      Interval1D(double min, double max)
      Initializes a closed interval [min, max].
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method and Description
      boolean contains(double x)
      Returns true if this interval contains the specified value.
      boolean equals(java.lang.Object other)
      Compares this transaction to the specified object.
      int hashCode()
      Returns an integer hash code for this interval.
      boolean intersects(Interval1D that)
      Returns true if this interval intersects the specified interval.
      double left()
      Deprecated. 
      Replaced by min().
      double length()
      Returns the length of this interval.
      static void main(java.lang.String[] args)
      Unit tests the Interval1D data type.
      double max()
      Returns the max endpoint of this interval.
      double min()
      Returns the min endpoint of this interval.
      double right()
      Deprecated. 
      Replaced by max().
      java.lang.String toString()
      Returns a string representation of this interval.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • MIN_ENDPOINT_ORDER

        public static final java.util.Comparator<Interval1D> MIN_ENDPOINT_ORDER
        Compares two intervals by min endpoint.
      • MAX_ENDPOINT_ORDER

        public static final java.util.Comparator<Interval1D> MAX_ENDPOINT_ORDER
        Compares two intervals by max endpoint.
      • LENGTH_ORDER

        public static final java.util.Comparator<Interval1D> LENGTH_ORDER
        Compares two intervals by length.
    • Constructor Detail

      • Interval1D

        public Interval1D(double min,
                          double max)
        Initializes a closed interval [min, max].
        Parameters:
        min - the smaller endpoint
        max - the larger endpoint
        Throws:
        java.lang.IllegalArgumentException - if the min endpoint is greater than the max endpoint
        java.lang.IllegalArgumentException - if either min or max is Double.NaN, Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY
    • Method Detail

      • left

        @Deprecated
        public double left()
        Deprecated. Replaced by min().
        Returns the left endpoint of this interval.
        Returns:
        the left endpoint of this interval
      • right

        @Deprecated
        public double right()
        Deprecated. Replaced by max().
        Returns the right endpoint of this interval.
        Returns:
        the right endpoint of this interval
      • min

        public double min()
        Returns the min endpoint of this interval.
        Returns:
        the min endpoint of this interval
      • max

        public double max()
        Returns the max endpoint of this interval.
        Returns:
        the max endpoint of this interval
      • intersects

        public boolean intersects(Interval1D that)
        Returns true if this interval intersects the specified interval.
        Parameters:
        that - the other interval
        Returns:
        true if this interval intersects the argument interval; false otherwise
      • contains

        public boolean contains(double x)
        Returns true if this interval contains the specified value.
        Parameters:
        x - the value
        Returns:
        true if this interval contains the value x; false otherwise
      • length

        public double length()
        Returns the length of this interval.
        Returns:
        the length of this interval (max - min)
      • toString

        public java.lang.String toString()
        Returns a string representation of this interval.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this interval in the form [min, max]
      • equals

        public boolean equals(java.lang.Object other)
        Compares this transaction to the specified object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - the other interval
        Returns:
        true if this interval equals the other interval; false otherwise
      • hashCode

        public int hashCode()
        Returns an integer hash code for this interval.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        an integer hash code for this interval
      • main

        public static void main(java.lang.String[] args)
        Unit tests the Interval1D data type.
        Parameters:
        args - the command-line arguments

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.