Class KiwiUrls2

java.lang.Object
org.kiwiproject.beta.net.KiwiUrls2

@Beta public final class KiwiUrls2 extends Object
Utilities related to URLs.

These utilities could be considered for kiwi's KiwiUrls class. Or, they could just stay here forever. One can never really know these things...

  • Method Details

    • uniqueHostOnlyUrls

      public static Set<URL> uniqueHostOnlyUrls(Collection<URL> urls)
      Given a collection of URLs, return a set containing URLs with only the host[:port] (the authority part).

      This is an alias of uniqueAuthorityOnlyUrls(Collection).

      Note: This method may perform DNS lookups when adding URL objects to the resulting Set. This is because "URL's equals() and hashCode() methods can perform a DNS lookup to resolve the host name" according to IntelliJ's "may contain URL objects" inspection. If you need to avoid this, use the uniqueAuthorityOnlyUrlsAsList(Collection) method to get a List of unique URLs. However, note that any subsequent conversion to a Set will potentially incur the same DNS lookups.

      Parameters:
      urls - the URLs to process
      Returns:
      a set containing unique URLs containing only the host[:port] (the authority part) from the original URLs
      See Also:
    • uniqueAuthorityOnlyUrls

      public static Set<URL> uniqueAuthorityOnlyUrls(Collection<URL> urls)
      Given a collection of URLs, return a set containing URLs with only the authority ( host[:port] ).

      Note: This method may perform DNS lookups when adding URL objects to the resulting Set. This is because "URL's equals() and hashCode() methods can perform a DNS lookup to resolve the host name" according to IntelliJ's "may contain URL objects" inspection. If you need to avoid this, use the uniqueAuthorityOnlyUrlsAsList(Collection) method to get a List of unique URLs. However, note that any subsequent conversion to a Set will potentially incur the same DNS lookups.

      Parameters:
      urls - the URLs to process
      Returns:
      a set containing unique URLs containing only the authority part ( host[:port] ) from the original URLs
      See Also:
    • uniqueAuthorityOnlyUrlsAsList

      public static List<URL> uniqueAuthorityOnlyUrlsAsList(Collection<URL> urls)
      Given a collection of URLs, return a list containing unique URLs with only the authority ( host[:port] ).

      Note: This method avoids DNS lookups performed by URL equals() and hashCode() methods that may occur when adding URL objects to sets and maps. Note also that any subsequent conversion to a Set will potentially incur the same DNS lookups, so it is best to work directly with the list of URLs returned by this method.

      Parameters:
      urls - the URLs to process
      Returns:
      a list containing unique URLs containing only the authority part ( host[:port] ) from the original URLs
    • hostOnlyUrlFrom

      public static URL hostOnlyUrlFrom(URL url)
      Strip any path or query parameters from the given URL, returning only host[:port] (the authority part).

      This is an alias of authorityOnlyUrlFrom(URL).

      Parameters:
      url - the URL to process
      Returns:
      a URL containing only the host[:port] (the authority part) of the original URL
      See Also:
    • authorityOnlyUrlFrom

      public static URL authorityOnlyUrlFrom(URL url)
      Strip any path or query parameters from the given URL, returning only the authority ( host[:port] ).
      Parameters:
      url - the URL to process
      Returns:
      a URL containing only the authority part of the original URL