com.miginfocom.util.dates
Class DateRange

java.lang.Object
  extended by com.miginfocom.util.dates.DateRange
All Implemented Interfaces:
DateRangeI, MutableDateRange, TimeSpan, PropertyObservable, java.io.Serializable, java.lang.Comparable

public class DateRange
extends java.lang.Object
implements MutableDateRange

Default implementation of a MutableDateRange.

See Also:
DateRangeI, Serialized Form

Field Summary
 
Fields inherited from interface com.miginfocom.util.dates.MutableDateRange
ALIGN_CENTER_DOWN, ALIGN_CENTER_DOWN_NVP, ALIGN_CENTER_UP, ALIGN_CENTER_UP_NVP, ALIGN_EARLIEST, ALIGN_EARLIEST_NVP, ALIGN_END, ALIGN_END_NVP, ALIGN_LATEST, ALIGN_LATEST_NVP, ALIGN_START, ALIGN_START_NVP, ALIGN_VNPS, PROPERTY_NAME
 
Fields inherited from interface com.miginfocom.util.dates.DateRangeI
CUSTOM_NVP, DATE_RANGE_NAMES, DATE_RANGES, DATE_RANGES_CUSTOM, DATE_RANGES_FROM_DAY, DAY_NVP, HOUR_NVP, MINUTE_NVP, MONTH_NVP, RANGE_TYPE_CUSTOM, RANGE_TYPE_DAY, RANGE_TYPE_HOUR, RANGE_TYPE_MINUTE, RANGE_TYPE_MONTH, RANGE_TYPE_OFFSET, RANGE_TYPE_SECOND, RANGE_TYPE_WEEK, RANGE_TYPE_YEAR_MONTHS, RANGE_TYPE_YEAR_WEEKS, RANGE_TYPES_MILLIS, SECOND_NVP, WEEK_NVP, YEAR_MONTHS_NVP, YEAR_WEEKS_NVP
 
Constructor Summary
DateRange()
          Constructor for a single date with the current time.
