View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.dcd.graph;
5   
6   import java.util.Comparator;
7   
8   /**
9    * Compares MemberNodes.  FieldNodes are smaller than ConstructorNodes
10   * which are smaller than MethodNodes.
11   */
12  public final class MemberNodeComparator implements Comparator<MemberNode> {
13  
14  	public static final MemberNodeComparator INSTANCE = new MemberNodeComparator();
15  
16  	private MemberNodeComparator() {
17  	}
18  
19  	public int compare(MemberNode node1, MemberNode node2) {
20  		if (node1 instanceof FieldNode) {
21  			if (node2 instanceof FieldNode) {
22  				return node1.compareTo(node2);
23  			} else {
24  				return -1;
25  			}
26  		} else if (node1 instanceof ConstructorNode) {
27  			if (node2 instanceof FieldNode) {
28  				return 1;
29  			} else if (node2 instanceof ConstructorNode) {
30  				return node1.compareTo(node2);
31  			} else {
32  				return -1;
33  			}
34  		} else {
35  			if (node2 instanceof MethodNode) {
36  				return node1.compareTo(node2);
37  			} else {
38  				return 1;
39  			}
40  		}
41  	}
42  }