com.miginfocom.util.dates
Class TimeSpanList

java.lang.Object
  extended by com.miginfocom.util.dates.TimeSpanList
Direct Known Subclasses:
ActivityList

public class TimeSpanList
extends java.lang.Object

A list of TimeSpan objects. (which include and {@link com.miginfocom.calendar.activity.Activity} objects)


Constructor Summary
TimeSpanList()
           
TimeSpanList(java.util.Collection c)
          Constructor
TimeSpanList(int initialCapacity)
           
TimeSpanList(TimeSpan[] timeSpans)
           
TimeSpanList(TimeSpan[] timeSpans, int from, int to)
          Constructs from an array, or part thereof.
TimeSpanList(TimeSpanList tsList)
          Constructor.
 
Method Summary
 void add(int index, TimeSpan ts)
           
 void add(TimeSpan ts)
           
 void addAll(java.util.Collection c)
           
 void addAll(TimeSpan[] timeSpans)
          Adds all of the elements in timeSpans to this list.
 void addAll(TimeSpan[] timeSpans, int from, int to)
          Adds all, or some, of the elements in timeSpans to this list.
 void addAll(TimeSpanList c)
           
 void addTimeSpanListListener(TimeSpanListListener l)
          Adds a listener that is notified of all changes to the list itself (add/remove).
 void addTimeSpanListListener(TimeSpanListListener l, boolean asWeakRef)
          Adds a listener that is notified of all changes to the list itself (size).
 void clear(int newCap)
          Disposes of the internal array.
 TimeSpanList cloneList()
          Creates a shallow copy
 void condense()
          Removes null elements and set the size to the number of elements that wasn't null.
 boolean contains(TimeSpan o)
          Returns if the actual object o is in this list
 TimeSpanList[] divideIntoRanges(TimeSpan[] spanList)
          Divides this list into smaller lists, each spanning a certain date.
 void fireDepositoryListChanged(TimeSpan[] timeSpans, int type, DateRangeI dateRange)
          Fires a manual TimeSpanListEvent.
protected  void fireTimeSpanListListener(TimeSpan[] timeSpans, int type)
          Fires a list change event to all registerd listeners.
 TimeSpan get(int ix)
          Returns the timespan at ix.
 TimeSpanList getOverlapCluster(DateRangeI overlapRange, boolean removeFound, boolean recursive)
          Returns a new list with references to a sub set of the activities that are in this list.
 TimeSpanList getOverlapCluster(DateRangeI overlapRange, java.util.Map substMap, boolean removeFound, boolean recursive)
          Returns a new list with references to a sub set of the activities that are in this list.
 MutableDateRange getTotalDateSpan()
          Returns the total time span of this list.
 boolean hasOverlapping(DateRangeI dr)
          Returns if there is at least one time span in this list that overlaps the time span.
 int indexOf(TimeSpan ts)
          Return index of ts or -1 if not found.
 boolean isTimeSpanInListOverlapping(DateRangeI dateRange)
          Checks to see if one or more of the activities in this overlaps (exclusive) dateRange.
 TimeSpan remove(int index)
           
 boolean remove(TimeSpan ts)
           
 boolean removeAll(java.util.Collection c)
           
 boolean removeAll(TimeSpan[] timeSpans)
           
 boolean removeAll(TimeSpanList c)
           
 void removeTimeSpanListListener(TimeSpanListListener l)
          Removes a listener.
 void set(int ix, TimeSpan ts)
          Sets the timespan for the index.
 boolean setIgnoreTimeSpanListChangeEvents(boolean b)
          Sets if add/remove events sould be ignored.
 void setSize(int newSize)
          Sets the absolute size of this list.
 int size()
          Returns the size.
 void sort()
          Sorts the list in its natural order.
 void sort(java.util.Comparator c)
          Sorts the list in the order specified by the comparator.
 TimeSpan[] toArray()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeSpanList

public TimeSpanList()

TimeSpanList

public TimeSpanList(int initialCapacity)

TimeSpanList

public TimeSpanList(java.util.Collection c)
Constructor

