|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.measure.LongitudeInterval
public class LongitudeInterval
An interval from one line of longitude to another.
This interval is half-open; it includes the starting point but does not include the ending point.
The motivation for this class is the desire to test, for example,
if a given point is between a longitude of 355 degrees and
10 degrees, which is different that testing if that point is
between 10 degrees and 355 degrees. Because there is a discontinuity
where once we reach the maximum longitude we proceed to the minimum,
we cannot use the typical range concept that allows us to test
whether a point is at or above a minimum and below a maximum, as
the example above shows. Instead, we need to know if a point
is on or after a starting point and before an
ending, where the starting point could be numerically
greater than the ending point. The TimeInterval
class
encapsulates the same concept for the time of day.
Version Info:
$Revision: 1707 $ |
$Date: 2008-11-14 10:23:59 -0700 (Fri, 14 Nov 2008) $ |
$Author: dharland $ (last person to modify) |
Constructor Summary | |
---|---|
LongitudeInterval()
Creates a new interval that encompasses the entire circle. |
|
LongitudeInterval(Longitude from,
Longitude to)
Creates a new interval using the given longitudes. |
Method Summary | |
---|---|
LongitudeInterval |
clone()
Returns a copy of this interval. |
boolean |
contains(Longitude longitude)
Returns true if longitude is contained in this interval. |
boolean |
equals(Object o)
Returns true if o is equal to this interval. |
Longitude |
getCenter()
Returns the longitude that is midway between the endpoints of this interval. |
Longitude |
getEnd()
Returns this interval's ending longitude. |
Angle |
getLength()
Returns the length of this this interval. |
Longitude |
getStart()
Returns this interval's starting longitude. |
int |
hashCode()
Returns a hash code value for this interval. |
static LongitudeInterval |
parse(String intervalText)
Creates a new longitude interval by parsing intervalText . |
static LongitudeInterval |
parse(String intervalText,
String endPointSeparator)
Creates a new longitude interval by parsing intervalText . |
void |
reset()
Resets this interval to its default state. |
void |
set(Longitude from,
Longitude to)
Sets the starting and ending points of this interval. |
void |
set(String intervalText)
Sets the endpoints of this interval based on intervalText . |
LongitudeInterval[] |
split(Longitude pointOfSplit)
Returns two new intervals that were formed by splitting this one at the given point. |
void |
switchEndpoints()
Exchanges the starting and ending points of this interval. |
LongitudeInterval |
toComplement()
Creates a new interval whose starting point is this interval's ending point and whose ending point is this interval's starting point. |
String |
toString()
Returns a string representation of this interval. |
String |
toString(String endPointSeparator)
Returns a string representation of this interval. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public LongitudeInterval()
public LongitudeInterval(Longitude from, Longitude to)
The description of the set(Longitude, Longitude)
method applies
to this constructor as well.
from
- the starting point of this interval. The starting
point is included in the interval.to
- the ending point of this interval. The ending
point is not included in the interval.Method Detail |
---|
public void reset()
A reset interval has the same state as one newly created by
the no-argument constructor
.
Specifically, it is an interval that encompasses a full circle.
public void set(Longitude from, Longitude to)
It is acceptable for the starting longitude to be
later than the ending longitude. The interval still
starts at from
; it is just that, in order to
reach to
, it must cross the "top" of the circle
(0, or 360, degrees).
If either parameter is null, an
IllegalArgumentException
will be thrown.
This class will maintain references to from
and
to
; it will not make copies. This means that
any changes made by clients to the parameter objects after
calling this method will be reflected in this object.
from
- the starting point of this interval. The starting
point is included in the interval.to
- the ending point of this interval. The ending
point is not included in the interval.public void set(String intervalText)
intervalText
.
If intervalText
is null or "" (the empty string),
the reset()
method is called. Otherwise, the parsing is
delegated to parse(String)
. See that method
for details related to parsing.
public void switchEndpoints()
public LongitudeInterval toComplement()
public LongitudeInterval[] split(Longitude pointOfSplit)
Scenario One. If this interval contains pointOfSplit
, then
the first interval in the array runs from this interval's starting point
to pointOfSplit
, and the second interval runs from
pointOfSplit
to this interval's ending point.
Scenario Two. If this interval does not contain
pointOfSplit
, then the first interval in the array will be equal
to this one, and the second interval will be a zero length interval whose
starting and ending endpoints are both pointOfSplit
.
pointOfSplit
- the point at which to split this interval in two.
public Longitude getStart()
The returned longitude, which is guaranteed to be non-null, is the actual longitude held by this interval, so changes made to it will be reflected in this object.
set(Longitude, Longitude)
public Longitude getEnd()
The returned longitude, which is guaranteed to be non-null, is the actual longitude held by this interval, so changes made to it will be reflected in this object.
set(Longitude, Longitude)
public Longitude getCenter()
Understand that while the returned value will always be between the endpoints (or coincident with them, if they are identical), the center may be numerically smaller than the starting point of this interval. For example, if this interval starts at 340 degrees and ends at 60 degrees, the length of this interval is 80 degrees, and the center is at 20 degrees, which is a smaller value than that of -- but is not "before" -- the starting point.
public Angle getLength()
public boolean contains(Longitude longitude)
longitude
is contained in this interval.
Note that this interval is half-open; it includes the starting point, but not the ending point.
longitude
- the longitude to be tested for containment.
longitude
is contained in this interval.public String toString()
FormatString.ENDPOINT_SEPARATOR
.
toString
in class Object
public String toString(String endPointSeparator)
toString
method in
Longitude
for information about how the endpoints
are formatted. The endPointSeparator
is used to
separate the two endpoints in the returned string.
endPointSeparator
- text that separates one endpoint from another
in the returned string. Using a null
or empty-string value here is a bad idea.
public static LongitudeInterval parse(String intervalText)
intervalText
.
This is a convenience method that is equivalent to:
parse(intervalText, FormatString.ENDPOINT_SEPARATOR);That is, the string separating the two endpoints is assumed to be
FormatString.ENDPOINT_SEPARATOR
.
intervalText
- the text to be parsed and converted into a longitude
interval. If this value is null or ""
(the empty string), a new interval of length zero is returned.
intervalText
.\
If intervalText
is null or ""
(the empty string), a new interval of length zero is returned.
IllegalArgumentException
- if intervalText
cannot be parsed.public static LongitudeInterval parse(String intervalText, String endPointSeparator)
intervalText
.
The general form of intervalText
is
StartTimeOfDaySeparatorEndTimeOfDay,
with the particulars of the longitude format described by
the Longitude.parse(String)
method of Longitude
.
intervalText
- the text to be parsed and converted into a longitude interval.
If this value is null or "" (the empty string),
a new interval of length zero is returned.endPointSeparator
- the text that separates the starting longitude
from the ending longitude in intervalText
.
intervalText
.
IllegalArgumentException
- if the combination intervalText
and endPointSeparator
cannot be parsed successfully.public LongitudeInterval clone()
If anything goes wrong during the cloning procedure,
a RuntimeException
will be thrown.
clone
in class Object
public boolean equals(Object o)
o
is equal to this interval.
equals
in class Object
public int hashCode()
hashCode
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |