de.enough.polish.calendar
Class CalendarEntryList

java.lang.Object
  extended by de.enough.polish.calendar.CalendarEntryList
All Implemented Interfaces:
Comparator

public class CalendarEntryList
extends Object
implements Comparator

Allows to sort and filter several calendar entries easily

Copyright Enough Software 2010

Author:
Robert Virkus, j2mepolish@enough.de

Constructor Summary
CalendarEntryList()
           
 
Method Summary
 void add(CalendarEntry entry)
          Adds a CalendarEntry to this list
 void add(CalendarEntryList entryList)
          Adds a list of entries.
 void clear()
          Clears the complete list, i.e.
 int compare(Object o1, Object o2)
          Compares two objects.
 boolean containsEntryWithGuid(long guid)
          Checks if this list contains at least one CalendaryEntry with the specified global unique ID
 CalendarEntry[] getEntries()
          Retrieves all entries of this list sorted by their start date (and then their summary)
 CalendarEntry[] getEntriesForDay(TimePoint day)
          Retrieves all entries for the specified day
 CalendarEntryList getEntriesForPeriod(TimePeriod period)
          Retrieves all entries for the specified time period.
 Object[] getInternalArray()
          Provides access to the internal array of this list.
 boolean remove(CalendarEntry entry)
          Removes a CalendarEntry from this list
 boolean remove(long guid)
          Removes a CalendarEntry from this list
 CalendarEntry[] searchEntries(String searchString, boolean onlyAtStart)
          Searches entries that start or include the specified search term in their summary.
 int size()
          Retrieves the size of this list
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CalendarEntryList

public CalendarEntryList()
Method Detail

add

public void add(CalendarEntry entry)
Adds a CalendarEntry to this list

Parameters:
entry - the entry

add

public void add(CalendarEntryList entryList)
Adds a list of entries.

Parameters:
entryList - The list with the entries to add.

remove

public boolean remove(CalendarEntry entry)
Removes a CalendarEntry from this list

Parameters:
entry - the entry
Returns:
true when the entry was found and removed

remove

public boolean remove(long guid)
Removes a CalendarEntry from this list

Parameters:
guid - the GUID of the entry that should be removed
Returns:
true when the entry was found and removed

clear

public void clear()
Clears the complete list, i.e. removes all entries.


size

public int size()
Retrieves the size of this list

Returns:
the size of this list

getEntries

public CalendarEntry[] getEntries()
Retrieves all entries of this list sorted by their start date (and then their summary)

Returns:
an array of all entries, can be empty but not null

getEntriesForDay

public CalendarEntry[] getEntriesForDay(TimePoint day)
Retrieves all entries for the specified day

Parameters:
day - the day
Returns:
all entries for the day, sorted by time and summary. Can be empty but not null.

getEntriesForPeriod

public CalendarEntryList getEntriesForPeriod(TimePeriod period)
Retrieves all entries for the specified time period.

Parameters:
period -
Returns:
returnList All entries which lies in the specified time period. Can be empty but not null.

searchEntries

public CalendarEntry[] searchEntries(String searchString,
                                     boolean onlyAtStart)
Searches entries that start or include the specified search term in their summary.

Parameters:
searchString - the search term
onlyAtStart - true when the entry summary should start with the given search term
Returns:
an array of found entries, may be empty but not null

compare

public int compare(Object o1,
                   Object o2)
Description copied from interface: Comparator
Compares two objects. In the foregoing description, the notation sgn(expression) designates the mathematical signum function, which is defined to return one of -1, 0, or 1 according to whether the value of expression is negative, zero or positive. The implementor must ensure that sgn(compare(x, y)) == -sgn(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.) The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0. Finally, the implementor must ensure that compare(x, y)==0 implies that sgn(compare(x, z))==sgn(compare(y, z)) for all z. It is generally the case, but not strictly required that (compare(x, y)==0) == (x.equals(y)). Generally speaking, any comparator that violates this condition should clearly indicate this fact. The recommended language is "Note: this comparator imposes orderings that are inconsistent with equals."

Specified by:
compare in interface Comparator
Parameters:
o1 - the first object
o2 - the object that is compared with o1
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

getInternalArray

public Object[] getInternalArray()
Provides access to the internal array of this list.

Returns:
the internal array, may contain null values

containsEntryWithGuid

public boolean containsEntryWithGuid(long guid)
Checks if this list contains at least one CalendaryEntry with the specified global unique ID

Parameters:
guid - the global unique ID of the CalendarEntry
Returns:
true when there is at least one entry with that GUID already present in this list.