|
50 | 50 | * file system. {@code Path} defines the {@link #getFileName() getFileName}, |
51 | 51 | * {@link #getParent getParent}, {@link #getRoot getRoot}, and {@link #subpath |
52 | 52 | * subpath} methods to access the path components or a subsequence of its name |
53 | | - * elements, and {@link #getExtension() getExtension} to obtain its extension. |
| 53 | + * elements. |
54 | 54 | * |
55 | 55 | * <p> In addition to accessing the components of a path, a {@code Path} also |
56 | 56 | * defines the {@link #resolve(Path) resolve} and {@link #resolveSibling(Path) |
@@ -249,63 +249,6 @@ public static Path of(URI uri) { |
249 | 249 | */ |
250 | 250 | Path getFileName(); |
251 | 251 |
|
252 | | - /** |
253 | | - * Returns the file extension of this path's file name as a {@code String}. |
254 | | - * The extension is derived from this {@code Path} by obtaining the |
255 | | - * {@linkplain #getFileName file name element}, deriving its {@linkplain |
256 | | - * #toString string representation}, and then extracting a substring |
257 | | - * determined by the position of a period character ('.', U+002E FULL STOP) |
258 | | - * within the file name string. If the file name element is {@code null}, |
259 | | - * or if the file name string does not contain a period character, or if |
260 | | - * the only period in the file name string is its first character, then |
261 | | - * the extension is {@code null}. Otherwise, the extension is the substring |
262 | | - * after the last period in the file name string. If this last period is |
263 | | - * also the last character in the file name string, then the extension is |
264 | | - * {@linkplain String#isEmpty empty}. |
265 | | - * |
266 | | - * @implSpec |
267 | | - * The default implementation is equivalent for this path to: |
268 | | - * <pre>{@code |
269 | | - * int lastPeriod = fileName.lastIndexOf('.'); |
270 | | - * if (lastPeriod <= 0) |
271 | | - * return null; |
272 | | - * return (lastPeriod == fileName.length() - 1) |
273 | | - * ? "" |
274 | | - * : fileName.substring(lastPeriod + 1); |
275 | | - * }</pre> |
276 | | - * |
277 | | - * @return the file name extension of this path, which might be the |
278 | | - * empty string, or {@code null} if no extension is found |
279 | | - * |
280 | | - * @since 20 |
281 | | - */ |
282 | | - default String getExtension() { |
283 | | - Path fileName = getFileName(); |
284 | | - if (fileName == null) |
285 | | - return null; |
286 | | - |
287 | | - String fileNameString = fileName.toString(); |
288 | | - int length = fileNameString.length(); |
289 | | - |
290 | | - // An empty or unity length file name string has a null extension |
291 | | - if (length > 1) { |
292 | | - int lastPeriodIndex = fileNameString.lastIndexOf('.'); |
293 | | - |
294 | | - // Indeterminate if there is no period character or |
295 | | - // only the first character is a period character |
296 | | - if (lastPeriodIndex > 0) { |
297 | | - if (lastPeriodIndex == length - 1) { |
298 | | - // empty string |
299 | | - return ""; |
300 | | - } else { |
301 | | - return fileNameString.substring(lastPeriodIndex + 1); |
302 | | - } |
303 | | - } |
304 | | - } |
305 | | - |
306 | | - return null; |
307 | | - } |
308 | | - |
309 | 252 | /** |
310 | 253 | * Returns the <em>parent path</em>, or {@code null} if this path does not |
311 | 254 | * have a parent. |
|
0 commit comments