Class URIBuilder

java.lang.Object
ai.clarity.codeartifact.URIBuilder

public class URIBuilder extends Object
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 Details

    • of

      public static URIBuilder of(URI uri)
      Creates a builder holding every component of uri.
      Parameters:
      uri - the uri to read
      Returns:
      a builder initialised from uri
    • withScheme

      public URIBuilder withScheme(String scheme)
      Sets the scheme component.
      Parameters:
      scheme - the scheme, such as https
      Returns:
      this builder
    • withFragment

      public URIBuilder withFragment(String fragment)
      Sets the fragment component.
      Parameters:
      fragment - the fragment, without the leading #
      Returns:
      this builder
    • withAuthority

      public URIBuilder withAuthority(String authority)
      Sets the authority component.
      Parameters:
      authority - the authority

      Note 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

      public URIBuilder withUserInfo(String userInfo)
      Sets the userInfo component.
      Parameters:
      userInfo - the user info, without the trailing @
      Returns:
      this builder
    • withHost

      public URIBuilder withHost(String host)
      Sets the host component.
      Parameters:
      host - the host
      Returns:
      this builder
    • withPort

      public URIBuilder withPort(int port)
      Sets the port component.
      Parameters:
      port - the port, or -1 for none
      Returns:
      this builder
    • withPath

      public URIBuilder withPath(String path)
      Sets the path component.
      Parameters:
      path - the path, with its leading /
      Returns:
      this builder
    • withQuery

      public URIBuilder withQuery(String query)
      Replaces every query parameter with the ones parsed from query.
      Parameters:
      query - the raw query string, without the leading ?; null clears the parameters
      Returns:
      this builder
    • getQueryParamValue

      public String getQueryParamValue(String param)
      Returns the value of one query parameter.
      Parameters:
      param - the parameter name
      Returns:
      its value, null when the parameter is absent or present without a value
    • removeQueryParam

      public URIBuilder removeQueryParam(String param)
      Removes one query parameter, doing nothing when it is absent.
      Parameters:
      param - the parameter name
      Returns:
      this builder
    • setQueryParam

      public URIBuilder setQueryParam(String param, String value)
      Sets one query parameter, replacing any previous value and keeping the original position when it was already present.
      Parameters:
      param - the parameter name
      value - its value, or null to render the parameter with no =
      Returns:
      this builder
    • toURI

      public URI toURI() throws URISyntaxException
      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

      public String getScheme()
      Returns the scheme component.
      Returns:
      the scheme
    • getFragment

      public String getFragment()
      Returns the fragment component.
      Returns:
      the fragment
    • getAuthority

      public String getAuthority()
      Returns the authority component.
      Returns:
      the authority as read from the original uri; see withAuthority(String) for why toURI() ignores it
    • getUserInfo

      public String getUserInfo()
      Returns the user info component.
      Returns:
      the user info
    • getHost

      public String getHost()
      Returns the host component.
      Returns:
      the host
    • getPort

      public int getPort()
      Returns the port component.
      Returns:
      the port, or -1 when there is none
    • getPath

      public String getPath()
      Returns the path component.
      Returns:
      the path
    • getQuery

      public String getQuery()
      Renders the current query parameters back into a query string.
      Returns:
      the query string, without the leading ?, or null when there are no parameters