net.degreedays.time
Class DayRange

java.lang.Object
  extended by net.degreedays.time.DayRange
All Implemented Interfaces:
java.io.Serializable

public final class DayRange
extends java.lang.Object
implements java.io.Serializable

Specifies a range of one or more days.

Instances of this class are immutable. You can safely reuse them and call them from multiple threads at once.


Constructor Summary
DayRange(Day first, Day last)
          Constructs a DayRange object that starts on the specified first day and ends on the specified last day.
 
Method Summary
 boolean contains(Day testDay)
          Returns true if the specified Day is fully contained within this DayRange; false otherwise.
 boolean contains(DayRange testRange)
          Returns true if the specified DayRange is contained within this DayRange; false otherwise.
 Day dayAt(int zeroBasedIndex)
          Returns the non-null Day at the specified zero-based index within this DayRange.
 int dayCount()
          Returns the number of days covered by this DayRange (always 1 or more).
 boolean equals(java.lang.Object o)
          Returns true if o is a DayRange covering exactly the same days as this DayRange; false otherwise.
 Day first()
          Returns the non-null first Day in this DayRange.
 MaybeEmptyDayRanges fullCalendarMonthsWithin()
           
 MaybeEmptyDayRanges fullCalendarYearsWithin()
           
 MaybeEmptyDayRanges fullMonthsWithin(StartOfMonth startOfMonth)
           
 DayRanges fullOrPartialCalendarMonthsWithin()
           
 DayRanges fullOrPartialCalendarYearsWithin()
           
 DayRanges fullOrPartialMonthsWithin(StartOfMonth startOfMonth)
           
 DayRanges fullOrPartialWeeksWithin(DayOfWeek firstDayOfWeek)
           
 DayRanges fullOrPartialYearsWithin(StartOfYear startOfYear)
           
 MaybeEmptyDayRanges fullWeeksWithin(DayOfWeek firstDayOfWeek)
           
 MaybeEmptyDayRanges fullYearsWithin(StartOfYear startOfYear)
           
 DayRange greedyUnion(Day dayToIncludeInUnion)
          Returns the non-null DayRange that includes all the days within this DayRange, the specified Day, and any days between.
 DayRange greedyUnion(DayRange rangeToIncludeInUnion)
          Returns the non-null DayRange that includes all the days within this DayRange, the specified DayRange, and any days between.
 int hashCode()
          Overridden to ensure consistency with equals.
 int indexOf(Day day)
          Returns the index of the specified Day within this DayRange, or -1 if it is not contained by this DayRange.
 DayRange intersectionOrNull(DayRange intersectWith)
          Returns a DayRange covering the days that are contained within both this DayRange and the specified DayRange, or null if there is no such intersection.
 Day last()
          Returns the non-null last Day in this DayRange.
 DayRanges toDailyDayRanges()
           
 java.lang.String toString()
          Returns a non-null, non-empty string representation of this object for logging and debugging purposes.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DayRange

public DayRange(Day first,
                Day last)
Constructs a DayRange object that starts on the specified first day and ends on the specified last day.

If first and last represent the same day, the range will cover that day only.

Parameters:
first - the first day that the DayRange should include. Cannot be null.
last - the last day that the DayRange should include. Cannot be null, and must be equal to or later than first.
Throws:
java.lang.NullPointerException - if first or last is null.
java.lang.IllegalArgumentException - if first is after last.
See Also:
Day.to(Day)
Method Detail

first

public Day first()
Returns the non-null first Day in this DayRange.


last

public Day last()
Returns the non-null last Day in this DayRange.


dayCount

public int dayCount()
Returns the number of days covered by this DayRange (always 1 or more).


dayAt

public Day dayAt(int zeroBasedIndex)
Returns the non-null Day at the specified zero-based index within this DayRange.

Parameters:
zeroBasedIndex - the index of the Day to return. Must be greater than or equal to zero and less than dayCount().
Returns:
the non-null Day at the specified index.
Throws:
java.lang.IndexOutOfBoundsException - if zeroBasedIndex is less than zero or greater than or equal to dayCount().
See Also:
indexOf(Day)

contains

public boolean contains(Day testDay)
Returns true if the specified Day is fully contained within this DayRange; false otherwise.

