View Javadoc

1   // $Id:NameComparator.java 62 2008-04-20 12:28:56Z me $
2   /*
3    * xsAnalyzer - XML schema analyzing tool. Copyright (C) 2008 Michael Engelhardt
4    * 
5    * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6    * License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7    * version.
8    * 
9    * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
10   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11   * 
12   * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
13   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14   */
15  /**
16   * 
17   */
18  package de.mindcrimeilab.xsanalyzer.util;
19  
20  import java.util.Comparator;
21  
22  import org.apache.xerces.xs.XSObject;
23  
24  /**
25   * @author Michael Engelhardt<me@mindcrime-ilab.de>
26   * @author $Author:me $
27   * @version $Revision:62 $
28   * 
29   */
30  public class NameComparator implements Comparator<XSObject> {
31  
32      /*
33       * (non-Javadoc)
34       * 
35       * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
36       */
37      @Override
38      public int compare(XSObject o1, XSObject o2) {
39          int ret = 0;
40          if (null != o1) {
41              if (null != o2) {
42                  final String name1 = o1.getName();
43                  final String name2 = o2.getName();
44                  if (null == name1 && null != name2) {
45                      ret = -1;
46                  }
47                  else if (null != name1 && null == name2) {
48                      ret = 1;
49                  }
50                  else if (null == name1 && null == name2) {
51                      ret = 0;
52                  }
53                  else {
54                      ret = (null == name1) ? -1 : name1.compareTo(name2);
55                  }
56              }
57              else {
58                  ret = -1;
59              }
60          }
61          else {
62              if (o2 != null) {
63                  ret = 1;
64              }
65              else {
66                  ret = 0;
67              }
68          }
69          return ret;
70      }
71  }