Class URLEndpoint


  • public class URLEndpoint
    extends Object

    Class which encapsulates the API URL, and enables relevant operations on this URL.

    Since:
    1.2.0
    • Constructor Detail

      • URLEndpoint

        public URLEndpoint​(URL url)

        Overloaded constructor.

        Parameters:
        url - the URL
      • URLEndpoint

        public URLEndpoint​(String url)

        Overloaded constructor.

        Parameters:
        url - the URL
    • Method Detail

      • append

        public URLEndpoint append​(String str)

        Appends the given string to the URL.

        Parameters:
        str - the string to append
        Returns:
        a URLEndpoint with the given string appended
      • getLanguage

        public String getLanguage()

        Returns the language portion of this URL.

        Example: URL of https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0401/BE0401A/ is converted to sv.

        Due to speed efficiency, this method does not perform any validity check on the specified URL. Calling this method without a valid URL for the API may (and probably will) result in undefined behavior.

        Returns:
        the language portion of this URL
      • getTable

        public String getTable()

        Returns the table portion of this URL.

        Example: URL of https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0401/BE0401A/ is converted to BE/BE0401/BE0401A/.

        Due to speed efficiency, this method does not perform any validity check on the specified URL. Calling this method without a valid URL for the API may (and probably will) result in undefined behavior.

        Returns:
        the table portion of this URL
      • toURL

        public URLEndpoint toURL​(Locale locale)

        Generates a new URL to the API using the specified Locale.

        See toURL(String) for implementation details.

        Parameters:
        locale - the Locale to use
        Returns:
        an URLEndpoint representing the URL
      • toURL

        public URLEndpoint toURL​(String language)

        Generates a new URL to the API by replacing the current language tag in the URL with the specified language tag. The communication protocol used, such as HTTP or HTTPS, is not modified.

        Parameters:
        language - the language to use
        Returns:
        an URLEndpoint representing the modified URL
        See Also:
        toURL(String, CommunicationProtocol)
      • toURL

        public URLEndpoint toURL​(String language,
                                 CommunicationProtocol communicationProtocol)

        Generates a new URL to the API by replacing the current language tag and communication protocol in the URL with the specified language tag and CommunicationProtocol.

        The method performs two distinct operations, if needed: replacement of the communication protocol and replacement of the language tag. The following steps are performed to figure out what needs to be replaced:

        1. Replaces the communication protocol (such as "http") with the specified protocol.
        2. Specifies the start segment as the segment preceding the language tag segment in the URL.
        3. Finds the length of the language tag segment by finding the next forward slash following the start segment, as this indicates that the segment has ended.
        4. Replaces the content between the start and end of the segment (forward slashes excluded) with the new language tag.

        Example: URL of https://api.scb.se/OV0104/v1/doris/sv/ssd/ and language input of en is converted to https://api.scb.se/OV0104/v1/doris/en/ssd/.

        Due to speed efficiency, this method does not perform any validity check on the specified URL. Calling this method without a valid URL for the API may (and probably will) result in undefined behavior.

        Parameters:
        language - the language to use
        communicationProtocol - the communication protocol to use
        Returns:
        an URLEndpoint representing the modified URL
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getRootUrl

        public static URLEndpoint getRootUrl​(Locale locale)

        Returns the root URL for the API for a specific Locale.

        Parameters:
        locale - the Locale
        Returns:
        an URLEndpoint representing the ROOT_URL with a converted language tag segment matching the specified Locale