Parameters:
testDay - the Day to test for containment within this DayRange.
Returns:
true if testDay is equal to or after the first() day of this DayRange, and equal to or before the last() day of this DayRange; false otherwise.
Throws:
java.lang.NullPointerException - if testDay is null.

contains

public boolean contains(DayRange testRange)
Returns true if the specified DayRange is contained within this DayRange; false otherwise.

Parameters:
testRange - the DayRange to test for containment within this DayRange.
Returns:
true if the first day of testRange is equal to or after the first day of this DayRange, and the last day of testRange is equal to or before the last day of this DayRange; false otherwise.
Throws:
java.lang.NullPointerException - if testRange is null.

indexOf

public int indexOf(Day day)
Returns the index of the specified Day within this DayRange, or -1 if it is not contained by this DayRange.

Parameters:
day - the Day to return the index of.
Throws:
java.lang.NullPointerException - if day is null.
See Also:
dayAt(int)

intersectionOrNull

public DayRange intersectionOrNull(DayRange intersectWith)
Returns a DayRange covering the days that are contained within both this DayRange and the specified DayRange, or null if there is no such intersection.

By definition, a.intersectionOrNull(b) will always give the same result as b.intersectionOrNull(a), provided neither a nor b are null.

Parameters:
intersectWith - the other DayRange that the intersection should be calculated from (together with this DayRange). Cannot be null.
Throws:
java.lang.NullPointerException - if intersectWith is null.

greedyUnion

public DayRange greedyUnion(DayRange rangeToIncludeInUnion)
Returns the non-null DayRange that includes all the days within this DayRange, the specified DayRange, and any days between.

This method is "greedy" because, if there is a gap between this DayRange and rangeToIncludeInUnion, that gap will be included in the returned DayRange.

Parameters:
rangeToIncludeInUnion - the non-null DayRange that the returned DayRange should include (together with this DayRange and any days between).
Returns:
the DayRange that includes all the days within this DayRange, rangeToIncludeInUnion, and any days between.
Throws:
java.lang.NullPointerException - if rangeToIncludeInUnion is null.

greedyUnion

public DayRange greedyUnion(Day dayToIncludeInUnion)
Returns the non-null DayRange that includes all the days within this DayRange, the specified Day, and any days between.

This method is "greedy" because, if there is a gap between this DayRange and dayToIncludeInUnion, that gap will be included in the returned DayRange.

Parameters:
dayToIncludeInUnion - the non-null Day that the returned DayRange should include (together with this DayRange and any days between).
Returns:
the DayRange that includes all the days within this DayRange, dayToIncludeInUnion, and any days between.
Throws:
java.lang.NullPointerException - if dayToIncludeInUnion is null.

fullWeeksWithin

public MaybeEmptyDayRanges fullWeeksWithin(DayOfWeek firstDayOfWeek)

fullMonthsWithin

public MaybeEmptyDayRanges fullMonthsWithin(StartOfMonth startOfMonth)

fullCalendarMonthsWithin

public MaybeEmptyDayRanges fullCalendarMonthsWithin()

fullYearsWithin

public MaybeEmptyDayRanges fullYearsWithin(StartOfYear startOfYear)

fullCalendarYearsWithin

public MaybeEmptyDayRanges fullCalendarYearsWithin()

fullOrPartialWeeksWithin

public DayRanges fullOrPartialWeeksWithin(DayOfWeek firstDayOfWeek)

fullOrPartialMonthsWithin

public DayRanges fullOrPartialMonthsWithin(StartOfMonth startOfMonth)

fullOrPartialCalendarMonthsWithin

public DayRanges fullOrPartialCalendarMonthsWithin()

fullOrPartialYearsWithin

public DayRanges fullOrPartialYearsWithin(StartOfYear startOfYear)

fullOrPartialCalendarYearsWithin

public DayRanges fullOrPartialCalendarYearsWithin()

toDailyDayRanges

public DayRanges toDailyDayRanges()

equals

public boolean equals(java.lang.Object o)
Returns true if o is a DayRange covering exactly the same days as this DayRange; false otherwise.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overridden to ensure consistency with equals.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns a non-null, non-empty string representation of this object for logging and debugging purposes.

The exact details of the representation are unspecified and subject to change.

Overrides:
toString in class java.lang.Object


www.degreedays.net/api/