I have a list of objects containing a date range (..and other props) ie
|-(1) MyClass (BeginDate=01/01/2005 EndDate=03/16/2005)
|-(2) MyClass (BeginDate=05/08/2005 EndDate=07/26/2005)
|-(3) MyClass (BeginDate=02/12/2006 EndDate=09/05/2006)
|-(4) MyClass (BeginDate=04/26/2007 EndDate=10/17/2007)
What is the best way to store these objects that will allow me to
A) Search by date ie A search for "08/17/2006" => would return:
(3) MyClass (BeginDate=02/12/2006 EndDate=09/05/2006)
B) Iterate through all objects by date range (both ascending
and descending order)?
I thought about using a java.util.List with a Comparator. But it seems like I would have to resort the list every time I wanted to switch from ascending to descending order. I also considered using a TreeSet
, but I am unsure how to search it by date.
Any advice would be appreciated :)