EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.location.suppliers]

COVERAGE SUMMARY FOR SOURCE FILE [ZoneToRegionToProviderOrJustProvider.java]

nameclass, %method, %block, %line, %
ZoneToRegionToProviderOrJustProvider.java0%   (0/2)0%   (0/4)0%   (0/114)0%   (0/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ZoneToRegionToProviderOrJustProvider0%   (0/1)0%   (0/2)0%   (0/105)0%   (0/18)
ZoneToRegionToProviderOrJustProvider (Set, String, URI, Map, Map): void 0%   (0/1)0%   (0/22)0%   (0/4)
get (): Set 0%   (0/1)0%   (0/83)0%   (0/14)
     
class ZoneToRegionToProviderOrJustProvider$10%   (0/1)0%   (0/2)0%   (0/9)0%   (0/2)
ZoneToRegionToProviderOrJustProvider$1 (ZoneToRegionToProviderOrJustProvider)... 0%   (0/1)0%   (0/6)0%   (0/1)
apply (Location): String 0%   (0/1)0%   (0/3)0%   (0/1)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.location.suppliers;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static com.google.common.collect.Maps.uniqueIndex;
23 
24import java.net.URI;
25import java.util.Map;
26import java.util.Set;
27 
28import javax.inject.Inject;
29import javax.inject.Singleton;
30 
31import org.jclouds.domain.Location;
32import org.jclouds.domain.LocationBuilder;
33import org.jclouds.domain.LocationScope;
34import org.jclouds.location.Iso3166;
35import org.jclouds.location.Provider;
36import org.jclouds.location.Zone;
37 
38import com.google.common.base.Function;
39import com.google.common.collect.ImmutableMap;
40import com.google.common.collect.ImmutableSet;
41import com.google.common.collect.ImmutableSet.Builder;
42 
43/**
44 * 
45 * @author Adrian Cole
46 */
47@Singleton
48public class ZoneToRegionToProviderOrJustProvider extends RegionToProviderOrJustProvider {
49   private final Map<String, String> zoneToRegion;
50   private Map<String, Set<String>> isoCodesById;
51 
52   @Inject
53   ZoneToRegionToProviderOrJustProvider(@Iso3166 Set<String> isoCodes, @Provider String providerName,
54            @Provider URI endpoint, @Iso3166 Map<String, Set<String>> isoCodesById,
55            @Zone Map<String, String> zoneToRegion) {
56      super(isoCodes, providerName, endpoint, ImmutableSet.copyOf(checkNotNull(zoneToRegion, "zoneToRegion").values()),
57               isoCodesById);
58      this.zoneToRegion = zoneToRegion;
59      this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById");
60   }
61 
62   @Override
63   public Set<? extends Location> get() {
64      Builder<Location> locations = buildJustProviderOrRegions();
65      ImmutableMap<String, Location> idToLocation = uniqueIndex(locations.build(), new Function<Location, String>() {
66         @Override
67         public String apply(Location from) {
68            return from.getId();
69         }
70      });
71      if (zoneToRegion.size() == 1)
72         return locations.build();
73      for (String zone : zoneToRegion.keySet()) {
74         Location parent = idToLocation.get(zoneToRegion.get(zone));
75         LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(zone).description(zone).parent(
76                  parent);
77         if (isoCodesById.containsKey(zone))
78            builder.iso3166Codes(isoCodesById.get(zone));
79         // be cautious.. only inherit iso codes if the parent is a region
80         // regions may be added dynamically, and we prefer to inherit an
81         // empty set of codes from a region, then a provider, whose code
82         // are likely hard-coded.
83         else if (parent.getScope() == LocationScope.REGION)
84            builder.iso3166Codes(parent.getIso3166Codes());
85         locations.add(builder.build());
86      }
87      return locations.build();
88   }
89}

[all classes][org.jclouds.location.suppliers]
EMMA 2.0.5312 (C) Vladimir Roubtsov