KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javadoc > search > DocIndexItem


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.javadoc.search;
21
22
23 import java.net.URL JavaDoc;
24 import java.util.Comparator JavaDoc;
25
26
27 /**
28  * Represents one item found in document index.
29  * It's produced by {@link IndexSearchThread} and communicated
30  * back to {@link IndexSearch} UI.
31  *
32  * @author Petr Hrebejk
33  */

34 final class DocIndexItem extends Object JavaDoc {
35
36     /** Standard comparators */
37     public static final Comparator JavaDoc REFERENCE_COMPARATOR = new ReferenceComparator();
38     public static final Comparator JavaDoc TYPE_COMPARATOR = new TypeComparator();
39     public static final Comparator JavaDoc ALPHA_COMPARATOR = new AlphaComparator();
40
41     private String JavaDoc text = null;
42     private URL JavaDoc contextURL = null;
43     private String JavaDoc spec = null;
44     private String JavaDoc remark = null;
45     private String JavaDoc pckg = null;
46     private String JavaDoc declaringClass = null;
47
48     private int iconIndex = DocSearchIcons.ICON_NOTRESOLVED;
49
50     public DocIndexItem ( String JavaDoc text, String JavaDoc remark, URL JavaDoc contextURL, String JavaDoc spec ) {
51         this.text = text;
52         this.remark = remark;
53         this.contextURL = contextURL;
54         this.spec = spec;
55         if (spec != null ) { // spec format ../pckg/Classname.html
56
int offset = spec.startsWith("../")? 3: 0; // NOI18N
57
int length = spec.lastIndexOf('/');
58             length = length < 0? spec.length(): length + 1;
59             pckg = spec.substring(offset, length);
60 // System.out.println("DII.length: " + length);
61
// System.out.println("DII: " + length + ", " + pckg + " <- " + spec);
62
pckg = pckg.replace('/', '.');
63         }
64     }
65
66     public URL JavaDoc getURL () throws java.net.MalformedURLException JavaDoc {
67         return new URL JavaDoc( contextURL, spec );
68     }
69
70     public String JavaDoc 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 JavaDoc getRemark() {
86         return remark;
87     }
88
89     public void setRemark( String JavaDoc remark ) {
90         this.remark = remark;
91     }
92
93     public String JavaDoc getPackage() {
94         return pckg == null ? "" : pckg; // NOI18N
95
}
96
97     public void setPackage( String JavaDoc pckg ) {
98 // System.out.println("DII.set: " + pckg);
99
this.pckg = pckg;
100     }
101
102     /** Getter for property declaringClass.
103      * @return Value of property declaringClass.
104  */

105     public java.lang.String JavaDoc getDeclaringClass() {
106         return declaringClass;
107     }
108
109     /** Setter for property declaringClass.
110      * @param declaringClass New value of property declaringClass.
111  */

112     public void setDeclaringClass(java.lang.String JavaDoc declaringClass) {
113         this.declaringClass = declaringClass;
114     }
115     
116     /** Getter for property field.
117      * @return Value of property field.
118  */

119     public java.lang.String JavaDoc getField() {
120         return text != null ? text : ""; //NOI18N
121
}
122
123     /** Setter for property field.
124      * @param Value of property field.
125     */

126     public void setField(String JavaDoc text) {
127         this.text = text;
128     }
129
130     // COMPARATOR INNER CLASSES ----------------------------------------------------------------
131

132     static final class ReferenceComparator implements java.util.Comparator JavaDoc {
133
134         public int compare( Object JavaDoc dii1, Object JavaDoc 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 JavaDoc 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 JavaDoc {
151
152         public int compare( Object JavaDoc dii1, Object JavaDoc dii2 ) {
153             return ((DocIndexItem)dii1).getIconIndex() - ((DocIndexItem)dii2).getIconIndex();
154         }
155
156         public boolean equals( Object JavaDoc 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 JavaDoc {
167
168         public int compare( Object JavaDoc dii1, Object JavaDoc dii2 ) {
169             return ((DocIndexItem)dii1).toString().compareTo( ((DocIndexItem)dii2).toString() );
170         }
171
172         public boolean equals( Object JavaDoc comp ) {
173             return ( comp instanceof AlphaComparator );
174         }
175
176         public int hashCode() {
177             return 33;
178         }
179     }
180 }
181
Popular Tags