public abstract class MaybeEmptyDayRanges extends java.lang.Object implements java.lang.Iterable<DayRange>
DayRange objects.
If a MaybeEmptyDayRanges instance is not empty, you will be able
to cast it to the DayRanges subclass. If you are confident that a
particular MaybeEmptyDayRanges instance is not empty (either
because you checked isEmpty() or you know it's impossible for it to be
empty given the dates you used to create it), you can call the
notEmpty() method to get it as a DayRanges object.
This abstract class is not designed to be extended by third-party code, which is why it does not have an accessible constructor.
All concrete subclasses of this abstract class are immutable. You can safely reuse them and call them from multiple threads at once.
| Modifier and Type | Method and Description |
|---|---|
int |
count()
Returns the number of
DayRange objects in this set. |
boolean |
equals(java.lang.Object o)
Returns
true if o is a
MaybeEmptyDayRanges (or DayRanges) object
representing the same set of DayRange objects as
this; false otherwise. |
DayRange |
fullRangeOrNull()
Returns the
DayRange extending from the first day of the
first DayRange to the last day of the last
DayRange in this chronologically-ordered set, or
null if isEmpty() returns true. |
DayRange |
get(int index)
Returns the
DayRange at the specified position in this
chronologically-ordered set. |
static MaybeEmptyDayRanges |
getEmpty()
Returns an empty
MaybeEmptyDayRanges object - definitely
empty in this case, not just maybe! |
int |
hashCode()
Overridden to ensure consistency with
equals. |
int |
indexOf(Day day)
Returns the index of the
DayRange that contains
day, or -1 if no such DayRange
exists in this chronologically-ordered set. |
int |
indexOf(DayRange dayRange)
Returns the index of the specified
DayRange in this
chronologically-ordered set, or -1 if it is not present. |
boolean |
isEmpty()
|
java.util.Iterator<DayRange> |
iterator() |
DayRanges |
notEmpty()
Returns this
MaybeEmptyDayRanges object as a
DayRanges object, which cannot be empty. |
MaybeEmptyDayRanges |
subRanges(int fromIndexInclusive,
int toIndexExclusive)
Returns a
MaybeEmptyDayRanges (which will be a
DayRanges if it isn't empty) containing the DayRange
objects between the specified indexes in this chronologically-ordered
set. |
MaybeEmptyDayRanges |
subRangesWithin(DayRange dayRange)
Returns a
MaybeEmptyDayRanges (which will be a
DayRanges if it isn't empty) containing any DayRange
objects from this set that are fully contained within the specified
DayRange. |
java.lang.String |
toString()
Returns a non-null, non-empty string representation of this object for logging and debugging purposes.
|
public final DayRange fullRangeOrNull()
DayRange extending from the first day of the
first DayRange to the last day of the last
DayRange in this chronologically-ordered set, or
null if isEmpty() returns true.public final boolean isEmpty()
public final DayRanges notEmpty() throws java.lang.IllegalStateException
MaybeEmptyDayRanges object as a
DayRanges object, which cannot be empty. Call this after
checking isEmpty() or if you know from the dates you created this
with that this cannot be empty.
This is effectively a quick way to cast a
MaybeEmptyDayRanges object (which can be empty) to a
DayRanges object (which can't be empty).
java.lang.IllegalStateException - if isEmpty() returns
true.public final int count()
DayRange objects in this set.public final DayRange get(int index)
DayRange at the specified position in this
chronologically-ordered set.index - the index of the DayRange object to return.java.lang.IndexOutOfBoundsException - if index is less than zero
or greater than or equal to count().public final java.util.Iterator<DayRange> iterator()
iterator in interface java.lang.Iterable<DayRange>public final int indexOf(DayRange dayRange)
DayRange in this
chronologically-ordered set, or -1 if it is not present.
This checks for dayRange using DayRange.equals(java.lang.Object), so
dayRange does not have to be the same instance as a
DayRange contained within this chronologically-ordered set,
it just has to be equal to one (i.e. cover the exact same dates).
dayRange - the DayRange to search for. Cannot be
null.java.lang.NullPointerException - if dayRange is
null.public final int indexOf(Day day)
DayRange that contains
day, or -1 if no such DayRange
exists in this chronologically-ordered set.java.lang.NullPointerException - if day is null.public final MaybeEmptyDayRanges subRanges(int fromIndexInclusive, int toIndexExclusive)
MaybeEmptyDayRanges (which will be a
DayRanges if it isn't empty) containing the DayRange
objects between the specified indexes in this chronologically-ordered
set.
If you are confident that your toIndexExclusive is greater
than your fromIndexInclusive, you can call notEmpty()
on the returned MaybeEmptyDayRanges to cast it to
DayRanges.
java.lang.IndexOutOfBoundsException - for an illegal index value (fromIndexInclusive < 0 || toIndexExclusive > count() ||
fromIndexInclusive > toIndexExclusive)public final MaybeEmptyDayRanges subRangesWithin(DayRange dayRange)
MaybeEmptyDayRanges (which will be a
DayRanges if it isn't empty) containing any DayRange
objects from this set that are fully contained within the specified
DayRange.dayRange - specifying the date range you want results for.java.lang.NullPointerException - if dayRange is
null.public final boolean equals(java.lang.Object o)
true if o is a
MaybeEmptyDayRanges (or DayRanges) object
representing the same set of DayRange objects as
this; false otherwise.equals in class java.lang.Objectpublic final int hashCode()
equals.hashCode in class java.lang.Objectpublic final java.lang.String toString()
The exact details of the representation are unspecified and subject to change.
toString in class java.lang.Objectpublic static MaybeEmptyDayRanges getEmpty()
MaybeEmptyDayRanges object - definitely
empty in this case, not just maybe!
See www.degreedays.net/api/ for more about the Degree Days.net API.
You can sign up for a Degree Days.net API account and read the integration guide that is useful and applicable whether you are using Java or not.