|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--corina.Range
This class represents a range of years which can be redated safely.
It's immutable; all destructive operations on it return new Ranges.
Unfortunately, this data structure violates single-instance
storage: we hope that the usage of Range and Sample will always
keep Sample.data.size() == Range.span()
, but there
aren't any built-in ways to do this, so it's up to you. The
problem is that end
is a duplicate of
Sample.data.size() + start
.
Year
,
Sample
Constructor Summary | |
Range()
Construct a new empty range, starting at Year.DEFAULT . |
|
Range(String s)
Construct a range from a String. |
|
Range(Year y,
int span)
Construct a range, given a starting year and span. |
|
Range(Year y1,
Year y2)
Construct a new range, from y1 to y2. |
Method Summary | |
int |
compareTo(Object o)
Compares this and o, for placing in fallback order. |
boolean |
contains(Year y)
Return true if (and only if) the given year is inside the range, inclusive. |
boolean |
endOfRow(Year y)
Is this year the end of a row? |
boolean |
equals(Object o)
Compare two ranges for equality. |
Year |
getEnd()
Get the ending year of this range. |
Year |
getStart()
Get the starting year of this range. |
Range |
intersection(Range r)
The intersection of this range with r. |
int |
overlap(Range r)
Return the number of years overlap between this range and the given range. |
Range |
redateBy(int dy)
Redate a range by a certain number of years. |
Range |
redateEndTo(Year y)
Set the ending year of the range, and adjust the start year to maintain the same length. |
Range |
redateStartTo(Year y)
Set the starting year of the range, and adjust the ending year to maintain the same length. |
int |
rows()
Compute the number of rows this Range will take to display, assuming rows are marked off as the row() method does. |
int |
span()
Return the number of years spanned by this range. |
boolean |
startOfRow(Year y)
Is this year the start of a row? (Year 1 is considered the start of that row.) |
String |
toString()
Return a simple string representation of the range, like "1001 - 1036". |
String |
toStringWithSpan()
Return a string representation of the range, including the span, like "(1001 - 1036, n=36)". |
Range |
union(Range r)
The union of this range with r. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Range()
Year.DEFAULT
.Year
public Range(Year y1, Year y2)
null
.) If y2 < y1,
it is an empty interval.y1
- starting yeary2
- ending yearpublic Range(Year y, int span)
y
- the starting yearspan
- the number of yearspublic Range(String s)
s
- the StringMethod Detail |
public Year getStart()
public Year getEnd()
public Range redateStartTo(Year y)
y
- new starting year for the rangeredateEndTo(corina.Year)
public Range redateBy(int dy)
dy
- the number of years to shift this range bypublic Range redateEndTo(Year y)
y
- new ending year for the rangeredateStartTo(corina.Year)
public int span()
public int rows()
public String toString()
toString
in class Object
public String toStringWithSpan()
public boolean contains(Year y)
y
- year to checky
is in the range, else falsepublic boolean startOfRow(Year y)
public boolean endOfRow(Year y)
public int overlap(Range r)
r
- range to comparepublic Range intersection(Range r)
r
- the range to intersect with this rangepublic Range union(Range r)
r
- the range to union with this rangepublic boolean equals(Object o)
equals
in class Object
r
- range to compare with thispublic int compareTo(Object o)
compareTo
in interface Comparable
o
- Object to compareClassCastException
- if o is not a Range
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |