Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2013-2015 Amazon Technologies, Inc.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at:
   *
   *    http://aws.amazon.com/apache2.0
   *
  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
  * OR CONDITIONS OF ANY KIND, either express or implied. See the
  * License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.amazonaws.regions;
 
 import java.net.URI;
 
 import java.util.List;

A collection of metadata about a set of regions and the services they contain.

See also:
RegionUtils
 
 public class RegionMetadata {
 
     private final List<Regionregions;

    
Creates a new RegionMetadata object from the given list of regions.

Parameters:
regions the list of regions
 
     public RegionMetadata(final List<Regionregions) {
         if (regions == null) {
             throw new IllegalArgumentException("regions cannot be null");
         }
 
         this. =
             Collections.unmodifiableList(new ArrayList<Region>(regions));
     }

    
Returns an immutable list of all regions known to this region metadata object, in no particular order.

Returns:
an immutable list of all regions
 
     public List<RegiongetRegions() {
         return ;
     }

    
Returns the region with the name given, if it exists. Otherwise, returns null.

Parameters:
name the name of the region to search for
Returns:
the corresponding region, if it exists
 
     public Region getRegion(final String name) {
         for (Region region : ) {
             if (region.getName().equals(name)) {
                 return region;
             }
         }
         return null;
     }

    
Returns a list of the regions that support the service given.

Parameters:
service the service abbreviation to search for
Returns:
the list of regions with support for the given service
See also:
ServiceAbbreviations
 
     public List<RegiongetRegionsForService(final String service) {
         List<Regionresults = new LinkedList<Region>();
 
         for (Region region : ) {
             if (region.isServiceSupported(service)) {
                 results.add(region);
             }
         }
 
         return results;
     }

    
Searches through all known regions to find one with any service at the specified endpoint. If no region is found with a service at that endpoint, an exception is thrown.

Parameters:
endpoint The endpoint for any service residing in the desired region.
Returns:
The region containing any service running at the specified endpoint, otherwise an exception is thrown if no region is found with a service at the specified endpoint.
Throws:
java.lang.IllegalArgumentException If the given URL is malformed, or if the one of the service URLs on record is malformed.
    public Region getRegionByEndpoint(final String endpoint) {
        String host = getHost(endpoint);
        for (Region region : ) {
            for (String serviceEndpoint
                     : region.getServiceEndpoints().values()) {
                if (host.equals(getHost(serviceEndpoint))) {
                    return region;
                }
            }
        }
        throw new IllegalArgumentException(
            "No region found with any service for endpoint " + endpoint);
    }

    
Parse the host portion out of an endpoint (which may or may not contain a scheme).

Parameters:
endpoint the endpoint to parse
Returns:
the host portion of the endpoint
    private static String getHost(final String endpoint) {
        String host = URI.create(endpoint).getHost();
        if (host == null) {
            host = URI.create("http://" + endpoint).getHost();
        }
        return host;
    }
    @Override
    public String toString() {
        return .toString();
    }
New to GrepCode? Check out our FAQ X