com.miginfocom.util.dates
Class DateRangeUnion

java.lang.Object
  extended by com.miginfocom.util.dates.DateRangeUnion

public class DateRangeUnion
extends java.lang.Object

A date range that have a base date range and end date range.
Basically this class keeps track of two date ranges and some convenience methods for handling them.


Field Summary
 MutableDateRange base
           
 MutableDateRange end
           
 
Constructor Summary
DateRangeUnion()
          Mostly to have a no-arg constructor.
DateRangeUnion(DateRangeI base)
          Cosntructor.
DateRangeUnion(DateRangeI base, int type)
          Cosntructor.
 
Method Summary
 void addDateChangeListener(DateChangeListener l)
          Adds the listener, if it isn't already in the list.
 void addDateChangeListener(DateChangeListener l, boolean asWeakRef)
          Adds the listener, if it isn't already in the list.
protected  void fireDateChange(DateRangeI oldRange, DateRangeI newRange, int type)
          Fires a date change event to the listeners
 DateRangeRounder getRounder()
          Returns the rounder used to round returned union date range.
 int getType()
          Returns the type.
 MutableDateRange getUnion(boolean sort)
          Returns the union of base and end range.
 void removeDateChangeListener(DateChangeListener l)
          Removes the listener, if it is in the list.
 MutableDateRange setBase(DateRangeI newBase)
          Sets the base date range.
 MutableDateRange setBaseAndTempEnd(DateRangeI newBase, DateRangeI tmpEnd)
          Sets base and end.
 void setRounder(DateRangeRounder rounder)
          Sets the rounder used to round the returned union date range.
 MutableDateRange setTempEnd(DateRangeI tmpEnd)
          Sets the end range.
 void setType(int type, boolean fireEvent)
          Sets the type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

base

public MutableDateRange base

end

public MutableDateRange end
Constructor Detail

DateRangeUnion

public DateRangeUnion()
Mostly to have a no-arg constructor. Must set a base and type to be usable.


DateRangeUnion

public DateRangeUnion(DateRangeI base)
Cosntructor. Sets type to 0.

Parameters:
base - The date date range.

DateRangeUnion

public DateRangeUnion(DateRangeI base,
                      int type)
Cosntructor.

Parameters:
base - The date date range.
type - The type of date range. Not interpreted by this class and is to be used by class that uses this object.
Method Detail

setBaseAndTempEnd

public MutableDateRange setBaseAndTempEnd(DateRangeI newBase,
                                          DateRangeI tmpEnd)
Sets base and end.

Parameters:
newBase - The base. Object are copied.
tmpEnd - The temporary end. Object are copied.
Returns:
The date range that is dirty (old union unioned with new union) or null if no change.

setBase

public MutableDateRange setBase(DateRangeI newBase)
Sets the base date range. If null the union is considered empty. Clears any temporary end.

Parameters:
newBase - The base. Object are copied.
Returns:
The date range that is dirty (old union unioned with base) or null if no change.

setTempEnd

public MutableDateRange setTempEnd(DateRangeI tmpEnd)
Sets the end range. Does nothing and returns null if base == null.

Parameters:
tmpEnd - Can be null and then there will be no end range. Range are copied, not kept.
Returns:
The total range that has gotten changed. I.e. the dirty range or null if no change.

getUnion

public MutableDateRange getUnion(boolean sort)
Returns the union of base and end range. If base is null then nul will be returned.

Parameters:
sort - If true the range returned will always be sorted. if false the returned date range will have a negative sorting (I.e. unsorted, start > end) if the temporary range's middle point is before (in time) the base's middle point.
Returns:
The union of base and end range. null if base is null. Returned range is a a new, free to use object. If no end the returned range will equal the base range from the constructor.
See Also:
MutableDateRange.sort(boolean), MutableDateRange.addRange(DateRangeI)

getType

public int getType()
Returns the type. Not interpreted by this class. User interpreted.

Returns:
The type

setType

public void setType(int type,
                    boolean fireEvent)
Sets the type. Not interpreted by this class. User interpreted.

Parameters:
type - The type
fireEvent - If there should be an event fired if the type is changed..

setRounder

public void setRounder(DateRangeRounder rounder)
Sets the rounder used to round the returned union date range. Can be used for instance to make a selected range 1 to 3 weeks or so that exactly two days must be selected.

Parameters:
rounder - The rounder. If null no rounding will be made.

getRounder

public DateRangeRounder getRounder()
Returns the rounder used to round returned union date range.

Returns:
The rounder. May be null.

addDateChangeListener

public void addDateChangeListener(DateChangeListener l)
Adds the listener, if it isn't already in the list. Old and new object will be the old union and new union repectively. Always sorted.

Parameters:
l - The listener. Not null.

addDateChangeListener

public void addDateChangeListener(DateChangeListener l,
                                  boolean asWeakRef)
Adds the listener, if it isn't already in the list. Old and new object will be the old union and new union repectively. Always sorted.

Parameters:
l - The listener. Not null.
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.

removeDateChangeListener

public void removeDateChangeListener(DateChangeListener l)
Removes the listener, if it is in the list.

Parameters:
l - The listener to remove, not null.

fireDateChange

protected void fireDateChange(DateRangeI oldRange,
                              DateRangeI newRange,
                              int type)
Fires a date change event to the listeners

Parameters:
oldRange - The old range or null if not applicable. Will be cloned locally. The old range doesn't need to be provided. MUST be sorted.
newRange - The new range or null if there was no new range. Will be cloned locally and always sorted.MUST be sorted.
type - The type, E.g. DateChangeEvent.SELECTED. As a contract between the producer and reciever of the event and can assume any value.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.