Java URL Create buildUrlsList(final String domain, final String... paths)

Here you can find the source of buildUrlsList(final String domain, final String... paths)

Description

Builds a List of URL s given a domain and 1..N paths relative to the domain.

License

Open Source License

Parameter

Parameter Description
domain the base domain for the given paths
paths an array of paths to relative to the base domain

Return

a of s

Declaration

private static List<URL> buildUrlsList(final String domain, final String... paths) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;

import java.util.List;
import java.util.stream.Collectors;

public class Main {
    /**//ww w  . ja v a  2s .  co  m
     * Builds a {@link List} of {@link URL}s given a domain and 1..N paths relative to the domain.
     *
     * @param domain the base domain for the given {@code paths}
     * @param paths an array of paths to relative to the base {@code domain}
     * @return a {@link List} of {@link URL}s
     */
    private static List<URL> buildUrlsList(final String domain, final String... paths) {
        return Arrays.stream(paths).map(p -> buildUrl(domain, p)).collect(Collectors.toList());
    }

    /**
     * Builds an {@link URL} given a domain and a path.
     *
     * @param domain the domain
     * @param path the path
     * @return the {@link URL}
     */
    private static URL buildUrl(final String domain, final String path) {
        try {
            return new URL(new URL(domain), path);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. buildUrl(String url, HashMap params)
  2. buildUrl(String URL, Map params)
  3. buildUrl(String urlPrefix, String urlSuffix)
  4. buildURL(URI base, Multimap params)
  5. buildUrlPath(String baseUrl, String childUrl)
  6. buildURLString(Iterable elements, String joiner)
  7. concatenate(URL server, String address)
  8. concatenateURL(final URL url, final String query)
  9. concatenateURL(URL url, String query)