Class Interval
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ClosedInterval,OpenInterval
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsAE(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 IntervalcreateFromEndpoints(double dblMin, double dblMax) Creates a new interval object according to the given endpoints.static IntervalcreateFromMidpoint(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).booleanAre intervals equaldoublegetMax()Get maximum value of interval.doublegetMin()Get minimum value of interval.inthashCode()intersection(Interval interval) Compute and return the largest interval contained in this interval and the argument interval (i.e., the intersection).booleanintersects(Interval interval) Inspects for non-empty intersection with the given interval.booleanisBoundary(double x) Is point a boundary element?booleanTest if this interval represents the entire real line.doublemeasure()Compute the interval length.booleanmembership(double x) Is point a member of this interval I ⊂ R.doublemidpoint()Compute the interval midpoint.voidprint(PrintWriter os) Print out contents on an output streamvoidprintln(PrintWriter os) Print out contents on an output stream, terminate in newline charactervoidsetMax(double max) Set the right end pointvoidsetMin(double min) Set the left end pointtoString()Return the contents of the interval as aString.double[]vertexCoordinates(double x) Compute the local "vertex coordinates" of the argument x with respect to this interval I ⊂ R.
-
Field Details
-
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
Initializing constructor - create an interval with specified endpoints- Parameters:
min- left endpointmax- right endpoint- Throws:
IllegalArgumentException- max is smaller than min
-
Interval
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
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 intervaldblLng- the length of the interval- Returns:
- new interval object with endpoints producing the given center and length
- Since:
- Apr 28, 2011
-
createFromEndpoints
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 anullvalue in this case.- Parameters:
dblMin- the left-hand endpointdblMax- 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 I ⊂ R. 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
Are intervals equal -
hashCode
public int hashCode() -
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:
trueif this interval represents the entire real line,falseotherwise- Since:
- Sep 25, 2015 by Christopher K. Allen
-
intersects
Inspects for non-empty intersection with the given interval. The interval is assumed closed.- Parameters:
interval- interval to inspect.- Returns:
- true if this ∩ I ≠ {}, false otherwise
- Since:
- Jun 2, 2009
-
containsAE
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:
trueif I ⊂this,falseotherwise- 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
Compute the local "vertex coordinates" of the argument x with respect to this interval I ⊂ R. These "local coordinates" {λ1,λ2} of a point x ∈ I can computed by solving the following linear equation for the {λi} :
where p = x ∈ R.⌈ x1 x2 ⌉ ⌊ 1 1 ⌋ ⌈ λ1 ⌉ | λ2 | = ⌈ x ⌉ ⌊ 1 ⌋ NOTES:
· After solving the above equation for the {λ1,λ2} if there is a λi such that λi ∉ [0,1], then x is not in T; that is, p∉ T.- Parameters:
x- point in I- Returns:
- order 2-array vertex coordinates {λ1,λ2}
- Throws:
MathException- argument is not a member of this set
-
convexHull
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
thisandI - Throws:
MathException- empty intersection
-
intersection
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 anullvalue 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 withthisinterval- Returns:
- intersection of
thisandI, ornullif the empty set {}
-
toString
Return the contents of the interval as aString. return string representation of interval -
print
Print out contents on an output stream- Parameters:
os- output stream receiving content dump
-
println
Print out contents on an output stream, terminate in newline character- Parameters:
os- output stream receiving content dump
-