Module bus.http

Class UnoUrl.Builder

java.lang.Object
org.miaixz.bus.http.UnoUrl.Builder
Enclosing class:
UnoUrl

public static final class UnoUrl.Builder extends Object
A builder for creating UnoUrl instances.
  • Constructor Details

    • Builder

      public Builder()
      Default constructor.
  • Method Details

    • scheme

      public UnoUrl.Builder scheme(String scheme)
      Sets the scheme of the URL.
      Parameters:
      scheme - The scheme (http or https).
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if scheme is null.
      IllegalArgumentException - if the scheme is invalid.
    • username

      public UnoUrl.Builder username(String username)
      Sets the username.
      Parameters:
      username - The username.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if username is null.
    • encodedUsername

      public UnoUrl.Builder encodedUsername(String encodedUsername)
      Sets the encoded username.
      Parameters:
      encodedUsername - The encoded username.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if encodedUsername is null.
    • password

      public UnoUrl.Builder password(String password)
      Sets the password.
      Parameters:
      password - The password.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if password is null.
    • encodedPassword

      public UnoUrl.Builder encodedPassword(String encodedPassword)
      Sets the encoded password.
      Parameters:
      encodedPassword - The encoded password.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if encodedPassword is null.
    • host

      public UnoUrl.Builder host(String host)
      Sets the hostname.
      Parameters:
      host - The hostname (regular hostname, IPv4, IPv6, or encoded IDN).
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if host is null.
      IllegalArgumentException - if the host is invalid.
    • port

      public UnoUrl.Builder port(int port)
      Sets the port number.
      Parameters:
      port - The port number.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the port number is invalid.
    • addPathSegment

      public UnoUrl.Builder addPathSegment(String pathSegment)
      Adds a path segment.
      Parameters:
      pathSegment - The path segment.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if pathSegment is null.
    • addPathSegments

      public UnoUrl.Builder addPathSegments(String pathSegments)
      Adds a list of path segments.
      Parameters:
      pathSegments - The path segments string.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if pathSegments is null.
    • addEncodedPathSegment

      public UnoUrl.Builder addEncodedPathSegment(String encodedPathSegment)
      Adds an encoded path segment.
      Parameters:
      encodedPathSegment - The encoded path segment.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if encodedPathSegment is null.
    • addEncodedPathSegments

      public UnoUrl.Builder addEncodedPathSegments(String encodedPathSegments)
      Adds a list of encoded path segments.
      Parameters:
      encodedPathSegments - The encoded path segments string.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if encodedPathSegments is null.
    • setPathSegment

      public UnoUrl.Builder setPathSegment(int index, String pathSegment)
      Sets a path segment at a specific index.
      Parameters:
      index - The index.
      pathSegment - The path segment.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if pathSegment is null.
      IllegalArgumentException - if the path segment is invalid.
    • setEncodedPathSegment

      public UnoUrl.Builder setEncodedPathSegment(int index, String encodedPathSegment)
      Sets an encoded path segment at a specific index.
      Parameters:
      index - The index.
      encodedPathSegment - The encoded path segment.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if encodedPathSegment is null.
      IllegalArgumentException - if the path segment is invalid.
    • removePathSegment

      public UnoUrl.Builder removePathSegment(int index)
      Removes a path segment at a specific index.
      Parameters:
      index - The index.
      Returns:
      this builder instance.
    • encodedPath

      public UnoUrl.Builder encodedPath(String encodedPath)
      Sets the encoded path.
      Parameters:
      encodedPath - The encoded path.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if encodedPath is null.
      IllegalArgumentException - if the path is invalid.
    • query

      public UnoUrl.Builder query(String query)
      Sets the query string.
      Parameters:
      query - The query string.
      Returns:
      this builder instance.
    • encodedQuery

      public UnoUrl.Builder encodedQuery(String encodedQuery)
      Sets the encoded query string.
      Parameters:
      encodedQuery - The encoded query string.
      Returns:
      this builder instance.
    • addQueryParameter

      public UnoUrl.Builder addQueryParameter(String name, String value)
      Adds a query parameter.
      Parameters:
      name - The parameter name.
      value - The parameter value.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if name is null.
    • addEncodedQueryParameter

      public UnoUrl.Builder addEncodedQueryParameter(String encodedName, String encodedValue)
      Adds an encoded query parameter.
      Parameters:
      encodedName - The encoded parameter name.
      encodedValue - The encoded parameter value.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if encodedName is null.
    • setQueryParameter

      public UnoUrl.Builder setQueryParameter(String name, String value)
      Sets a query parameter, replacing any existing parameters with the same name.
      Parameters:
      name - The parameter name.
      value - The parameter value.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if name is null.
    • setEncodedQueryParameter

      public UnoUrl.Builder setEncodedQueryParameter(String encodedName, String encodedValue)
      Sets an encoded query parameter, replacing any existing parameters with the same name.
      Parameters:
      encodedName - The encoded parameter name.
      encodedValue - The encoded parameter value.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if encodedName is null.
    • removeAllQueryParameters

      public UnoUrl.Builder removeAllQueryParameters(String name)
      Removes all query parameters with the given name.
      Parameters:
      name - The parameter name.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if name is null.
    • removeAllEncodedQueryParameters

      public UnoUrl.Builder removeAllEncodedQueryParameters(String encodedName)
      Removes all encoded query parameters with the given name.
      Parameters:
      encodedName - The encoded parameter name.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if encodedName is null.
    • fragment

      public UnoUrl.Builder fragment(String fragment)
      Sets the fragment.
      Parameters:
      fragment - The fragment.
      Returns:
      this builder instance.
    • encodedFragment

      public UnoUrl.Builder encodedFragment(String encodedFragment)
      Sets the encoded fragment.
      Parameters:
      encodedFragment - The encoded fragment.
      Returns:
      this builder instance.
    • build

      public UnoUrl build()
      Builds a new UnoUrl instance.
      Returns:
      a new UnoUrl instance.
      Throws:
      IllegalStateException - if the scheme or host is not set.
    • toString

      public String toString()
      Returns the string representation of the URL.
      Overrides:
      toString in class Object
      Returns:
      The URL string.