EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.location.functions]

COVERAGE SUMMARY FOR SOURCE FILE [RegionToEndpointOrProviderIfNull.java]

nameclass, %method, %block, %line, %
RegionToEndpointOrProviderIfNull.java0%   (0/1)0%   (0/2)0%   (0/90)0%   (0/10)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RegionToEndpointOrProviderIfNull0%   (0/1)0%   (0/2)0%   (0/90)0%   (0/10)
RegionToEndpointOrProviderIfNull (URI, String, Map): void 0%   (0/1)0%   (0/18)0%   (0/5)
apply (Object): URI 0%   (0/1)0%   (0/72)0%   (0/5)

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.functions;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23import static com.google.common.base.Preconditions.checkState;
24 
25import java.net.URI;
26import java.util.Map;
27 
28import javax.annotation.Nullable;
29import javax.inject.Inject;
30import javax.inject.Singleton;
31 
32import org.jclouds.location.Provider;
33import org.jclouds.location.Region;
34 
35import com.google.common.base.Function;
36 
37/**
38 * If a mapping of regions to endpoints exists, return a uri corresponding to the name of the region
39 * (passed argument). Otherwise, return the default location.
40 * 
41 * @author Adrian Cole
42 */
43@Singleton
44public class RegionToEndpointOrProviderIfNull implements Function<Object, URI> {
45   private final URI defaultUri;
46   private final String defaultProvider;
47   private final Map<String, URI> regionToEndpoint;
48 
49   @Inject
50   public RegionToEndpointOrProviderIfNull(@Provider URI defaultUri, @Provider String defaultProvider,
51         @Nullable @Region Map<String, URI> regionToEndpoint) {
52      this.defaultUri = checkNotNull(defaultUri, "defaultUri");
53      this.defaultProvider = checkNotNull(defaultProvider, "defaultProvider");
54      this.regionToEndpoint = regionToEndpoint;
55   }
56 
57   @Override
58   public URI apply(@Nullable Object from) {
59      if (from == null || from.equals(defaultProvider))
60         return defaultUri;
61      checkState(from.equals(defaultProvider) || regionToEndpoint != null, "requested location " + from
62            + ", but only the default location " + defaultProvider + " is configured");
63      checkArgument(from.equals(defaultProvider) || (regionToEndpoint != null && regionToEndpoint.containsKey(from)),
64            "requested location %s, which is not in the configured locations: %s", from, regionToEndpoint);
65      return regionToEndpoint.get(from);
66   }
67}

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