Package ai.clarity.codeartifact
Class URIBuilder
java.lang.Object
ai.clarity.codeartifact.URIBuilder
Mutable builder for editing the parts of a
URI, used here to read and strip the ?profile= query
parameter of a repository url without rebuilding the string by hand.
Query parameters keep their insertion order, and a parameter present with no = is held with a
null value so that it survives a round trip.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the authority component.Returns the fragment component.getHost()Returns the host component.getPath()Returns the path component.intgetPort()Returns the port component.getQuery()Renders the current query parameters back into a query string.getQueryParamValue(String param) Returns the value of one query parameter.Returns the scheme component.Returns the user info component.static URIBuilderCreates a builder holding every component ofuri.removeQueryParam(String param) Removes one query parameter, doing nothing when it is absent.setQueryParam(String param, String value) Sets one query parameter, replacing any previous value and keeping the original position when it was already present.toURI()Builds the uri from the components held by this builder.withAuthority(String authority) Sets the authority component.withFragment(String fragment) Sets the fragment component.Sets the host component.Sets the path component.withPort(int port) Sets the port component.Replaces every query parameter with the ones parsed fromquery.withScheme(String scheme) Sets the scheme component.withUserInfo(String userInfo) Sets the userInfo component.
-
Method Details
-
of
Creates a builder holding every component ofuri.- Parameters:
uri- the uri to read- Returns:
- a builder initialised from
uri
-
withScheme
Sets the scheme component.- Parameters:
scheme- the scheme, such ashttps- Returns:
- this builder
-
withFragment
Sets the fragment component.- Parameters:
fragment- the fragment, without the leading#- Returns:
- this builder
-
withAuthority
Sets the authority component.- Parameters:
authority- the authorityNote
toURI()rebuilds the authority from the user info, host and port instead of using this value, so setting it alone does not change the uri produced.- Returns:
- this builder
-
withUserInfo
Sets the userInfo component.- Parameters:
userInfo- the user info, without the trailing@- Returns:
- this builder
-
withHost
Sets the host component.- Parameters:
host- the host- Returns:
- this builder
-
withPort
Sets the port component.- Parameters:
port- the port, or-1for none- Returns:
- this builder
-
withPath
Sets the path component.- Parameters:
path- the path, with its leading/- Returns:
- this builder
-
withQuery
Replaces every query parameter with the ones parsed fromquery.- Parameters:
query- the raw query string, without the leading?;nullclears the parameters- Returns:
- this builder
-
getQueryParamValue
Returns the value of one query parameter.- Parameters:
param- the parameter name- Returns:
- its value,
nullwhen the parameter is absent or present without a value
-
removeQueryParam
Removes one query parameter, doing nothing when it is absent.- Parameters:
param- the parameter name- Returns:
- this builder
-
setQueryParam
Sets one query parameter, replacing any previous value and keeping the original position when it was already present.- Parameters:
param- the parameter namevalue- its value, ornullto render the parameter with no=- Returns:
- this builder
-
toURI
Builds the uri from the components held by this builder.- Returns:
- the resulting uri, with the query rendered from the current parameters
- Throws:
URISyntaxException- when the components do not form a valid uri
-
getScheme
Returns the scheme component.- Returns:
- the scheme
-
getFragment
Returns the fragment component.- Returns:
- the fragment
-
getAuthority
Returns the authority component.- Returns:
- the authority as read from the original uri; see
withAuthority(String)for whytoURI()ignores it
-
getUserInfo
Returns the user info component.- Returns:
- the user info
-
getHost
Returns the host component.- Returns:
- the host
-
getPort
public int getPort()Returns the port component.- Returns:
- the port, or
-1when there is none
-
getPath
Returns the path component.- Returns:
- the path
-
getQuery
Renders the current query parameters back into a query string.- Returns:
- the query string, without the leading
?, ornullwhen there are no parameters
-