Class Url

java.lang.Object
com.oorian.utils.Url

public class Url extends Object
Mutable URL wrapper with query parameter manipulation.

Url provides a convenient way to parse, manipulate, and rebuild URLs. It automatically parses query parameters into a Parameters object and can reconstruct the URL after modifications.

Since:
2020
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

  • Method Details

    • setUrl

      public final void setUrl(String url) throws MalformedURLException
      Sets the URL to a new value, re-parsing the query parameters.
      Parameters:
      url - the URL string to parse.
      Throws:
      MalformedURLException - if the URL is invalid.
    • setParameter

      public final void setParameter(String name, String value) throws MalformedURLException
      Sets or adds a query parameter and rebuilds the URL.
      Parameters:
      name - the parameter name.
      value - the parameter value.
      Throws:
      MalformedURLException - if the rebuilt URL is invalid.
    • getQuery

      public String getQuery()
      Returns the query string portion of the URL.
      Returns:
      the query string, or null if none.
    • getPath

      public String getPath()
      Returns the path portion of the URL.
      Returns:
      the path.
    • getUserInfo

      public String getUserInfo()
      Returns the user info portion of the URL.
      Returns:
      the user info, or null if none.
    • getAuthority

      public String getAuthority()
      Returns the authority portion of the URL.
      Returns:
      the authority.
    • getProtocol

      public String getProtocol()
      Returns the protocol (scheme) of the URL.
      Returns:
      the protocol (e.g., "https").
    • getHost

      public String getHost()
      Returns the host of the URL.
      Returns:
      the host name.
    • getPort

      public int getPort()
      Returns the port number of the URL.
      Returns:
      the port number, or -1 if not specified.
    • getHostAndPort

      public String getHostAndPort()
      Returns the host and port as a combined string.

      If no port is specified, returns just the host.

      Returns:
      the host and port (e.g., "example.com:8080" or "example.com").
    • getFile

      public String getFile()
      Returns the file portion of the URL (path plus query string).
      Returns:
      the file portion of the URL.
    • getRef

      public String getRef()
      Returns the fragment (anchor) portion of the URL.
      Returns:
      the fragment, or null if none.
    • toString

      public String toString()
      Overrides:
      toString in class Object