Parameters:
c - Collection of TimeSpan objects.

TimeSpanList

public TimeSpanList(TimeSpanList tsList)
Constructor.

Parameters:
tsList - Collection of TimeSpan objects.

TimeSpanList

public TimeSpanList(TimeSpan[] timeSpans)

TimeSpanList

public TimeSpanList(TimeSpan[] timeSpans,
                    int from,
                    int to)
Constructs from an array, or part thereof.

Parameters:
timeSpans - The array
from - Use the elements from this index
to - Use the elements to this index
Method Detail

isTimeSpanInListOverlapping

public boolean isTimeSpanInListOverlapping(DateRangeI dateRange)
Checks to see if one or more of the activities in this overlaps (exclusive) dateRange.

Parameters:
dateRange - The date range to chek the list for
Returns:
If one or more of the activities in this list "touches" the day that 'date' is in.
See Also:
DateRangeI.isOverlapping(com.miginfocom.util.dates.DateRangeI)

getOverlapCluster

public TimeSpanList getOverlapCluster(DateRangeI overlapRange,
                                      boolean removeFound,
                                      boolean recursive)
Returns a new list with references to a sub set of the activities that are in this list.

Parameters:
overlapRange - The date range that the activities should overlap (exclusive) to be in the returned list.
removeFound - If true all TimeSpan object that are returned will be removed from this list. The effect is that the returned list will be "cut out" from this.
recursive - If true the overlapRange will continuously be expanded with all TimeSpan objects added to the returned list. The method will re-iterate until no overlapping ranges are found, effectively returning a list of TimeSpan objects that not other objects in the list overlaps.
Returns:
A new list with references to a sub set of the activities that are in this list. Not null.
See Also:
DateRangeI.isOverlapping(com.miginfocom.util.dates.DateRangeI)

getOverlapCluster

public TimeSpanList getOverlapCluster(DateRangeI overlapRange,
                                      java.util.Map substMap,
                                      boolean removeFound,
                                      boolean recursive)
Returns a new list with references to a sub set of the activities that are in this list.

Parameters:
overlapRange - The date range that the activities should overlap (exclusive) to be in the returned list.
substMap - For every TimeSpan in this tat is looked up to check for overlapping the map is asked to return the actual time span to check. This can be used to invoke this method on rounded time spans without actually changing (rounding) the time spans that this list holds. Can be null inwhich case it is not used, the time spans them selves is used as is.
removeFound - If true all TimeSpan object that are returned will be removed from this list. The effect is that the returned list will be "cut out" from this.
recursive - If true the overlapRange will continuously be expanded with all TimeSpan objects added to the returned list. The method will re-iterate until no overlapping ranges are found, effectively returning a list of TimeSpan objects that not other objects in the list overlaps.
Returns:
A new list with references to a sub set of the activities that are in this list. Not null.
See Also:
DateRangeI.isOverlapping(com.miginfocom.util.dates.DateRangeI)

contains

public boolean contains(TimeSpan o)
Returns if the actual object o is in this list

Parameters:
o - The object
Returns:
If the actual object o is in this list

hasOverlapping

public boolean hasOverlapping(DateRangeI dr)
Returns if there is at least one time span in this list that overlaps the time span.

Parameters:
dr - The date range to test. Not null.
Returns:
If there is at least one time span in this list that overlaps the time span.

divideIntoRanges

public TimeSpanList[] divideIntoRanges(TimeSpan[] spanList)
Divides this list into smaller lists, each spanning a certain date. Note that a TimeSpan can end upp in more than one of these TimeSpanLists if it overlaps more than one of the ranges.

Parameters:
spanList - The time spans (type TimeSpan) to divide the list into. Not null and can be unsorted/overlapping.

getTotalDateSpan

public MutableDateRange getTotalDateSpan()
Returns the total time span of this list. The smallest MutableDateRange that can contain all of the activeties in the list.

Returns:
Returns the total time span of this list. null only if the list is empty. Newly created and free to use.

sort

public void sort()
Sorts the list in its natural order.


sort

