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

Quick Search    Search Deep

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