1 19 20 package org.netbeans.modules.javadoc.search; 21 22 23 import java.net.URL ; 24 import java.util.Comparator ; 25 26 27 34 final class DocIndexItem extends Object { 35 36 37 public static final Comparator REFERENCE_COMPARATOR = new ReferenceComparator(); 38 public static final Comparator TYPE_COMPARATOR = new TypeComparator(); 39 public static final Comparator ALPHA_COMPARATOR = new AlphaComparator(); 40 41 private String text = null; 42 private URL contextURL = null; 43 private String spec = null; 44 private String remark = null; 45 private String pckg = null; 46 private String declaringClass = null; 47 48 private int iconIndex = DocSearchIcons.ICON_NOTRESOLVED; 49 50 public DocIndexItem ( String text, String remark, URL contextURL, String spec ) { 51 this.text = text; 52 this.remark = remark; 53 this.contextURL = contextURL; 54 this.spec = spec; 55 if (spec != null ) { int offset = spec.startsWith("../")? 3: 0; int length = spec.lastIndexOf('/'); 58 length = length < 0? spec.length(): length + 1; 59 pckg = spec.substring(offset, length); 60 pckg = pckg.replace('/', '.'); 63 } 64 } 65 66 public URL getURL () throws java.net.MalformedURLException { 67 return new URL ( contextURL, spec ); 68 } 69 70 public String toString() { 71 if ( remark != null ) 72 return text + remark; 73 else 74 return text; 75 } 76 77 public int getIconIndex() { 78 return iconIndex; 79 } 80 81 public void setIconIndex( int iconIndex ) { 82 this.iconIndex = iconIndex; 83 } 84 85 public String getRemark() { 86 return remark; 87 } 88 89 public void setRemark( String remark ) { 90 this.remark = remark; 91 } 92 93 public String getPackage() { 94 return pckg == null ? "" : pckg; } 96 97 public void setPackage( String pckg ) { 98 this.pckg = pckg; 100 } 101 102 105 public java.lang.String getDeclaringClass() { 106 return declaringClass; 107 } 108 109 112 public void setDeclaringClass(java.lang.String declaringClass) { 113 this.declaringClass = declaringClass; 114 } 115 116 119 public java.lang.String getField() { 120 return text != null ? text : ""; } 122 123 126 public void setField(String text) { 127 this.text = text; 128 } 129 130 132 static final class ReferenceComparator implements java.util.Comparator { 133 134 public int compare( Object dii1, Object dii2 ) { 135 int res = ((DocIndexItem)dii1).getPackage().compareTo( ((DocIndexItem)dii2).getPackage() ); 136 137 return res != 0 ? res : DocIndexItem.ALPHA_COMPARATOR.compare( dii1, dii2 ); 138 } 139 140 public boolean equals( Object comp ) { 141 return ( comp instanceof ReferenceComparator ); 142 } 143 144 public int hashCode() { 145 return 353; 146 } 147 148 } 149 150 static final class TypeComparator implements java.util.Comparator { 151 152 public int compare( Object dii1, Object dii2 ) { 153 return ((DocIndexItem)dii1).getIconIndex() - ((DocIndexItem)dii2).getIconIndex(); 154 } 155 156 public boolean equals( Object comp ) { 157 return ( comp instanceof TypeComparator ); 158 } 159 160 public int hashCode() { 161 return -34; 162 } 163 164 } 165 166 static final class AlphaComparator implements java.util.Comparator { 167 168 public int compare( Object dii1, Object dii2 ) { 169 return ((DocIndexItem)dii1).toString().compareTo( ((DocIndexItem)dii2).toString() ); 170 } 171 172 public boolean equals( Object comp ) { 173 return ( comp instanceof AlphaComparator ); 174 } 175 176 public int hashCode() { 177 return 33; 178 } 179 } 180 } 181 | Popular Tags |