Package com.github.mizool.core
Class UrlRef
java.lang.Object
com.github.mizool.core.UrlRef
Safely stores a reference to a URL and allows conversion to
Features
URI
and URL
at any time. Features
-
Unlike
URL
, this class ensures that invocations ofequals()
andhashCode()
never trigger network requests, making this class suitable for collections. For details, see the SonarQube rule "URL.hashCode" and "URL.equals" should be avoided. -
When constructing a
UrlRef
instance, it is ensured that it later can be converted to both aURI
and aURL
. -
Creating a
UrlRef
never throws checked exceptions. -
Unlike
URI
, anUrlRef
instance can be used to build a child URI - just likeURL
with itstwo-arg constructor
.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
UrlRef
- Throws:
NullPointerException
- ifuri
isnull
IllegalArgumentException
- if the resultingUrlRef
would cause exceptions when converted toURL
-
UrlRef
- Throws:
NullPointerException
- ifurl
isnull
IllegalArgumentException
- if the resultingUrlRef
would cause exceptions when converted toURI
-
UrlRef
- Throws:
NullPointerException
- ifspec
isnull
IllegalArgumentException
- if the resultingUrlRef
would cause exceptions when converted toURI
orURL
-
-
Method Details
-
resolve
Creates a newUrlRef
by combining the URL referenced by this instance (the "context") with the given spec.
The new URL is constructed as if usingURL(URL, String)
. Note that the result differs based on whether the context has a trailing slash, the spec has a leading slash, both, or none.- Throws:
NullPointerException
- ifspec
isnull
IllegalArgumentException
- if the resultingUrlRef
would cause exceptions when converted toURI
orURL
-
toUri
-
toUrl
-
toString
-
equals
-
hashCode
public int hashCode()
-