Class Interval

java.lang.Object
xal.tools.math.Interval
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ClosedInterval, OpenInterval

public class Interval extends Object implements Serializable

Represents an interval on the real line. Intervals are identified by their end points, which may or may not be included depending upon whether the interval is open or closed. Nonetheless, we consider the left end the minimum value and the right end point the maximum value and refer to them as such.

Issues concerning boundary points are delegated to the derived classes.

Author:
Christopher K. Allen
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Interval
    The entire real line
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor - creates a new instance of Interval with one point, the origin.
    Interval(double min, double max)
    Initializing constructor - create an interval with specified endpoints
    Interval(Interval interval)
    Copy constructor - create a new open interval initialized to the argument.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    containsAE(Interval interval)
    Contains Almost Everywhere - ⊂ a.e.
    convexHull(Interval interval)
    Compute and return the smallest interval containing both this interval and the argument interval (i.e., the union of they are intersected).
    static Interval
    createFromEndpoints(double dblMin, double dblMax)
    Creates a new interval object according to the given endpoints.
    static Interval
    createFromMidpoint(double dblMidpt, double dblLng)
    Creates an interval object given the midpoint (centroid) of the interval and the length of the interval (which is the Lebesgue measure).
    boolean
    Are intervals equal
    double
    Get maximum value of interval.
    double
    Get minimum value of interval.
    int
     
    Compute and return the largest interval contained in this interval and the argument interval (i.e., the intersection).
    boolean
    intersects(Interval interval)
    Inspects for non-empty intersection with the given interval.
    boolean
    isBoundary(double x)
    Is point a boundary element?
    boolean
    Test if this interval represents the entire real line.
    double
    Compute the interval length.
    boolean
    membership(double x)
    Is point a member of this interval IR.
    double
    Compute the interval midpoint.
    void
    Print out contents on an output stream
    void
    Print out contents on an output stream, terminate in newline character
    void
    setMax(double max)
    Set the right end point
    void
    setMin(double min)
    Set the left end point
    Return the contents of the interval as a String.
    double[]
    Compute the local "vertex coordinates" of the argument x with respect to this interval IR.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • REAL_LINE

      public static final Interval REAL_LINE
      The entire real line
  • Constructor Details

    • Interval

      public Interval()
      Default constructor - creates a new instance of Interval with one point, the origin.
    • Interval

      public Interval(double min, double max) throws IllegalArgumentException
      Initializing constructor - create an interval with specified endpoints
      Parameters:
      min - left endpoint
      max - right endpoint
      Throws:
      IllegalArgumentException - max is smaller than min
    • Interval

      public Interval(Interval interval) throws MathException
      Copy constructor - create a new open interval initialized to the argument.
      Parameters:
      interval - interval to copy
      Throws:
      MathException - malformed interval to copy
  • Method Details

    • createFromMidpoint

      public static Interval createFromMidpoint(double dblMidpt, double dblLng)
      Creates an interval object given the midpoint (centroid) of the interval and the length of the interval (which is the Lebesgue measure). We do not throw an exception assuming that both arguments are positive.
      Parameters:
      dblMidpt - the center location of the interval
      dblLng - the length of the interval
      Returns:
      new interval object with endpoints producing the given center and length
      Since:
      Apr 28, 2011
    • createFromEndpoints

      public static Interval createFromEndpoints(double dblMin, double dblMax)
      Creates a new interval object according to the given endpoints. We do not throw an exception here, which would normally happen if the left-hand endpoint was larger than the right-hand endpoint. Instead we return a null value in this case.
      Parameters:
      dblMin - the left-hand endpoint
      dblMax - the right-hand endpoint
      Returns:
      the interval [dblMin,dblMax]
      Since:
      Apr 28, 2011
    • setMin

      public void setMin(double min)
      Set the left end point
      Parameters:
      min - interval left-hand side
    • setMax

      public void setMax(double max)
      Set the right end point
      Parameters:
      max - interval right-hand side
    • getMin

      public double getMin()
      Get minimum value of interval.
      Returns:
      the left end point
    • getMax

      public double getMax()
      Get maximum value of interval.
      Returns:
      the right end point
    • measure

      public double measure()
      Compute the interval length. This is the difference in endpoints.
      Returns:
      length of the interval
    • midpoint

      public double midpoint()
      Compute the interval midpoint. This is the average of the endpoints.
      Returns:
      interval center of mass
    • membership

      public boolean membership(double x)
      Is point a member of this interval IR. The test is done assuming I is closed, so the endpoints are included.
      Parameters:
      x - point to be tested as a member of this interval
      Returns:
      true if x ∈ I, false otherwise
    • equals

      public boolean equals(Object obj)
      Are intervals equal
      Overrides:
      equals in class Object
      Parameters:
      I - interval object to be checked for equality
      Returns:
      true if both objects are equal as intervals
    • hashCode

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

      public boolean isRealLine()
      Test if this interval represents the entire real line. Such an interval has the structure [Double.NEGATIVE_INFINITY,Double.POSITIVE_INFINITY]].
      Returns:
      true if this interval represents the entire real line, false otherwise
      Since:
      Sep 25, 2015 by Christopher K. Allen
    • intersects

      public boolean intersects(Interval interval)
      Inspects for non-empty intersection with the given interval. The interval is assumed closed.
      Parameters:
      interval - interval to inspect.
      Returns:
      true if thisI ≠ {}, false otherwise
      Since:
      Jun 2, 2009
    • containsAE

      public boolean containsAE(Interval interval)

      Contains Almost Everywhere - ⊂ a.e.

      Checks whether or not the given interval is a proper subset of this interval, modulo the endpoints. Specifically, I must be contained within this interval modulo the endpoints. We ignore the endpoints and, thus, the condition of whether or not either interval is closed or open.

      Parameters:
      interval - interval to be tested
      Returns:
      true if Ithis, false otherwise
      Since:
      Apr 28, 2011
    • isBoundary

      public boolean isBoundary(double x)
      Is point a boundary element?
      Parameters:
      x - point to be tested as boundary element
      Returns:
      true if x is a boundary element
    • vertexCoordinates

      public double[] vertexCoordinates(double x) throws MathException

      Compute the local "vertex coordinates" of the argument x with respect to this interval IR. These "local coordinates" {λ12} of a point xI can computed by solving the following linear equation for the {λi} :
       

      x1 x2  
      1 1
      λ1
      | λ2 |
      =
      x
      1

      where p = xR.

      NOTES:

      · After solving the above equation for the {λ12} if there is a λi such that λi ∉ [0,1], then x is not in T; that is, pT.

      Parameters:
      x - point in I
      Returns:
      order 2-array vertex coordinates {λ12}
      Throws:
      MathException - argument is not a member of this set
    • convexHull

      public Interval convexHull(Interval interval) throws MathException
      Compute and return the smallest interval containing both this interval and the argument interval (i.e., the union of they are intersected).
      Parameters:
      interval - right-hand-side argument
      Returns:
      union of this and I
      Throws:
      MathException - empty intersection
    • intersection

      public Interval intersection(Interval interval)
      Compute and return the largest interval contained in this interval and the argument interval (i.e., the intersection). If the intersection of the two intervals contains no points (i.e., it is the empty set), then a null value is returned. Since the empty is a valid result of intersection, this value should be considered in any robust implementation.
      Parameters:
      interval - interval to be intersected with this interval
      Returns:
      intersection of this and I, or null if the empty set {}
    • toString

      public String toString()
      Return the contents of the interval as a String. return string representation of interval
      Overrides:
      toString in class Object
      See Also:
    • print

      public void print(PrintWriter os)
      Print out contents on an output stream
      Parameters:
      os - output stream receiving content dump
    • println

      public void println(PrintWriter os)
      Print out contents on an output stream, terminate in newline character
      Parameters:
      os - output stream receiving content dump