DateRange(java.util.Calendar cal, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructs a range that simulates a singe point in time.
DateRange(java.util.Date start, java.util.Date end, boolean endIsExcluding, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructor.
DateRange(DateRangeI dateRange)
          Constructs a range that has the same range as dateRange.
DateRange(DateRangeI dateRange1, DateRangeI dateRange2)
          Sets the date range to the maximum date span possible with the two ranges start and end dates.
DateRange(long date, int boundaryType, int size, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructs a range and set it to a boundary to the first and last millisecond of a boundary.
DateRange(long start, long end, boolean endIsExcluding, int boundaryType, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructs a range and set it to a boundary to the first and last millisecond of a boundary.
DateRange(long start, long end, boolean endIsExcluding, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructor.
DateRange(long start, long end, java.util.TimeZone timeZone, java.util.Locale locale, boolean hasDate, boolean hasTime)
          Constructor.This is mostly to recreatr the object with a PersistenceDelegate.
DateRange(long millis, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructor.
 
Method Summary
 MutableDateRange add(int field, long amount, boolean preserveLength, boolean lengthDSTSafe)
          Directly passed on to start and end Calendars without any intervention
 void add(int field, long delta, boolean start, boolean end, DateRangeRounder dateRangeRounder)
          Add/move the start and/or end time of this range.
 void addEnd(int field, long amount)
          Forwarded to Calendar.add(int, int) for the end date.
 void addMillis(long amount)
          Adds amount number of milliseconds to both start and end date.
 void addMillisDSTSafe(long amount)
          Adds amount number of milliseconds to both start and end date.
 void addPropertyListener(java.beans.PropertyChangeListener l)
          Adds a listener that should be notified of all changes that to the property values of this com.miginfocom.theme.
This is usually just implemented as addPropertyListener(l, false)
 void addPropertyListener(java.beans.PropertyChangeListener l, boolean asWeakRef)
          Adds a listener that should be notified of all changes that to the property values of this com.miginfocom.theme
 MutableDateRange addRange(DateRangeI range)
          Adds range to this range.
 void addStart(int field, long amount)
          Forwarded to Calendar.add(int, int)
 void allowEvents()
          Decreases the postpone count and if it reaches 0 an event is fired automatically.
Throws an IllegalStateException if the postpone count is alread at 0 and the date range has actually changed.
 DateRangeI cloneRange()
           
 int compareTo(java.lang.Object o)
          Compares startdates, and if they are the same, end dates.
 MutableDateRange cut(DateRangeI maxBounds)
          Cuts of the start and/or end dates to the start or end dates in maxBounds if maxBounds is "inside" or this date range.
Note that if maxBounds doesn't overlap this then the resulting range (this) will span no time and probably be unsorted.
 boolean equals(java.lang.Object o)
          Returns true if obj is != null, is an instance of DateRangeI and represents date range with the same start and end millisecond.
 MutableDateRange expandRange(int field, int amount)
          Expands the range by adding and substracting the amount to field for end and start date, respectively.
protected  boolean firePropertyChangeEvent(boolean testForEq)
           
 MutableDateRange getDateRangeClone()
          Returns the date range that the object spans as a clone which is safe to change without chaning the original time span.
 DateRangeI getDateRangeForReading()
          Returns the date range that the object spans.
 java.lang.String getDurationString(java.lang.String formatString)
          Calls DateUtil.getDurationString(java.util.Calendar, java.util.Calendar, boolean, String) for the start and end dates and returns the result.
 java.util.Calendar getEnd()
          This is simply short for: getEnd(false), which means it will typically have milliseconds set to 999.
 java.util.Calendar getEnd(boolean excluding)
          Returns the actual contained Calendar.
 int getEndField(int field)
          This is simply short for: getEndField(field, false), which means it will typically have milliseconds set to 999.
 int getEndField(int field, boolean excluding)
          Forwarded to Calendar#get.
 ImmutableDateRange getEndInstant()
          This is simply short for: getEndInstant(false), which means it will typically have milliseconds set to 999.
 ImmutableDateRange getEndInstant(boolean excluding)
          Returns an ImmutableDateRange representing the end of this date range.
 long getEndMillis()
          This is simply short for: getEndMillis(false), which means it will typically have milliseconds set to 999.
 long getEndMillis(boolean excluding)
          Returns the end date in milliseconds.
 java.util.Date getEndTime()
          This is simply short for: getEndTime(false), which means it will typically have milliseconds set to 999.
 java.util.Date getEndTime(boolean excluding)
          Returns a new Date object representing the end time
 boolean getHasDate()
          A simple settable property that does nothing for the contained values or calculations.
 boolean getHasTime()
          A simple settable property that does nothing for the contained values or calculations.
 ImmutableDateRange getImmutable()
          Returns the range as a true immutable date range.
 java.util.Locale getLocale()
          Returns the locale associated with this time zone or null if the default should be used.
 java.util.Calendar getMiddle()
          Calulates the time in the middle of 'startDate' and 'endDate'.
 long getMiddleMillis()
          Calulates the time in the middle of 'startDate' and 'endDate'.
 long getMillisSpanned(boolean dSTSafe, boolean excluding)
          Returns the number of milliseconds this range spans.
 int getRangeType()
          Returns the type of range that this DataSpan spans.
 java.util.Calendar getRelative(double perc)
          Returns a date that are perc percent into the range.
 long getRelativeMillis(double perc)
          Returns a date that are perc percent into the range.
 DateRangeI getRelativeRange(double startPerc, double endPerc)
          Returns a date range that start from startPerc percent into the range until endPerc into the range.
 int getSize(int rangeType, boolean dstSafe)
          Returns the number of seconds, minutes, hours, days, weeks, months or years betwen start and end date, inclusive.
 java.util.Calendar getStart()
          Returns a clone of the start date, free to change and it wont affect the range.
 int getStartField(int field)
          Forwarded to Calendar#get.
 ImmutableDateRange getStartInstant()
          Returns an ImmutableDateRange representing the start of this date range.
 long getStartMillis()
          Returns the start date in milliseconds.
 java.util.Date getStartTime()
          Returns a new Date object representing the start time
 java.util.ArrayList getSubDateList(int field, int[] values, int occurField, int[] dayOfWeekOccur, int maxCount, boolean asRanges)
          Runs an iterator over the range with sizes field and returns all date/times that's inside this range and which have a field value that is one of the integers in values.
 java.util.TimeZone getTimeZone()
          Returns the time zone associated with this time zone or null if the default should be used.
 MutableDateRange getWritableDateRange()
          Returns the contained date range for editing.
 int hashCode()
           
 boolean isContaining(DateRangeI innerRange)
          Checks if a 'innerDateSpan' is compleately inside or equal to this range.
 boolean isContaining(long timeInMillis, boolean disregardSorting)
          Returns if the millisecond is within the range, inclusive.
 boolean isContinuous(DateRangeI range)
          Checks if dateRange overlaps (or touches) this date range or if they are next to eachother so that there are no time between them and they thus form a continuous date range.
 boolean isIgnorePropertyEvents()
          Returns if the PropertyObservable is currently ignoring change events.
 boolean isInSame(int rangeType)
          Returns if cal1 and cal2 is in the same range type.
 boolean isOverlapping(DateRangeI range)
          Checks if dateRange overlaps (or touches) this date range.
 boolean isOverlapping(DateRangeI range, DateRangeI withinRange)
          Checks if dateRange overlaps (or touches) this date range.
 boolean isSorted()
          Returns if startDate is before (or same) as endDate (to the millisecond)
 boolean isSpanningTime()
          Returns if start date is not same as end date.
 java.util.Iterator iterator(int boundaryType)
          Returns an iterator that iterates over the range, returning a new DateRangeI for every call to .next().
 java.util.Iterator iterator(int boundaryType, int amount)
          Returns an iterator that iterates over the range, returning a new DateRangeI for every call to .next().
 MutableDateRange move(int field, long amount, int boundaryType)
          Adds/moves the range by using a "middle point add and expand" algorithm.
 void postponeEvents()
          Increase the postpone count.
 void removePropertyListener(java.beans.PropertyChangeListener l)
          Removes a listener if it is in the list.
 void roll(int field, int amount)
          Directly passed on to start and end Calendars without any intervention
 MutableDateRange roundExpand(int boundaryType)
          Sets the start and end date to the first and last millisecond of a specific boundary by expanding the range.
 MutableDateRange roundReduce(int boundaryType)
          Sets the start and end date to the first and last millisecond of a specific boundary by reducing the range.
 MutableDateRange setDateFromRange(DateRangeI dateRange)
          Copies date (yeas, day of year) from dateRange's start and end date and sets in this's start and end date making the date of day match but not necessary the time.
 void setEnd(java.util.Calendar date, boolean excluding)
           
 void setEndField(int field, int value)
          Forwarded to Calendar.set(int, int) for the end date.
 void setEndMillis(long millis, boolean excluding)
          Sets the milliseconds of the end date directly
 void setEndToBoundaryExpand(int boundaryType)
          Sets the end date/time to boundaryType by expanding it to that boundary.
 void setEndToBoundaryReduce(int boundaryType)
          Sets the end date/time to boundaryType by reducing it to that boundary.
 void setHasDate(boolean b)
          A simple settable property that does nothing for the contained values or calculations.
 void setHasTime(boolean b)
          A simple settable property that does nothing for the contained values or calculations.
 boolean setIgnorePropertyEvents(boolean b)
          Sets if ChangeEvent's should be fired.
 void setMillisSpanned(long millis, boolean dSTSafe, boolean excluding)
          Changes end date so the total duration becomes millis.
 MutableDateRange setSize(int boundaryType, int size, AtRefRangeNumber align)
          Resizes the range to a specified number of a certain type (e.g.
 MutableDateRange setSize(int boundaryType, int size, int align)
          Resizes the range to a specified number of a certain type (e.g.
 void setStart(java.util.Calendar date)
           
 void setStartField(int field, int value)
          Forwarded to Calendar.set(int, int) for the start field
 void setStartMillis(long millis)
          Sets the milliseconds of the start date directly
 void setStartToBoundaryExpand(int boundaryType)
          Sets the start date/time to boundaryType by expanding it to that boundary.
 void setStartToBoundaryReduce(int boundaryType)
          Sets the start date/time to boundaryType by reducing it to that boundary.
 MutableDateRange setTimeFromRange(DateRangeI dateRange)
          Copies time (hour, min, sec, millis) from dateRange's start and end date and sets in this's start and end date making the time of day match but not necessary the date.
 MutableDateRange setToRange(DateRangeI dateRange)
          Sets this range to the same start and end date/time as dateRange.
 MutableDateRange sort()
          Sorts this range by swapping start and end date references if needed.
 MutableDateRange sort(boolean b)
          Sorts or unsorts this range by swapping start and end date references if needed.
 java.lang.String toString()
           
 java.lang.String toString(java.lang.String formatString, boolean endIsExcluding, boolean includeOffset)
          Retuns a string representation of the date range.
 MutableDateRange union(DateRangeI range)
          Sets this range so that it's start date is the earliest of the two and the end date is the latest of the two.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateRange

public DateRange()
Constructor for a single date with the current time. Default locale and time zone


DateRange

public DateRange(long millis,
                 java.util.TimeZone timeZone,
                 java.util.Locale locale)
Constructor.

Parameters:
millis - The date/time in milliseconds that should be the start and end for this date range are an even number (0).
timeZone - The time zone or null for default. Please see the tutorial for information about time zones.
locale - The locale or null for default.

DateRange

public DateRange(java.util.Date start,
                 java.util.Date end,
                 boolean endIsExcluding,
                 java.util.TimeZone timeZone,
                 java.util.Locale locale)
Constructor.

Parameters:
start - The start date/time
end - The end date/time. Can be same object as start to simulate a single point in time.
endIsExcluding - Set to true if the end date is 'excluding' the last millisecond, normally meaning that the milliseconds are are an even number (0).
timeZone - The time zone or null for default. Please see the tutorial for information about time zones.
locale - The locale or null for default.

DateRange

public DateRange(java.util.Calendar cal,
                 java.util.TimeZone timeZone,
                 java.util.Locale locale)
Constructs a range that simulates a singe point in time. It actually spans 1 millisecond since both start and end date are considered inclusive.
Same as new DateRange(date, date, false);

Parameters:
cal - The start and end date. Object is cloned. Not null.
timeZone - The time zone or null for default. Please see the tutorial for information about time zones.
locale - The locale or null for default.

DateRange

public DateRange(long start,
                 long end,
                 boolean endIsExcluding,
                 java.util.TimeZone timeZone,
                 java.util.Locale locale)
Constructor.

Parameters:
start - The start date/time in milliseconds.
end - The end date/time in milliseconds.
endIsExcluding - Set to true if the end date is 'excluding' the last millisecond, normally meaning that the milliseconds are are an even number (0).
timeZone - The time zone or null for default. Please see the tutorial for information about time zones.
locale - The locale or null for default.

DateRange

public DateRange(DateRangeI dateRange)
Constructs a range that has the same range as dateRange. Makes a defensive copy of the sent in date range. The new range will have the same immutable state.

Parameters:
dateRange - The AtStart and end date. Object is cloned for storing. Not null

DateRange

public DateRange(long start,
                 long end,
                 boolean endIsExcluding,
                 int boundaryType,
                 java.util.TimeZone timeZone,
                 java.util.Locale locale)
Constructs a range and set it to a boundary to the first and last millisecond of a boundary.

Parameters:
start - AtStart date. Object is cloned for storing. Not null
end - AtEnd date. Object is cloned for storing. Not null
boundaryType - Both dates will be changed to the start/end boundary indicated by 'boundaryType'. It can be one of: RANGE_TYPE_SECOND Set the dates to seconds's boundaries
RANGE_TYPE_MINUTE Set the dates to minutes's boundaries
RANGE_TYPE_HOUR Set the dates to hous's boundaries
RANGE_TYPE_DAY Set the dates to day's boundaries
RANGE_TYPE_WEEK Set the dates to a week's boundaries
RANGE_TYPE_MONTH Set the dates to a month's boundaries
RANGE_TYPE_YEAR_MONTHS Set the dates to a year's boundaries. Jan 1 to Dec 31.
RANGE_TYPE_YEAR_WEEKS Set the dates to a yearäs boundaries. Week 01 to week 52/53
endIsExcluding - Set to true if the end date is 'excluding' the last millisecond, normally meaning that the milliseconds are are an even number (0).
timeZone - The time zone or null for default. Please see the tutorial for information about time zones.
locale - The locale or null for default.
See Also:
roundExpand(int)

DateRange

public DateRange(long date,
                 int boundaryType,
                 int size,
                 java.util.TimeZone timeZone,
                 java.util.Locale locale)
Constructs a range and set it to a boundary to the first and last millisecond of a boundary.

Note that the range is set around date with equal amount of time before and after it,

Parameters:
date - The startDate that will be set to the given boundary. endDate will be cloned from this object and set to the given boundary. Object is cloned for storing. Not null
boundaryType - Both dates will be changed to the start/end boundary indicated by 'boundaryType'. It can be one of: RANGE_TYPE_SECOND Set the dates to seconds's boundaries
RANGE_TYPE_MINUTE Set the dates to minutes's boundaries
RANGE_TYPE_HOUR Set the dates to hous's boundaries
RANGE_TYPE_DAY Set the dates to day's boundaries
RANGE_TYPE_WEEK Set the dates to a week's boundaries
RANGE_TYPE_MONTH Set the dates to a month's boundaries
RANGE_TYPE_YEAR_MONTHS Set the dates to a year's boundaries. Jan 1 to Dec 31.
RANGE_TYPE_YEAR_WEEKS Set the dates to a year's boundaries. Week 01 to week 52/53
size - The number of boundaryType to span. Must be > 0.
timeZone - The time zone or null for default. Please see the tutorial for information about time zones.
locale - The locale or null for default.
See Also:
roundExpand(int), setSize(int, int, int)

DateRange

public DateRange(DateRangeI dateRange1,
                 DateRangeI dateRange2)
Sets the date range to the maximum date span possible with the two ranges start and end dates. They don't have to be sorted. One of the ranges can be null but not both.

Time Zone/Locale will be taken from dateRange1 if not null in which case it will be taken from dateRange2. The resulting date range (this) will always be sorted.

Parameters:
dateRange1 - Date range 1. May be null if dateRange2 is not.
dateRange2 - Date range 2. May be null if dateRange1 is not.

DateRange

public DateRange(long start,
                 long end,
                 java.util.TimeZone timeZone,
                 java.util.Locale locale,
                 boolean hasDate,
                 boolean hasTime)
Constructor.This is mostly to recreatr the object with a PersistenceDelegate.

Parameters:
start - The start date/time in milliseconds.
end - The end date/time in milliseconds. Excluding!
timeZone - The time zone or null for default. Please see the tutorial for information about time zones.
locale - The locale or null for default.
hasDate - If the date in this date range is relevant. Only as inpormation, doesn't affect calculations.
hasTime - If the time in this date range is relevant. Only as inpormation, doesn't affect calculations.
Method Detail

getTimeZone

public java.util.TimeZone getTimeZone()
Description copied from interface: DateRangeI
Returns the time zone associated with this time zone or null if the default should be used.

Specified by:
getTimeZone in interface DateRangeI
Returns:
The time zone associated with this time zone or null if the default should be used.

getLocale

public java.util.Locale getLocale()
Description copied from interface: DateRangeI
Returns the locale associated with this time zone or null if the default should be used.

Specified by:
getLocale in interface DateRangeI
Returns:
The locale associated with this time zone or null if the default should be used.

getHasDate

public boolean getHasDate()
Description copied from interface: DateRangeI
A simple settable property that does nothing for the contained values or calculations. It is just a "tag"-boolean that can be interpreted by users of this class.

Specified by:
getHasDate in interface DateRangeI
Returns:
If the range's date should be considered. Default is true.

setHasDate

public void setHasDate(boolean b)
Description copied from interface: MutableDateRange
A simple settable property that does nothing for the contained values or calculations. It is just a "tag"-boolean that can be interpreted by users of this class. Will NOT fire a property change event.

Specified by:
setHasDate in interface MutableDateRange
Parameters:
b - If the range's date should be considered. Default is true.

getHasTime

public boolean getHasTime()
Description copied from interface: DateRangeI
A simple settable property that does nothing for the contained values or calculations. It is just a "tag"-boolean that can be interpreted by users of this class.

Specified by:
getHasTime in interface DateRangeI
Returns:
If the range's date should be considered. Default is true.

setHasTime

public void setHasTime(boolean b)
Description copied from interface: MutableDateRange
A simple settable property that does nothing for the contained values or calculations. It is just a "tag"-boolean that can be interpreted by users of this class. Will NOT fire a property change event.

Specified by:
setHasTime in interface MutableDateRange
Parameters:
b - If the range's date should be considered. Default is true.

getDateRangeClone

public MutableDateRange getDateRangeClone()
Description copied from interface: TimeSpan
Returns the date range that the object spans as a clone which is safe to change without chaning the original time span. If the range is only to be read from use TimeSpan.getDateRangeForReading() instead to avoid unnecessary object cloning.

Specified by:
getDateRangeClone in interface TimeSpan
Returns:
Returns the date range that the object spans.

getDateRangeForReading

public DateRangeI getDateRangeForReading()
Description copied from interface: TimeSpan
Returns the date range that the object spans. If the object contains an immutable date range or a range that must not be changed that is returned here. In order to get a truly immutable date range that will not change call DateRangeI.getImmutable() on the returned range. The contract is to not change the returned date range.

Specified by:
getDateRangeForReading in interface TimeSpan
Returns:
Returns the date range that the object spans.

getWritableDateRange

public MutableDateRange getWritableDateRange()
Description copied from interface: TimeSpan
Returns the contained date range for editing. If the local date range isn't allowed to be edited an UnsupportedOperationException should be thrown.

Specified by:
getWritableDateRange in interface TimeSpan
Returns:
The contained date range for editing.

getImmutable

public ImmutableDateRange getImmutable()
Description copied from interface: DateRangeI
Returns the range as a true immutable date range.

Specified by:
getImmutable in interface DateRangeI
Returns:
The range as a true immutable date range.

getEnd

public java.util.Calendar getEnd(boolean excluding)
Description copied from interface: DateRangeI
Returns the actual contained Calendar. Should absolutely not be changed, though this is not checked. Nasty buggs could be the result of changing this retirned com.miginfocom.calendar.

Specified by:
getEnd in interface DateRangeI
Parameters:
excluding - If true the returned date will have one millisecond added first. Depending on how the returned com.miginfocom.calendar should be used this might, or might not, be desirable. For example, if the range spans exactly four days and the returned date should be used for displaying in what day it ends, then you should set this argument to false. But if it should be used to show a time range, for instance 09:00 to 10:00 the argument should be true since he actual stored end date/time is 09:59:999 (inclusive). See class info.
Returns:
A cloned com.miginfocom.calendar representing the end date.

getEnd

public java.util.Calendar getEnd()
Description copied from interface: DateRangeI
This is simply short for: getEnd(false), which means it will typically have milliseconds set to 999.

Specified by:
getEnd in interface DateRangeI
See Also:
DateRangeI.getEnd(boolean)

getEndTime

public java.util.Date getEndTime(boolean excluding)
Description copied from interface: DateRangeI
Returns a new Date object representing the end time

Specified by:
getEndTime in interface DateRangeI
Parameters:
excluding - If true the returned date will have one millisecond added first. Depending on how the returned com.miginfocom.calendar should be used this might, or might not, be desirable. For example, if the range spans exactly four days and the returned date should be used for displaying in what day it ends, then you should set this argument to false. But if it should be used to show a time range, for instance 09:00 to 10:00 the argument should be true since he actual stored end date/time is 09:59:999 (inclusive). See class info.
Returns:
A new Date object representing the end time

getEndTime

public java.util.Date getEndTime()
Description copied from interface: DateRangeI
This is simply short for: getEndTime(false), which means it will typically have milliseconds set to 999.

Specified by:
getEndTime in interface DateRangeI
See Also:
DateRangeI.getEndTime(boolean)

getEndField

public int getEndField(int field,
                       boolean excluding)
Description copied from interface: DateRangeI
Forwarded to Calendar#get.

Specified by:
getEndField in interface DateRangeI
Parameters:
field - The field to get
excluding - If true the returned date/time will be for the "next" millisecond that end date denotes. That date actually does not belong to this range but it is common for that value to be used for example when displaying a time range (e.g. 10:00:00.000 -> 11:15:00.000).
Returns:
The field's value
See Also:
Calendar.get(int)

getEndField

public int getEndField(int field)
Description copied from interface: DateRangeI
This is simply short for: getEndField(field, false), which means it will typically have milliseconds set to 999.

Specified by:
getEndField in interface DateRangeI
See Also:
DateRangeI.getEndField(int, boolean)

setEnd

public void setEnd(java.util.Calendar date,
                   boolean excluding)

setEndMillis

public void setEndMillis(long millis,
                         boolean excluding)
Description copied from interface: MutableDateRange
Sets the milliseconds of the end date directly

Specified by:
setEndMillis in interface MutableDateRange
Parameters:
millis - The milliseconds.
excluding - If field should be excluded form the range, set to true.

getEndMillis

public long getEndMillis(boolean excluding)
Description copied from interface: DateRangeI
Returns the end date in milliseconds. Especially useful when dealing with immutable date ranges since no defensive cloning is needed compared to DateRangeI.getEnd(boolean)

Specified by:
getEndMillis in interface DateRangeI
Parameters:
excluding - If true the returned date will have one millisecond added first. Depending on how the returned com.miginfocom.calendar should be used this might, or might not, be desirable. For example, if the range spans exactly four days and the returned date should be used for displaying in what day it ends, then you should set this argument to false. But if it should be used to show a time range, for instance 09:00 to 10:00 the argument should be true since he actual stored end date/time is 09:59:999 (inclusive). See class info.
Returns:
The end date in milliseconds

getEndMillis

public long getEndMillis()
Description copied from interface: DateRangeI
This is simply short for: getEndMillis(false), which means it will typically have milliseconds set to 999.

Specified by:
getEndMillis in interface DateRangeI
See Also:
DateRangeI.getEndMillis(boolean)

setEndField

public void setEndField(int field,
                        int value)
Description copied from interface: MutableDateRange
Forwarded to Calendar.set(int, int) for the end date.

Specified by:
setEndField in interface MutableDateRange
Parameters:
field - The field
value - The value to set
See Also:
Calendar.set(int, int)

addEnd

public void addEnd(int field,
                   long amount)
Description copied from interface: MutableDateRange
Forwarded to Calendar.add(int, int) for the end date.

Specified by:
addEnd in interface MutableDateRange
Parameters:
field - The field
amount - The value to set
See Also:
Calendar.add(int, int)

getStartInstant

public ImmutableDateRange getStartInstant()
Description copied from interface: DateRangeI
Returns an ImmutableDateRange representing the start of this date range.

Specified by:
getStartInstant in interface DateRangeI
Returns:
An ImmutableDateRange representing the start of this date range.

getEndInstant

public ImmutableDateRange getEndInstant(boolean excluding)
Description copied from interface: DateRangeI
Returns an ImmutableDateRange representing the end of this date range.

Specified by:
getEndInstant in interface DateRangeI
Parameters:
excluding - If true the returned date range will have one millisecond added first. Depending on how the returned calendar should be used this might, or might not, be desirable. For example, if the range spans exactly four days and the returned date should be used for displaying in what day it ends, then you should set this argument to false. But if it should be used to show a time range, for instance 09:00 to 10:00 the argument should be true since he actual stored end date/time is 09:59:999 (inclusive). See class info.
Returns:
An ImmutableDateRange representing the end of this date range.

getEndInstant

public ImmutableDateRange getEndInstant()
Description copied from interface: DateRangeI
This is simply short for: getEndInstant(false), which means it will typically have milliseconds set to 999.

Specified by:
getEndInstant in interface DateRangeI
See Also:
DateRangeI.getEndInstant(boolean)

getStart

public java.util.Calendar getStart()
Description copied from interface: DateRangeI
Returns a clone of the start date, free to change and it wont affect the range.

Specified by:
getStart in interface DateRangeI
Returns:
A clone of the start date

getStartTime

public java.util.Date getStartTime()
Description copied from interface: DateRangeI
Returns a new Date object representing the start time

Specified by:
getStartTime in interface DateRangeI
Returns:
A new Date object representing the start time

getStartField

public int getStartField(int field)
Description copied from interface: DateRangeI
Forwarded to Calendar#get.

Specified by:
getStartField in interface DateRangeI
Parameters:
field - The field to get. E.g. Calendar.WEEK.
Returns:
The field's value
See Also:
Calendar.get(int)

getStartMillis

public long getStartMillis()
Description copied from interface: DateRangeI
Returns the start date in milliseconds. Especially useful when dealing with immutable date ranges since no defensive cloning is needed compared to DateRangeI.getStart()

Specified by:
getStartMillis in interface DateRangeI
Returns:
The start date in milliseconds

setStart

public void setStart(java.util.Calendar date)

setStartMillis

public void setStartMillis(long millis)
Description copied from interface: MutableDateRange
Sets the milliseconds of the start date directly

Specified by:
setStartMillis in interface MutableDateRange
Parameters:
millis - The milliseconds.

setStartField

public void setStartField(int field,
                          int value)
Description copied from interface: MutableDateRange
Forwarded to Calendar.set(int, int) for the start field

Specified by:
setStartField in interface MutableDateRange
Parameters:
field - The field
value - The value to set
See Also:
Calendar.set(int, int)

addStart

public void addStart(int field,
                     long amount)
Description copied from interface: MutableDateRange
Forwarded to Calendar.add(int, int)

Specified by:
addStart in interface MutableDateRange
Parameters:
field - The field
amount - The value to set
See Also:
Calendar.add(int, int)

setToRange

public MutableDateRange setToRange(DateRangeI dateRange)
Description copied from interface: MutableDateRange
Sets this range to the same start and end date/time as dateRange. Will not copy time zone or locale! Will copy hasTime and hasDate.

dateRange will not be referenced in any way after this method, free to change.

Specified by:
setToRange in interface MutableDateRange
Parameters:
dateRange - The range containing the date/time. Won't be change.
Returns:
this

setTimeFromRange

public MutableDateRange setTimeFromRange(DateRangeI dateRange)
Description copied from interface: MutableDateRange
Copies time (hour, min, sec, millis) from dateRange's start and end date and sets in this's start and end date making the time of day match but not necessary the date.

Specified by:
setTimeFromRange in interface MutableDateRange
Parameters:
dateRange - The range to copy the time of day from
Returns:
this.

setDateFromRange

public MutableDateRange setDateFromRange(DateRangeI dateRange)
Description copied from interface: MutableDateRange
Copies date (yeas, day of year) from dateRange's start and end date and sets in this's start and end date making the date of day match but not necessary the time.

Specified by:
setDateFromRange in interface MutableDateRange
Parameters:
dateRange - The range to copy the time of day from
Returns:
this.

isSpanningTime

public boolean isSpanningTime()
Description copied from interface: DateRangeI
Returns if start date is not same as end date. Even if they are the same it actually spans 1 millisecond since both start and end date are considered inclusive.
Notice that DateRangeI.getMillisSpanned(boolean, boolean) will return 1.

Specified by:
isSpanningTime in interface DateRangeI
Returns:
If start date is not same as end date.

isSorted

public boolean isSorted()
Description copied from interface: DateRangeI
Returns if startDate is before (or same) as endDate (to the millisecond)

Specified by:
isSorted in interface DateRangeI
Returns:
If startDate is before (or same) as endDate (to the millisecond)

isInSame

public boolean isInSame(int rangeType)
Description copied from interface: DateRangeI
Returns if cal1 and cal2 is in the same range type. (e.g. DateRangeI.RANGE_TYPE_DAY) Much faster than getSpanCount(rangeType, xxx) == 0 !

Specified by:
isInSame in interface DateRangeI
Parameters:
rangeType - The range type. DateRangeI.RANGE_TYPE_xxx. Not RANGE_TYPE_CUSTOM.
Returns:
If cal1 and cal2 is in the same range type.d

getSize

public int getSize(int rangeType,
                   boolean dstSafe)
Description copied from interface: DateRangeI
Returns the number of seconds, minutes, hours, days, weeks, months or years betwen start and end date, inclusive. For instance 2002-12-31 to 2003-01-01 spans two years!
RANGE_TYPE_MONTH, RANGE_TYPE_YEAR_MONTHS and RANGE_TYPE_YEAR_WEEKS are passed in to getSpanCountIter(...) since their length is variable and has to be iterated anyway.

Specified by:
getSize in interface DateRangeI
Parameters:
rangeType - One of: DateRangeI.RANGE_TYPE_SECOND Counts the seconds
DateRangeI.RANGE_TYPE_MINUTE Counts the minutes
DateRangeI.RANGE_TYPE_HOUR Counts the hours
DateRangeI.RANGE_TYPE_DAY Counts the days
DateRangeI.RANGE_TYPE_WEEK Counts the weeks
DateRangeI.RANGE_TYPE_MONTH Counts the months (iterative algorithm)
DateRangeI.RANGE_TYPE_YEAR_MONTHS Counts the years, month based. jan 1 to dec 31 (iterative algorithm)
DateRangeI.RANGE_TYPE_YEAR_WEEKS Counts the years, week based. week 01 to week 52/53 (iterative algorithm)
NOTE! Getting the time zone is currently a quite expensive call. So only set this to true if it is really needed.
dstSafe - For instance a day can span 23, 24 or 25 hours depending on if it's the Daylight saving day. With this set to true the returned value will be compensated to return 24 for all days. This is also valid for minutes and seconds. Note that if true adding the returned amount to start may not end up on end but on one earlier or later.
Returns:
The number of days, weeks, months or years betwen two dates inclusive, which means never 0.

getMillisSpanned

public long getMillisSpanned(boolean dSTSafe,
                             boolean excluding)
Description copied from interface: DateRangeI
Returns the number of milliseconds this range spans.

Specified by:
getMillisSpanned in interface DateRangeI
Parameters:
dSTSafe - If true transitions over a DST border will be compensated for the offset. false is just a endDate.getTimeInMillis() - startDate.getTimeInMillis() + 1. false is as UTC-mode.
excluding - If true the returned value will have one millisecond added first. Depending on how the returned value should be used this might, or might not, be desirable.
Basically setting to true will return 1000 millis for one spanned second and setting to false will return 999 which is the internal representation.
Returns:
The number of milliseconds from start to end date. Always > 0. (E.g. 1000 for one second)
See Also:
DateRangeI.getEnd(boolean), DateRangeI.isSpanningTime()

setMillisSpanned

public void setMillisSpanned(long millis,
                             boolean dSTSafe,
                             boolean excluding)
Description copied from interface: MutableDateRange
Changes end date so the total duration becomes millis.

Specified by:
setMillisSpanned in interface MutableDateRange
Parameters:
millis - The duration in milliseconds.
dSTSafe - If true transitions over a DST border will be compensated for the offset (clock will always move x millis). false is just set the millisecond different. false is as UTC-mode.
excluding - If true the setted value will have one millisecond added first. Depending on how the returned value should be used this might, or might not, be desirable.Basically setting to true will set one second spanned for 1000 millis and setting to false will need 999 to set one second spanned.

isOverlapping

public boolean isOverlapping(DateRangeI range)
Description copied from interface: DateRangeI
Checks if dateRange overlaps (or touches) this date range. Inclusive.

Specified by:
isOverlapping in interface DateRangeI
Parameters:
range - The date range to check if this is overlapping with
Returns:
If dateRange overlaps (or touches) this date range. Inclusive.

isContinuous

public boolean isContinuous(DateRangeI range)
Description copied from interface: DateRangeI
Checks if dateRange overlaps (or touches) this date range or if they are next to eachother so that there are no time between them and they thus form a continuous date range.

Specified by:
isContinuous in interface DateRangeI
Parameters:
range - The date range to check if this is continuous with
Returns:
If dateRange overlaps or is next to this date range.

isOverlapping

public boolean isOverlapping(DateRangeI range,
                             DateRangeI withinRange)
Description copied from interface: DateRangeI
Checks if dateRange overlaps (or touches) this date range. Inclusive.

Specified by:
isOverlapping in interface DateRangeI
Parameters:
range - The date range to check if this is overlapping with
withinRange - Only return true if there is an overlap within this range. Not null.
Returns:
If dateRange overlaps (or touches) this date range. Inclusive.

isContaining

public boolean isContaining(DateRangeI innerRange)
Description copied from interface: DateRangeI
Checks if a 'innerDateSpan' is compleately inside or equal to this range.

Specified by:
isContaining in interface DateRangeI
Parameters:
innerRange - The possibly inside date range
Returns:
If 'innerDateSpan' is compleately inside or equal to this range.

cloneRange

public DateRangeI cloneRange()

sort

public MutableDateRange sort(boolean b)
Description copied from interface: MutableDateRange
Sorts or unsorts this range by swapping start and end date references if needed. A sorted range is one that start <= end.

Specified by:
sort in interface MutableDateRange
Parameters:
b - If true the range will be sorted. If false the range will be "unsorted" so that the end date will change place, if necessary, so that the end date will be before the start date.
Returns:
this

sort

public MutableDateRange sort()
Description copied from interface: MutableDateRange
Sorts this range by swapping start and end date references if needed. A sorted range is one that start <= end.

Exactly the same as .sort(true);.

Specified by:
sort in interface MutableDateRange
Returns:
this

isContaining

public boolean isContaining(long timeInMillis,
                            boolean disregardSorting)
Description copied from interface: DateRangeI
Returns if the millisecond is within the range, inclusive.

Specified by:
isContaining in interface DateRangeI
disregardSorting - If true unsorted ranges (start > end) also returns true if timeInMillis is betweend the boundarys
Returns:
If the millisecond is within the range.

getRangeType

public int getRangeType()
Description copied from interface: DateRangeI
Returns the type of range that this DataSpan spans. (RANGE_TYPE_xxx). This method doesn't handle time of day at all. The smallest range type that can be returned is RANGE_TYPE_DAY and it will do that if the range start and end is in the same day.

Only if one day, one week, one month or one year (week or month based) are exactly spanned (end date inclusive) will anything other than RANGE_TYPE_CUSTOM be returned.

Specified by:
getRangeType in interface DateRangeI
Returns:
The type of range that this DataSpan spans. (RANGE_TYPE_xxx)

roundExpand

public MutableDateRange roundExpand(int boundaryType)
Description copied from interface: MutableDateRange
Sets the start and end date to the first and last millisecond of a specific boundary by expanding the range. If the range isn't sorted (startDate > endDate) the boundaries are reversed. For instance endDate would be set to the FIRST millisecond of boundaryField if startDate %gt endDate.

Specified by:
roundExpand in interface MutableDateRange
Parameters:
boundaryType - Both dates will be changed to the start/end boundary indicated by 'boundaryType'. i.e. RANGE_TYPE_xxx
Returns:
this as a convenience

roundReduce

public MutableDateRange roundReduce(int boundaryType)
Description copied from interface: MutableDateRange
Sets the start and end date to the first and last millisecond of a specific boundary by reducing the range. If the range isn't sorted (startDate > endDate) the boundaries are reversed. For instance endDate would be set to the FIRST millisecond of boundaryField if startDate %gt endDate.

Specified by:
roundReduce in interface MutableDateRange
Parameters:
boundaryType - Both dates will be changed to the start/end boundary indicated by 'boundaryType'. i.e. RANGE_TYPE_xxx
Returns:
this as a convenience

setStartToBoundaryExpand

public void setStartToBoundaryExpand(int boundaryType)
Description copied from interface: MutableDateRange
Sets the start date/time to boundaryType by expanding it to that boundary. If sorted to the earlier edge of the boundary and vice versa.

Specified by:
setStartToBoundaryExpand in interface MutableDateRange
Parameters:
boundaryType - The boundary type to round to. E.g. DateRangeI.DateRangeI.RANGE_TYPE_WEEK.

setStartToBoundaryReduce

public void setStartToBoundaryReduce(int boundaryType)
Description copied from interface: MutableDateRange
Sets the start date/time to boundaryType by reducing it to that boundary. If sorted to the earlier edge of the boundary and vice versa.
Note that the date range might change sorting after this method, that means that start and end might "pass" eachother. Also note that if the start is alread at the first millisecond of indicated boundaryType noting will happen.

Specified by:
setStartToBoundaryReduce in interface MutableDateRange
Parameters:
boundaryType - The boundary type to round to. E.g. DateRangeI.DateRangeI.RANGE_TYPE_WEEK.

setEndToBoundaryExpand

public void setEndToBoundaryExpand(int boundaryType)
Description copied from interface: MutableDateRange
Sets the end date/time to boundaryType by expanding it to that boundary. If sorted to the later edge of the boundary and vice versa.

Specified by:
setEndToBoundaryExpand in interface MutableDateRange
Parameters:
boundaryType - The boundary type to round to. E.g. DateRangeI.DateRangeI.RANGE_TYPE_HOUR.

setEndToBoundaryReduce

public void setEndToBoundaryReduce(int boundaryType)
Description copied from interface: MutableDateRange
Sets the end date/time to boundaryType by reducing it to that boundary. If sorted to the later edge of the boundary and vice versa.
Note that the date range might change sorting after this method, that means that start and end might "pass" eachother. Also note that if the end is alread at the last millisecond of indicated boundaryType noting will happen.

Specified by:
setEndToBoundaryReduce in interface MutableDateRange
Parameters:
boundaryType - The boundary type to round to. E.g. DateRangeI.DateRangeI.RANGE_TYPE_HOUR.

move

public MutableDateRange move(int field,
                             long amount,
                             int boundaryType)
Description copied from interface: MutableDateRange
Adds/moves the range by using a "middle point add and expand" algorithm. This is what's happens:
1) The middle point between start and end dates are moved (added) by field/amount
2) A new DateRange is expanded around this new middle point to the specified boundary.
Not that the size might change and will always be ONE boundaryType!

Specified by:
move in interface MutableDateRange
Parameters:
field - See Calendar fields.
amount - The amount of 'field's to add.
boundaryType - Both dates will be changed to the start/end boundary indicated by 'boundaryType'. E.e. DateRangeI.RANGE_TYPE_WEEK.
Returns:
this
See Also:
MutableDateRange.roundExpand(int), DateRangeI.getMiddle()

add

public void add(int field,
                long delta,
                boolean start,
                boolean end,
                DateRangeRounder dateRangeRounder)
Description copied from interface: MutableDateRange
Add/move the start and/or end time of this range.

Specified by:
add in interface MutableDateRange
Parameters:
field - see Calendar.add(int, int)
delta - see Calendar.add(int, int)
start - If true the start date will change.
end - If true the end date will change.
dateRangeRounder - The object responsible for snapping/rounding time/date. Can be null.

add

public MutableDateRange add(int field,
                            long amount,
                            boolean preserveLength,
                            boolean lengthDSTSafe)
Description copied from interface: MutableDateRange
Directly passed on to start and end Calendars without any intervention

Specified by:
add in interface MutableDateRange
Parameters:
field - Same as for Calendar.add(int, int)
amount - Same as for Calendar.add(int, int)
preserveLength - If true the the length (i.e. spanned DST-corrected millis) will be same as before the call. The length can change if some rounding occur, for instande in this case (2003-01-28 - 2003-02-01).add(Month, 1) the range will change to (2003-02-28 - 2003-03-01) which spannes two days instead of four. The end date/time is adjusted to get the correct length.
false will just add the same to both start and end date and length might change.
lengthDSTSafe - If true additions over a DST border will be compensated for the offset. false is just make sure the actual (UTC) length is the same.
Returns:
this
See Also:
Calendar.add(int, int)

addMillis

public void addMillis(long amount)
Description copied from interface: MutableDateRange
Adds amount number of milliseconds to both start and end date. Separate from add(int field, int amount) since a long has to be used to hold the amount.
NOTE! this method does not compensate for jumps over Daylight Savings Time boundary. This means that one millisecond added may actually make the local time one hour less (minus one millisecond of course).

Specified by:
addMillis in interface MutableDateRange
Parameters:
amount - The number of milliseconds to add. Can be negative.
See Also:
MutableDateRange.addMillisDSTSafe(long)

addMillisDSTSafe

public void addMillisDSTSafe(long amount)
Description copied from interface: MutableDateRange
Adds amount number of milliseconds to both start and end date. Separate from add(int field, int amount) since a long has to be used to hold the amount.

Specified by:
addMillisDSTSafe in interface MutableDateRange
Parameters:
amount - The number of milliseconds to add. Can be negative.
See Also:
DateUtil.addMillisDSTSafe(long, java.util.TimeZone, long)

roll

public void roll(int field,
                 int amount)
Description copied from interface: MutableDateRange
Directly passed on to start and end Calendars without any intervention

Specified by:
roll in interface MutableDateRange
Parameters:
field - see Calendar
amount - see Calendar
See Also:
Calendar.roll(int, int)

expandRange

public MutableDateRange expandRange(int field,
                                    int amount)
Description copied from interface: MutableDateRange
Expands the range by adding and substracting the amount to field for end and start date, respectively.

Specified by:
expandRange in interface MutableDateRange
Parameters:
field - The field, eq Calendar.WEEK_OF_YEAR, to expand the range with
amount - The number of 'field's that the range should be expanded with. negative values reduces the range.
Returns:
this

setSize

public MutableDateRange setSize(int boundaryType,
                                int size,
                                int align)
Description copied from interface: MutableDateRange
Resizes the range to a specified number of a certain type (e.g. weeks). The range can be unsorted and it will be handeled correctly.

For instance a range can be set to span "five days", or "three hours". The alignment decides where to put the extra time or where to cut time from (start, end or both).

Specified by:
setSize in interface MutableDateRange
Parameters:
boundaryType - The unit that 'newSize' is specified in. Eg RANGE_TYPE_WEEK.
size - The size in 'rangeType' units that the range will be set to.
align - Specifies is extra time, or cut of time, will be taken/given from the start, end pr both. See the different alignment options, They are:
MutableDateRange.ALIGN_CENTER_DOWN, MutableDateRange.ALIGN_CENTER_UP, MutableDateRange.ALIGN_START, MutableDateRange.ALIGN_END, MutableDateRange.ALIGN_EARLIEST, MutableDateRange.ALIGN_LATEST.
Returns:
this For chaining.
See Also:
MutableDateRange.roundExpand(int)

setSize

public MutableDateRange setSize(int boundaryType,
                                int size,
                                AtRefRangeNumber align)
Description copied from interface: MutableDateRange
Resizes the range to a specified number of a certain type (e.g. weeks).The range can be unsorted and it will be handeled correctly.

For instance a range can be set to span "four weeks", or "three days". The alignment decides where to put the extra time or where to cut time from (start, end or both).

Specified by:
setSize in interface MutableDateRange
Parameters:
boundaryType - The unit that 'newSize' is specified in. Eg RANGE_TYPE_WEEK.
size - The size in 'rangeType' units that the range will be set to.
align - Specifies how to align the new time range relative to the old one. If null the alignment will be centered.

The most usable types are probably:

  • AtStart Align it so that the start will be the specified amount of boundaryType from the old start. For instance two weeks, if boundaryType is DateRangeI.RANGE_TYPE_WEEK and the argument is new AtStart(2f).
  • AtEnd Align it so that the end will be the specified amount of boundaryType from the old end. Most logically a negative value will be used. E.g. new AtEnd(-1f).
  • AtFraction 0f will align starts, 0.5f will center and 1f will align ends. All values in between is also valid of course.
Returns:
this For chaining.

cut

public MutableDateRange cut(DateRangeI maxBounds)
Description copied from interface: MutableDateRange
Cuts of the start and/or end dates to the start or end dates in maxBounds if maxBounds is "inside" or this date range.
Note that if maxBounds doesn't overlap this then the resulting range (this) will span no time and probably be unsorted.

Specified by:
cut in interface MutableDateRange
Parameters:
maxBounds - The bounds which to cut with
Returns:
this
See Also:
DateRangeI.isSorted(), DateRangeI.isSpanningTime(), DateRangeI.isOverlapping(com.miginfocom.util.dates.DateRangeI)

union

public MutableDateRange union(DateRangeI range)
Description copied from interface: MutableDateRange
Sets this range so that it's start date is the earliest of the two and the end date is the latest of the two. Do a union of the ranges.

Specified by:
union in interface MutableDateRange
Parameters:
range - The range to expand with. Will not be changed. If null nothing will be changed.
Returns:
this.

addRange

public MutableDateRange addRange(DateRangeI range)
Description copied from interface: MutableDateRange
Adds range to this range. The resulting range will be spanning the smallest date range that can contain both ranges. The difference from MutableDateRange.union(DateRangeI) is that this method can leave this range unsorted. The returned date range will be unsorted (unsorted == start > end) if range's middle point is before (in time) the this range's middle point. The sorting of either range or this is thus NOT taken into account.

Specified by:
addRange in interface MutableDateRange
Parameters:
range - The range to add. Not null.
Returns:
this For chaining.

getMiddle

public java.util.Calendar getMiddle()
Description copied from interface: DateRangeI
Calulates the time in the middle of 'startDate' and 'endDate'.

Specified by:
getMiddle in interface DateRangeI
Returns:
The time in the middle of 'startDate' and 'endDate'.

getMiddleMillis

public long getMiddleMillis()
Description copied from interface: DateRangeI
Calulates the time in the middle of 'startDate' and 'endDate'.

Specified by:
getMiddleMillis in interface DateRangeI
Returns:
The time im millisoconds in the middle of 'startDate' and 'endDate'.

getRelative

public java.util.Calendar getRelative(double perc)
Description copied from interface: DateRangeI
Returns a date that are perc percent into the range. i.e. if perc is 0.5d, a date exactly between start and end date is returned. 0.0d means start date and 1.0d is the end date/time

Specified by:
getRelative in interface DateRangeI
Parameters:
perc - The percentage.
Returns:
A date that are perc percent in the range.

getRelativeMillis

public long getRelativeMillis(double perc)
Description copied from interface: DateRangeI
Returns a date that are perc percent into the range. i.e. if perc is 0.5d, a date exactly between start and end date is returned. 0.0d means start date and 1.0d is the end date/time

Specified by:
getRelativeMillis in interface DateRangeI
Parameters:
perc - The percentage.
Returns:
A date that are perc percent in the range.

getRelativeRange

public DateRangeI getRelativeRange(double startPerc,
                                   double endPerc)
Description copied from interface: DateRangeI
Returns a date range that start from startPerc percent into the range until endPerc into the range. If endPerc is 1.0d the last millisecond is returned (since it is inclusive), as opposed to #getRelativeDateRange. If startPerc and endPerc is equal, a range with the same start and end date will be returned.

Specified by:
getRelativeRange in interface DateRangeI
Parameters:
startPerc - A percentage into the range. must be <= endPerc
endPerc - A percentage into the range. must be >= startPerc
Returns:
A date range spanning the relative part of a this date range.

getDurationString

public java.lang.String getDurationString(java.lang.String formatString)
Description copied from interface: DateRangeI
Calls DateUtil.getDurationString(java.util.Calendar, java.util.Calendar, boolean, String) for the start and end dates and returns the result.

Specified by:
getDurationString in interface DateRangeI
Parameters:
formatString - The format string. See DateUtil.getDurationString(java.util.Calendar, java.util.Calendar, boolean, String) for details.
Returns:
The resulting string. Not null.

iterator

public java.util.Iterator iterator(int boundaryType)
Description copied from interface: DateRangeI
Returns an iterator that iterates over the range, returning a new DateRangeI for every call to .next(). Every DateRangeI returned will be of the length that 'boundaryType' indicates, except maybe the first and last since these two are NOT rounded to their boundary before starting. If this range's start date and end date are within same 'boundaryType' (eg. week) the iterator will only return one DateRange with range same as 'this'.
This range's start and end dates are read at the initialization of the Iterator and may be changed while using it, without affecting the Iterator or its returned values.
If the date range isn't sorted the iterator will return no ranges as all.

Specified by:
iterator in interface DateRangeI
Parameters:
boundaryType - The "size" that this range will be "chopped" to. 'boundaryType'. RANGE_TYPE_xxx
Returns:
An iterator that iterates over the range.

iterator

public java.util.Iterator iterator(int boundaryType,
                                   int amount)
Description copied from interface: DateRangeI
Returns an iterator that iterates over the range, returning a new DateRangeI for every call to .next(). Every DateRangeI returned will be of the length that 'boundaryType' indicates, except maybe the first and last since these two are NOT rounded to their boundary before staring. If this range's start date and end date are within same 'boundaryType' (eg. week) the iterator will only return one DateRange with range same as 'this'.
This range's start and end dates are read at the initialization of the Iterator and may be changed while using it, without affecting the Iterator or its returned values.
If the date range isn't sorted the iterator will return no ranges as all.

Specified by:
iterator in interface DateRangeI
Parameters:
boundaryType - The "size" that this range will be "chopped" to (regardless of amount). 'boundaryType'. RANGE_TYPE_xxx
amount - The amount of boundsryType to add for every iteration.
Returns:
An iterator that iterates over the range.

getSubDateList

public java.util.ArrayList getSubDateList(int field,
                                          int[] values,
                                          int occurField,
                                          int[] dayOfWeekOccur,
                                          int maxCount,
                                          boolean asRanges)
Description copied from interface: DateRangeI
Runs an iterator over the range with sizes field and returns all date/times that's inside this range and which have a field value that is one of the integers in values. E.g. if this range is a month and field is Calendar.DAY_OF_WEEK with values == {0, 1} then all sundays and mondays within this range are returned as GegorianCalendars.

Specified by:
getSubDateList in interface DateRangeI
Parameters:
field - The field in a Calendar. E.g. Calendar.DAY_OF_WEEK.
values - A number of values for field to match. Not null. Can be negative and if so is relative to the maximum possible value of the field. E.g. -1 when field is Calendar.HOUR is same as 23.
occurField - Either Calendar.DAY_OF_YEAR or Calendar.DAY_OF_MONTH. Only used if occurFilter is non-null. field must also be set to Calendar.DAY_OF_WEEK.
dayOfWeekOccur - Specifies for every value that only an occurence within the month or year (depending on occurField) should be returned.
For instance if values[0] == Calendar.MONDAY, occurField == Calendar.DAY_OF_YEAR and dayOfWeekOccur[0] == 2 then only the second monday of the year is considered a "hit". Negative values means "from the end", so dayOfWeekOccur[0] == -2 would mean second to last monday of the year.
An element that is 0 is as usual (as if dayOfWeekOccur == null) considered to be all mondays (for instance).
If non-null must be same length as values, field must be Calendar.DAY_OF_WEEK. If input is a bad combination an IllegalArgumentException is thrown.
See "BYDAY" paragraph in "RFC 2445" for further explanation.
maxCount - The maximum size of the returned list. -1 means no limit. Can be used as a "protection" against bad input that would return to much data.
asRanges - If true the returned List is made up of DateRanges instead of Calendars. These ranges are set to fill the whole boundary that field indicats. E.g. spans exactly a day for Calendar.DAY_OF_MONTH.
Returns:
A list of GegorianCalendar s and/or MutableDateRanges. Never null but can be of size 0.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String formatString,
                                 boolean endIsExcluding,
                                 boolean includeOffset)
Description copied from interface: DateRangeI
Retuns a string representation of the date range. E.g. "yyyy-MM-dd HH:mm:ss:SSS".

Specified by:
toString in interface DateRangeI
Parameters:
formatString - Format for the dates. If null default date time instance is used.
endIsExcluding - Set to true if the end date should be displayed 'excluding' the last millisecond, normally meaning that the milliseconds are are an even number (0).
includeOffset - If the DST (Daylight Savings Time) offset should be included in the output.
Returns:
The string.

equals

public boolean equals(java.lang.Object o)
Returns true if obj is != null, is an instance of DateRangeI and represents date range with the same start and end millisecond. The hasDate, hasTime, locale and time zone also have to equal.

Overrides:
equals in class java.lang.Object
Parameters:
o - The other object
Returns:
true if obj is != null and a date range with the same start and end millisecond

compareTo

public int compareTo(java.lang.Object o)
Compares startdates, and if they are the same, end dates. If .equals() return 0.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - The other DateRangeI to compare to. Not null and must be of type DateRangeI
Returns:
-1, 0 or 1.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

postponeEvents

public void postponeEvents()
Description copied from interface: MutableDateRange
Increase the postpone count. If postpone count > 1 (it will always be after a call to this method) events abount this date range changes will be postponed until the postpone count is down to 0 again. Can be used if multiple changes is to be made to the date range and only one property event should be fired when its all done.
It's important to always match incPostponeCount() with an decPostponeCount() for all possible paths or no events will be fired.
Throws an exception if the postpone count > 100 since that is probably due to a bug.

Specified by:
postponeEvents in interface MutableDateRange
See Also:
MutableDateRange.allowEvents(), PropertyObservable.addPropertyListener(java.beans.PropertyChangeListener, boolean)

allowEvents

public void allowEvents()
Description copied from interface: MutableDateRange
Decreases the postpone count and if it reaches 0 an event is fired automatically.
Throws an IllegalStateException if the postpone count is alread at 0 and the date range has actually changed.

Specified by:
allowEvents in interface MutableDateRange
See Also:
MutableDateRange.postponeEvents(), PropertyObservable.addPropertyListener(java.beans.PropertyChangeListener, boolean)

isIgnorePropertyEvents

public boolean isIgnorePropertyEvents()
Description copied from interface: PropertyObservable
Returns if the PropertyObservable is currently ignoring change events. If no lisneners returns true.

Specified by:
isIgnorePropertyEvents in interface PropertyObservable
Returns:
If the PropertyObservable is currently ignoring change events

setIgnorePropertyEvents

public boolean setIgnorePropertyEvents(boolean b)
Description copied from interface: PropertyObservable
Sets if ChangeEvent's should be fired. If there are no listeners registered this method does nothing.

Specified by:
setIgnorePropertyEvents in interface PropertyObservable
Parameters:
b - true or false...
Returns:
The old value.

addPropertyListener

public void addPropertyListener(java.beans.PropertyChangeListener l)
Description copied from interface: PropertyObservable
Adds a listener that should be notified of all changes that to the property values of this com.miginfocom.theme.
This is usually just implemented as addPropertyListener(l, false)

Specified by:
addPropertyListener in interface PropertyObservable
Parameters:
l - The listener.

addPropertyListener

public void addPropertyListener(java.beans.PropertyChangeListener l,
                                boolean asWeakRef)
Description copied from interface: PropertyObservable
Adds a listener that should be notified of all changes that to the property values of this com.miginfocom.theme

Specified by:
addPropertyListener in interface PropertyObservable
Parameters:
l - The listener
asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since the garbage collector can collect the listener if it is only referenced from this list.
Note! This (weak reference) can not be used with listeners that doesn't have another real (a.k.a Strong) reference to it, as for instance an annonymous inner class. If one such listener is added it will be removed almost immediately by the garbage collector.

removePropertyListener

public void removePropertyListener(java.beans.PropertyChangeListener l)
Description copied from interface: PropertyObservable
Removes a listener if it is in the list.

Specified by:
removePropertyListener in interface PropertyObservable
Parameters:
l - the listener

firePropertyChangeEvent

protected boolean firePropertyChangeEvent(boolean testForEq)


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.