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
UrlRefinstance, it is ensured that it later can be converted to both aURIand aURL. -
Creating a
UrlRefnever throws checked exceptions. -
Unlike
URI, anUrlRefinstance can be used to build a child URI - just likeURLwith itstwo-arg constructor.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
UrlRef
- Throws:
NullPointerException- ifuriisnullIllegalArgumentException- if the resultingUrlRefwould cause exceptions when converted toURL
-
UrlRef
- Throws:
NullPointerException- ifurlisnullIllegalArgumentException- if the resultingUrlRefwould cause exceptions when converted toURI
-
UrlRef
- Throws:
NullPointerException- ifspecisnullIllegalArgumentException- if the resultingUrlRefwould cause exceptions when converted toURIorURL
-
-
Method Details
-
resolve
Creates a newUrlRefby 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- ifspecisnullIllegalArgumentException- if the resultingUrlRefwould cause exceptions when converted toURIorURL
-
toUri
-
toUrl
-
toString
-
equals
-
hashCode
public int hashCode()
-