1 19 20 package org.netbeans.api.java.comparators; 21 22 import org.openide.src.FieldElement; 23 import java.util.Comparator ; 24 25 class FieldComparator extends MemberNameComparator { 26 private Comparator typeComparator; 27 28 protected FieldComparator(int type) { 29 super(type); 30 if ((type&TYPE)!=0) { 31 typeComparator=TypeComparator.createComparator(type&SOURCE); 32 } 33 } 34 35 public int compare(Object o1, Object o2) { 36 FieldElement fe1=(FieldElement)o1; 37 FieldElement fe2=(FieldElement)o2; 38 int result; 39 40 if ((type&NAME)!=0) { 41 result = super.compare(fe1, fe2); 42 if (result!=0) return result; 43 } 44 if (typeComparator!=null) { 45 result = typeComparator.compare(fe1, fe2); 46 if (result!=0) return result; 47 } 48 if ((type&MODIFIERS)!=0) { 49 result = fe1.getModifiersMask()-fe2.getModifiersMask(); 50 51 if (result<0) return -1; 52 if (result==0) return 0; 53 return 1; 54 } 55 return 0; 56 } 57 58 static Comparator createComparator(int type) { 59 return new FieldComparator(type); 60 } 61 62 } 63 64 | Popular Tags |