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

Quick Search    Search Deep

Source code: openfuture/bugbase/model/BugReportDoctorComparator.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  import java.util.Comparator;
20  import openfuture.bugbase.domain.BugReport;
21  
22  // Configuration Management Information: 
23  // -------------------------------------
24  // $Id: BugReportDoctorComparator.java,v 1.3 2001/07/01 06:46:30 wreissen Exp $
25  //
26  // Version History:
27  // ----------------
28  // $Log: BugReportDoctorComparator.java,v $
29  // Revision 1.3  2001/07/01 06:46:30  wreissen
30  // fixed errors in DOS/Unix-translation.
31  //
32  // Revision 1.1  2001/04/03 05:21:43  wreissen
33  // initial version
34  //
35  //
36  // ***********************************************************************************
37  /**
38   * Compare two objects. If <code>o1</code> and <code>o1</code> are
39   * {@link openfuture.bugbase.domain.BugReport bug reports}, their
40   * {@link openfuture.bugbase.domain.BugReport#getDoctor() doctor}
41   * is compared.<p>
42   *
43   *
44   * Created: Fri Mar 30 23:45:19 2001
45   *
46   * @author <a href="mailto:wolfgang@openfuture.de">Wolfgang Reissenberger</a>
47   * @version $Revision: 1.3 $
48   */
49  
50  public class BugReportDoctorComparator implements Comparator {
51      
52      /*
53       * Compare two objects. If <code>o1</code> and <code>o1</code> are
54       * {@link openfuture.bugbase.domain.BugReport bug reports}, their
55       * {@link openfuture.bugbase.domain.BugReport#getDoctor() doctor}
56       * is compared.
57       *
58       * @param o1 a value of type 'Object'
59       * @param o2 a value of type 'Object'
60       * @return -1 if <code>o1</code> is smaller, 1 if <code>o1</code>
61       *         is greater and 0 of <code>o1</code> is equal to 
62       *         <code>o2</code>.
63       */
64       public int compare(Object o1, Object o2) {
65    if (o1 == null && o2 == null) return 0;
66    if (o1 == null) return -1;
67    if (o2 == null) return 1;
68  
69    if (o1 instanceof BugReport && o2 instanceof BugReport) {
70        BugReport report1 = (BugReport)o1;
71        BugReport report2 = (BugReport)o2;
72  
73        if (report1.getDoctor() == null && report2.getDoctor() == null)
74      return 0;
75        if (report1.getDoctor() == null) return -1;
76        if (report2.getDoctor() == null) return 1;
77  
78        int result = report1.getDoctor().compareTo(report2.getDoctor());
79  
80        if (result != 0) return result;
81        return(BugReportIdComparator.compareId(report1.getId(),
82                 report2.getId()));
83  
84    } else {
85        throw new IllegalArgumentException();
86    }
87      }
88  } // BugReportDoctorComparator