public void sort(java.util.Comparator c)
Sorts the list in the order specified by the comparator.

Parameters:
c - The comarator used to sort the list

cloneList

public TimeSpanList cloneList()
Creates a shallow copy

Returns:
A shallow copy;

get

public TimeSpan get(int ix)
Returns the timespan at ix.

Parameters:
ix - The index.
Returns:
The timespan at ix.

size

public int size()
Returns the size.

Returns:
The size

add

public void add(TimeSpan ts)

addAll

public void addAll(TimeSpanList c)

addAll

public void addAll(java.util.Collection c)

addAll

public void addAll(TimeSpan[] timeSpans)
Adds all of the elements in timeSpans to this list.

Parameters:
timeSpans - The spans to add. Not null.

addAll

public void addAll(TimeSpan[] timeSpans,
                   int from,
                   int to)
Adds all, or some, of the elements in timeSpans to this list.

Parameters:
timeSpans - The spans to add. Not null.
from - Use the elements from this index
to - Use the elements to this index, excluding.

add

public void add(int index,
                TimeSpan ts)

clear

public void clear(int newCap)
Disposes of the internal array.

Parameters:
newCap - The new capacity.

set

public void set(int ix,
                TimeSpan ts)
Sets the timespan for the index.

Parameters:
ix - The index. Must be < size;
ts - The timespan to set. May be null if condense() is called after anything is done with the list.

condense

public void condense()
Removes null elements and set the size to the number of elements that wasn't null.


setSize

public void setSize(int newSize)
Sets the absolute size of this list. If bigger than now, just allocate more and set elements to null. If smaller remove the last ones so the list becomes the right size.

Parameters:
newSize - The new Size

remove

public TimeSpan remove(int index)

remove

public boolean remove(TimeSpan ts)

indexOf

public int indexOf(TimeSpan ts)
Return index of ts or -1 if not found. Matched by identity and NOT equals.

Parameters:
ts - The timespane to match. Not null.
Returns:
The index or -1 if not found.

removeAll

public boolean removeAll(TimeSpanList c)

removeAll

public boolean removeAll(java.util.Collection c)

removeAll

public boolean removeAll(TimeSpan[] timeSpans)

toArray

public final TimeSpan[] toArray()

toString

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

addTimeSpanListListener

public void addTimeSpanListListener(TimeSpanListListener l)
Adds a listener that is notified of all changes to the list itself (add/remove). The list itself is the source.

Parameters:
l - The listener
See Also:
ListenerSet

addTimeSpanListListener

public void addTimeSpanListListener(TimeSpanListListener l,
                                    boolean asWeakRef)
Adds a listener that is notified of all changes to the list itself (size). The list itself is the source,.

Parameters:
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.
l - The listener.
See Also:
ListenerSet

removeTimeSpanListListener

public void removeTimeSpanListListener(TimeSpanListListener l)
Removes a listener.

Parameters:
l - the listener.

fireTimeSpanListListener

protected void fireTimeSpanListListener(TimeSpan[] timeSpans,
                                        int type)
Fires a list change event to all registerd listeners. Can be called to note that the structure has changed and all should be recreated. Doesn't do anything if events is turned off.

Parameters:
timeSpans - The affected time spans.
type - If added or removed. E.g. TimeSpanListEvent.ADDED.

fireDepositoryListChanged

public void fireDepositoryListChanged(TimeSpan[] timeSpans,
                                      int type,
                                      DateRangeI dateRange)
Fires a manual TimeSpanListEvent. If for instance a recurring activity was added its recurrency range is not inclded in the normal notification date range. A manual event needs to be fired for this.

Parameters:
timeSpans - The affected time spans.
type - If added or removed. E.g. TimeSpanListEvent.REMOVED.
dateRange - The total date span affected.

setIgnoreTimeSpanListChangeEvents

public boolean setIgnoreTimeSpanListChangeEvents(boolean b)
Sets if add/remove events sould be ignored. To used for batch changing without creating a lot of repaints.

Parameters:
b - true turns off events
See Also:
fireTimeSpanListListener(TimeSpan[], int)


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.