Skip to content

Commit

Permalink
Change getShortName to getNameWithoutExtension, re #15
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Jan 8, 2025
1 parent 8b969dd commit bf91ff2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
15 changes: 8 additions & 7 deletions src/main/java/org/libj/net/URIs.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,18 @@ public static String getName(final URI uri) {
}

/**
* Returns the simple name of the file or directory denoted by the specified {@link URI}. This is just the last name in the name
* sequence of {@code uri}, with its dot-extension removed if present. If the name sequence of {@code uri} is empty, then the empty
* string is returned.
* Returns the last name in the {@code '/'}-delimited sequence of path segments of the given {@code uri} with its dot-prefixed
* extension removed. The unmodified {@linkplain URIs#getName(URI) name of the uri} is returned if no dot-prefixed extension is
* present.
*
* @param uri The {@link URI}.
* @return The simple name of the file or directory denoted by the specified {@link URI}, or the empty string if the name sequence
* of {@code uri} is empty.
* @return The last name in the {@code '/'}-delimited sequence of path segments of the given {@code uri} with its dot-prefixed
* extension removed.
* @throws NullPointerException If {@code uri} is null.
* @see StringPaths#getNameWithoutExtension(String)
*/
public static String getSimpleName(final URI uri) {
return StringPaths.getSimpleName(uri.toString());
public static String getNameWithoutExtension(final URI uri) {
return StringPaths.getNameWithoutExtension(uri.toString());
}

/**
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/org/libj/net/URLs.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,17 +548,18 @@ public static String getName(final URL url) {
}

/**
* Returns the simple name of the file or directory denoted by the specified {@link URL}. This is just the last name in the name
* sequence of {@code url}, with its dot-extension removed if present. If the name sequence of {@code url} is empty, then the empty
* string is returned.
* Returns the last name in the {@code '/'}-delimited sequence of path segments of the given {@code url} with its dot-prefixed
* extension removed. The unmodified {@linkplain URLs#getName(URL) name of the url} is returned if no dot-prefixed extension is
* present.
*
* @param url The {@link URL}.
* @return The simple name of the file or directory denoted by the specified {@link URL}, or the empty string if the name sequence
* of {@code url} is empty.
* @return The last name in the {@code '/'}-delimited sequence of path segments of the given {@code url} with its dot-prefixed
* extension removed.
* @throws NullPointerException If {@code url} is null.
* @see StringPaths#getNameWithoutExtension(String)
*/
public static String getSimpleName(final URL url) {
return StringPaths.getSimpleName(url.toString());
public static String getNameWithoutExtension(final URL url) {
return StringPaths.getNameWithoutExtension(url.toString());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/libj/net/URIsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public void testGetName() throws Exception {

@Test
public void testGetSimpleName() throws Exception {
assertEquals("share", URIs.getSimpleName(new URI("file:///usr/share/../share")));
assertEquals("lib", URIs.getSimpleName(new URI("file:///usr/share/../share/../lib")));
assertEquals("var", URIs.getSimpleName(new URI("file:///usr/share/../share/../lib/../../var")));
assertEquals("resolv", URIs.getSimpleName(new URI("file:///etc/resolv.conf")));
assertEquals("share", URIs.getNameWithoutExtension(new URI("file:///usr/share/../share")));
assertEquals("lib", URIs.getNameWithoutExtension(new URI("file:///usr/share/../share/../lib")));
assertEquals("var", URIs.getNameWithoutExtension(new URI("file:///usr/share/../share/../lib/../../var")));
assertEquals("resolv", URIs.getNameWithoutExtension(new URI("file:///etc/resolv.conf")));
}

@Test
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/libj/net/URLsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ public void testGetName() throws Exception {
@Test
public void testGetSimpleName() throws Exception {
assertNull(URLs.canonicalize(null));
assertEquals("share", URLs.getSimpleName(new URL("file:///usr/share/../share")));
assertEquals("lib", URLs.getSimpleName(new URL("file:///usr/share/../share/../lib")));
assertEquals("var", URLs.getSimpleName(new URL("file:///usr/share/../share/../lib/../../var")));
assertEquals("resolv", URLs.getSimpleName(new URL("file:///etc/resolv.conf")));
assertEquals("share", URLs.getNameWithoutExtension(new URL("file:///usr/share/../share")));
assertEquals("lib", URLs.getNameWithoutExtension(new URL("file:///usr/share/../share/../lib")));
assertEquals("var", URLs.getNameWithoutExtension(new URL("file:///usr/share/../share/../lib/../../var")));
assertEquals("resolv", URLs.getNameWithoutExtension(new URL("file:///etc/resolv.conf")));
}

@Test
Expand Down

0 comments on commit bf91ff2

Please sign in to comment.