View Javadoc

1   package org.apache.maven.jcoveragereport;
2   
3   /* ====================================================================
4    *   Copyright 2001-2004 The Apache Software Foundation.
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   * ====================================================================
18   */
19  
20  import java.util.Comparator;
21  
22  /**
23   * @author Emmanuel Venisse
24   * @version $Id: PackageComparator.java 170200 2005-05-15 06:24:19Z brett $
25   */
26  public class PackageComparator implements Comparator
27  {
28      public int compare(Object package1, Object package2)
29      {
30          if (package1 instanceof Package && package2 instanceof Package)
31          {
32              Package p1 = (Package) package1;
33              Package p2 = (Package) package2;
34              if (p1.getName() != null && p2.getName() != null)
35              {
36                  String lower1 = p1.getName().toLowerCase();
37                  String lower2 = p2.getName().toLowerCase();
38                  return lower1.compareTo(lower2);
39              }
40              else
41              {
42                  if (p1.getName() == null && p2.getName() == null)
43                  {
44                      return 0;
45                  }
46                  else
47                  {
48                      return -1;
49                  }
50              }
51          }
52          else
53          {
54              return -1;
55          }
56      }
57  }