package Java;
import java.net.URI;
import static Java.URIs.schemedPattern;
/** @see
* URI generic syntax §4.1, URI reference
*/
public final class URI_References {
private URI_References() {}
/** Returns the given directory if it ends with a slash character ‘/’ or is empty,
* otherwise returns a copy of the directory with a slash character appended.
*
* @param directory A URI reference to a directory.
* @see
* URI generic syntax §4.1, URI reference
*/
public static String enslash( String directory ) {
if( !( directory.isEmpty() || directory.endsWith("/") )) directory += "/";
return directory; }
/** Whether `ref` has a path that ends with the given extension.
*/
public static boolean hasExtension( final String extension, final URI ref ) {
final String path = ref.getPath();
return path != null && path.endsWith( extension ); }
/** Returns true if URI reference `ref` begins with either a scheme or authority, false otherwise.
*
* @see
* URI generic syntax §4.1, URI reference
* @see
* URI generic syntax §3.1, Scheme
* @see
* URI generic syntax §3.2, Authority
*/
public static boolean isRemote( final String ref ) {
return ref.startsWith("//") || schemedPattern.matcher(ref).lookingAt(); }
/** Returns true if URI reference `ref` begins with either a scheme or authority, false otherwise.
*
* @see
* URI generic syntax §4.1, URI reference
* @see
* URI generic syntax §3.1, Scheme
* @see
* URI generic syntax §3.2, Authority
*/
public static boolean isRemote( final URI ref ) {
return ref.getScheme() != null || ref.getRawAuthority() != null; }}
// Copyright © 2022 Michael Allan. Licence MIT.