21
21
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
22
22
* portions copyright 2005 Trond Norbye. All rights reserved.
23
23
* Use is subject to license terms.
24
+ * Portions Copyright (c) 2019, Chris Fraire <[email protected] >.
24
25
*/
25
26
package org .opengrok .indexer .search ;
26
27
31
32
*
32
33
* @author Trond Norbye
33
34
*/
34
- public class Hit implements Comparable < Hit > {
35
+ public class Hit {
35
36
/**
36
37
* Holds value of property filename.
37
38
*/
38
- private String filename ;
39
+ private final String filename ;
39
40
40
41
/**
41
42
* Holds value of property directory.
42
43
*/
43
- private String directory ;
44
+ private final String directory ;
44
45
45
46
/**
46
47
* Holds value of property line.
@@ -65,17 +66,19 @@ public class Hit implements Comparable<Hit> {
65
66
/**
66
67
* path relative to source root.
67
68
*/
68
- private String path ;
69
+ private final String path ;
69
70
70
71
/**
71
- * Creates a new instance of Hit.
72
+ * Creates a new, possibly-defined instance.
73
+ *
74
+ * @param filename The name of the file this hit represents
72
75
*/
73
- public Hit () {
74
- this (null , null , null , false , false );
76
+ public Hit (String filename ) {
77
+ this (filename , null , null , false , false );
75
78
}
76
79
77
80
/**
78
- * Creates a new instance of Hit .
81
+ * Creates a new, possibly-defined instance .
79
82
*
80
83
* @param filename The name of the file this hit represents
81
84
* @param line The line containing the match
@@ -88,115 +91,55 @@ public Hit(String filename, String line, String lineno, boolean binary, boolean
88
91
File file = new File (filename );
89
92
this .path = filename ;
90
93
this .filename = file .getName ();
91
- this . directory = file .getParent ();
92
- if (directory == null ) {
94
+ final String parent = file .getParent ();
95
+ if (parent == null ) {
93
96
directory = "" ;
97
+ } else {
98
+ directory = parent ;
94
99
}
100
+ } else {
101
+ this .path = "" ;
102
+ this .filename = "" ;
103
+ this .directory = "" ;
95
104
}
96
105
this .line = line ;
97
106
this .lineno = lineno ;
98
107
this .binary = binary ;
99
108
this .alt = alt ;
100
109
}
101
110
102
- /**
103
- * Getter for property filename.
104
- *
105
- * @return Value of property filename.
106
- */
107
111
public String getFilename () {
108
112
return this .filename ;
109
113
}
110
114
111
- /**
112
- * Getter for property path.
113
- *
114
- * @return Value of property path.
115
- */
116
115
public String getPath () {
117
116
return this .path ;
118
117
}
119
118
120
- /**
121
- * Getter for property directory.
122
- *
123
- * @return Value of property directory
124
- */
125
119
public String getDirectory () {
126
120
return this .directory ;
127
121
}
128
122
129
- /**
130
- * Setter for property filename.
131
- *
132
- * @param filename New value of property filename.
133
- */
134
- public void setFilename (String filename ) {
135
- this .filename = filename ;
136
- }
137
-
138
- /**
139
- * Getter for property line.
140
- *
141
- * @return Value of property line.
142
- */
143
123
public String getLine () {
144
124
return this .line ;
145
125
}
146
126
147
- /**
148
- * Setter for property line.
149
- *
150
- * @param line New value of property line.
151
- */
152
127
public void setLine (String line ) {
153
128
this .line = line ;
154
129
}
155
130
156
- /**
157
- * Getter for property line no.
158
- *
159
- * @return Value of property line no.
160
- */
161
131
public String getLineno () {
162
132
return this .lineno ;
163
133
}
164
134
165
- /**
166
- * Setter for property line no.
167
- *
168
- * @param lineno New value of property line no.
169
- */
170
135
public void setLineno (String lineno ) {
171
136
this .lineno = lineno ;
172
137
}
173
138
174
- /**
175
- * Compare this object to another hit (in order to implement the comparable interface).
176
- *
177
- * @param o The object to compare this object with
178
- *
179
- * @return the result of a toString().compareTo() of the filename
180
- */
181
- @ Override
182
- public int compareTo (Hit o ) throws ClassCastException {
183
- return filename .compareTo (o .filename );
184
- }
185
-
186
- /**
187
- * Getter for property binary.
188
- *
189
- * @return Value of property binary.
190
- */
191
139
public boolean isBinary () {
192
140
return this .binary ;
193
141
}
194
142
195
- /**
196
- * Setter for property binary.
197
- *
198
- * @param binary New value of property binary.
199
- */
200
143
public void setBinary (boolean binary ) {
201
144
this .binary = binary ;
202
145
}
@@ -206,19 +149,11 @@ public void setBinary(boolean binary) {
206
149
*/
207
150
private String tag ;
208
151
209
- /**
210
- * Getter for property tag.
211
- * @return Value of property tag.
212
- */
213
152
public String getTag () {
214
153
215
154
return this .tag ;
216
155
}
217
156
218
- /**
219
- * Setter for property tag.
220
- * @param tag New value of property tag.
221
- */
222
157
public void setTag (String tag ) {
223
158
224
159
this .tag = tag ;
@@ -231,23 +166,4 @@ public void setTag(String tag) {
231
166
public boolean getAlt () {
232
167
return alt ;
233
168
}
234
-
235
- /**
236
- * Check if two objects are equal. Only consider the {@code filename} field
237
- * to match the return value of the {@link #compareTo(Hit)} method.
238
- * @param o the object to compare with
239
- * @return true if the filenames are equal
240
- */
241
- @ Override
242
- public boolean equals (Object o ) {
243
- if (o instanceof Hit ) {
244
- return compareTo ((Hit ) o ) == 0 ;
245
- }
246
- return false ;
247
- }
248
-
249
- @ Override
250
- public int hashCode () {
251
- return filename .hashCode ();
252
- }
253
169
}
0 commit comments