Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: openfuture/bugbase/model/BugReportDateComparator.java


1   package openfuture.bugbase.model;
2   /*
3    * This library is free software; you can redistribute it and/or
4    * modify it under the terms of the GNU Lesser General Public
5    * License as published by the Free Software Foundation; either
6    * version 2 of the License, or (at your option) any later version.<p>
7    *
8    * This library is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11   * Lesser General Public License for more details.<p>
12   *
13   * You should have received a copy of the GNU Lesser General Public
14   * License along with this library; if not, write to the Free Software
15   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA<br>
16   * http://www.gnu.org/copyleft/lesser.html
17   */
18  
19  /**
20   * Compares two {@link openfuture.bugbase.domain.BugReport bug reports} by
21   * their {@link openfuture.bugbase.domain.BugReport#getDateReported() 
22   *              reported date}. If they are equal,
23   * {@link openfuture.bugbase.domain.BugReport#getDateStarted() 
24   *        starting date} is used for comparison. If these are also equal,
25   * their {@link openfuture.bugbase.domain.BugReport#getId() ID} is used.<p>
26   * 
27   *
28   *
29   * Created: Mon Apr 03 20:51:54 2000
30   *
31   * @author Wolfgang Reissenberger
32   * @version $Revision: 1.3 $
33   */
34  // Configuration Management Information: 
35  // -------------------------------------
36  // $Id: BugReportDateComparator.java,v 1.3 2001/07/01 06:46:30 wreissen Exp $
37  //
38  // Version History:
39  // ----------------
40  // $Log: BugReportDateComparator.java,v $
41  // Revision 1.3  2001/07/01 06:46:30  wreissen
42  // fixed errors in DOS/Unix-translation.
43  //
44  // Revision 1.2  2001/03/12 09:21:53  wreissen
45  // in case of equal values, the report IDs are compared.
46  //
47  // Revision 1.1  2000/09/27 15:53:24  wreissen
48  // moved to openfuture.
49  //
50  // Revision 1.2  2000/04/25 05:12:29  wreissen
51  // BugReport moved to package openfuture.bugbase.domain
52  //
53  // Revision 1.1  2000/04/04 05:20:37  wreissen
54  // initial version.
55  //
56  //
57  // ***********************************************************************************
58  
59  import openfuture.bugbase.domain.BugReport;
60  import java.util.Comparator;
61  import java.util.Date;
62  
63  public class BugReportDateComparator implements Comparator {
64      
65      public BugReportDateComparator() {}
66      
67      /**
68       * Compares two {@link openfuture.bugbase.domain.BugReport bug reports} by
69       * their {@link openfuture.bugbase.domain.BugReport#getDateReported() 
70       *              reported date}. If they are equal,
71       * {@link openfuture.bugbase.domain.BugReport#getDateStarted() 
72       *        starting date} is used for comparison. If these are also equal,
73       * their {@link openfuture.bugbase.domain.BugReport#getId() ID} is used.
74       *
75       * @param o1 a value of type 'Object'
76       * @param o2 a value of type 'Object'
77       * @return -1 if <code>o1</code> is smaller, 1 if <code>o1</code>
78       *         is greater and 0 of <code>o1</code> is equal to 
79       *         <code>o2</code>.
80       */
81      public int compare(Object o1, Object o2) {
82    if (o1 instanceof BugReport && o2 instanceof BugReport) {
83  
84        BugReport report1 = (BugReport)o1;
85        BugReport report2 = (BugReport)o2;
86  
87        Date o1Date = report1.getDateReported();
88        Date o2Date = report2.getDateReported();
89  
90        int result = dateCompare(o1Date, o2Date);
91  
92        if (result != 0) return result;
93        return(BugReportIdComparator.compareId(report1.getId(),
94                 report2.getId()));
95    } else {
96        throw new IllegalArgumentException();
97    }
98      }
99  
100 
101 
102     /**
103      * Compare two dates. <code>null</code> is the smallest element
104      * of the order.
105      *
106      * @param d1 a value of type 'Date'
107      * @param d2 a value of type 'Date'
108      * @return -1 if <code>d1</code> is smaller, 1 if <code>d1</code>
109      *         is greater and 0 of <code>d1</code> is equal to 
110      *         <code>d2</code>.
111      */
112     public int dateCompare(Date d1, Date d2) {
113   if (d1 == null) {
114       if (d2 == null) {
115     return 0;
116       } else {
117     return -1;
118       }
119   } else {
120       if (d2 == null) {
121     return 1;
122       } else {
123     return d1.compareTo(d2);
124       }
125   }
126     }    
127 
128 } // BugReportDateComparator