// Path: provider/src/main/java/com/cloudera/director/google/util/Urls.java
// public final class Urls {
// 
//   @VisibleForTesting
//   static final String MALFORMED_RESOURCE_URL_MSG = "Malformed resource url '%s'.";
// 
//   private Urls() {}
// 
//   public static String getLocalName(String fullResourceUrl) {
//     if (fullResourceUrl == null || fullResourceUrl.isEmpty()) {
//       return null;
//     }
// 
//     GenericUrl url = new GenericUrl(fullResourceUrl);
//     return Iterables.getLast(url.getPathParts());
//   }
// 
//   public static String getProject(String fullResourceUrl) {
//     if (fullResourceUrl == null || fullResourceUrl.isEmpty()) {
//       return null;
//     }
// 
//     List<String> pathParts = new GenericUrl(fullResourceUrl).getPathParts();
// 
//     if (pathParts == null) {
//       throw new IllegalArgumentException(String.format(MALFORMED_RESOURCE_URL_MSG, fullResourceUrl));
//     }
// 
//     String[] urlParts = Iterables.toArray(pathParts, String.class);
// 
//     // Resource urls look like so: https://www.googleapis.com/compute/v1/projects/rhel-cloud/global/images/rhel-6-v20150526
//     // The path parts begin after the host and include a leading "" path part to force the leading slash.
//     if (urlParts.length < 8) {
//       throw new IllegalArgumentException(String.format(MALFORMED_RESOURCE_URL_MSG, fullResourceUrl));
//     } else {
//       return urlParts[urlParts.length - 4];
//     }
//   }
// 
//   public static String buildGenericApisUrl(String domainName, String version, String projectId, String... resourcePathParts) {
//     GenericUrl genericUrl = new GenericUrl();
//     genericUrl.setScheme("https");
//     genericUrl.setHost("www.googleapis.com");
// 
//     List<String> pathParts = Lists.newArrayList("", domainName, version);
//     pathParts.add("projects");
//     pathParts.add(projectId);
// 
//     if (resourcePathParts != null) {
//       pathParts.addAll(Lists.newArrayList(resourcePathParts));
//     }
// 
//     genericUrl.setPathParts(pathParts);
// 
//     return genericUrl.build();
//   }
// }


import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.cloudera.director.google.util.Urls;
import java.util.List;
    List<String> pathParts = Lists.newArrayList("zones", zone);

    if (resourcePathParts != null) {
      pathParts.addAll(Lists.newArrayList(resourcePathParts));
    }

    return buildGoogleComputeApisUrl(projectId, Iterables.toArray(pathParts, String.class));
  }

  public static String buildRegionalUrl(String projectId, String region, String... resourcePathParts) {
    List<String> pathParts = Lists.newArrayList("regions", region);

    if (resourcePathParts != null) {
      pathParts.addAll(Lists.newArrayList(resourcePathParts));
    }

    return buildGoogleComputeApisUrl(projectId, Iterables.toArray(pathParts, String.class));
  }

  public static String buildGlobalUrl(String projectId, String... resourcePathParts) {
    List<String> pathParts = Lists.newArrayList("global");

    if (resourcePathParts != null) {
      pathParts.addAll(Lists.newArrayList(resourcePathParts));
    }

    return buildGoogleComputeApisUrl(projectId, Iterables.toArray(pathParts, String.class));
  }

  static String buildGoogleComputeApisUrl(String projectId, String... resourcePathParts) {
// Path: provider/src/main/java/com/cloudera/director/google/util/Urls.java
// public final class Urls {
// 
//   @VisibleForTesting
//   static final String MALFORMED_RESOURCE_URL_MSG = "Malformed resource url '%s'.";
// 
//   private Urls() {}
// 
//   public static String getLocalName(String fullResourceUrl) {
//     if (fullResourceUrl == null || fullResourceUrl.isEmpty()) {
//       return null;
//     }
// 
//     GenericUrl url = new GenericUrl(fullResourceUrl);
//     return Iterables.getLast(url.getPathParts());
//   }
// 
//   public static String getProject(String fullResourceUrl) {
//     if (fullResourceUrl == null || fullResourceUrl.isEmpty()) {
//       return null;
//     }
// 
//     List<String> pathParts = new GenericUrl(fullResourceUrl).getPathParts();
// 
//     if (pathParts == null) {
//       throw new IllegalArgumentException(String.format(MALFORMED_RESOURCE_URL_MSG, fullResourceUrl));
//     }
// 
//     String[] urlParts = Iterables.toArray(pathParts, String.class);
// 
//     // Resource urls look like so: https://www.googleapis.com/compute/v1/projects/rhel-cloud/global/images/rhel-6-v20150526
//     // The path parts begin after the host and include a leading "" path part to force the leading slash.
//     if (urlParts.length < 8) {
//       throw new IllegalArgumentException(String.format(MALFORMED_RESOURCE_URL_MSG, fullResourceUrl));
//     } else {
//       return urlParts[urlParts.length - 4];
//     }
//   }
// 
//   public static String buildGenericApisUrl(String domainName, String version, String projectId, String... resourcePathParts) {
//     GenericUrl genericUrl = new GenericUrl();
//     genericUrl.setScheme("https");
//     genericUrl.setHost("www.googleapis.com");
// 
//     List<String> pathParts = Lists.newArrayList("", domainName, version);
//     pathParts.add("projects");
//     pathParts.add(projectId);
// 
//     if (resourcePathParts != null) {
//       pathParts.addAll(Lists.newArrayList(resourcePathParts));
//     }
// 
//     genericUrl.setPathParts(pathParts);
// 
//     return genericUrl.build();
//   }
// }


// Path: provider/src/main/java/com/cloudera/director/google/compute/util/ComputeUrls.java
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.cloudera.director.google.util.Urls;
import java.util.List;

    List<String> pathParts = Lists.newArrayList("zones", zone);

    if (resourcePathParts != null) {
      pathParts.addAll(Lists.newArrayList(resourcePathParts));
    }

    return buildGoogleComputeApisUrl(projectId, Iterables.toArray(pathParts, String.class));
  }

  public static String buildRegionalUrl(String projectId, String region, String... resourcePathParts) {
    List<String> pathParts = Lists.newArrayList("regions", region);

    if (resourcePathParts != null) {
      pathParts.addAll(Lists.newArrayList(resourcePathParts));
    }

    return buildGoogleComputeApisUrl(projectId, Iterables.toArray(pathParts, String.class));
  }

  public static String buildGlobalUrl(String projectId, String... resourcePathParts) {
    List<String> pathParts = Lists.newArrayList("global");

    if (resourcePathParts != null) {
      pathParts.addAll(Lists.newArrayList(resourcePathParts));
    }

    return buildGoogleComputeApisUrl(projectId, Iterables.toArray(pathParts, String.class));
  }

  static String buildGoogleComputeApisUrl(String projectId, String... resourcePathParts) {
    return Urls.buildGenericApisUrl("compute", "v1", projectId, resourcePathParts);