EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.softlayer.compute.functions]

COVERAGE SUMMARY FOR SOURCE FILE [DatacenterToLocation.java]

nameclass, %method, %block, %line, %
DatacenterToLocation.java100% (1/1)100% (3/3)97%  (75/77)98%  (9.8/10)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DatacenterToLocation100% (1/1)100% (3/3)97%  (75/77)98%  (9.8/10)
createIso3166Codes (Address): Iterable 100% (1/1)95%  (38/40)97%  (5.8/6)
DatacenterToLocation (JustProvider): void 100% (1/1)100% (9/9)100% (3/3)
apply (Datacenter): Location 100% (1/1)100% (28/28)100% (1/1)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.softlayer.compute.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import javax.inject.Inject;
24 
25import static com.google.common.base.Strings.nullToEmpty;
26import org.jclouds.domain.Location;
27import org.jclouds.domain.LocationBuilder;
28import org.jclouds.domain.LocationScope;
29import org.jclouds.location.suppliers.JustProvider;
30import org.jclouds.softlayer.domain.Address;
31import org.jclouds.softlayer.domain.Datacenter;
32 
33import com.google.common.base.Function;
34import com.google.common.collect.ImmutableMap;
35import com.google.common.collect.ImmutableSet;
36import com.google.common.collect.Iterables;
37 
38/**
39 * Converts an Datacenter into a Location.
40 */
41public class DatacenterToLocation implements Function<Datacenter,Location> {
42   private final JustProvider provider;
43 
44   // allow us to lazy discover the provider of a resource
45   @Inject
46   public DatacenterToLocation(JustProvider provider) {
47      this.provider = checkNotNull(provider, "provider");
48   }
49   
50    @Override
51    public Location apply(Datacenter datacenter) {
52        return new LocationBuilder().scope(LocationScope.ZONE)
53                                    .metadata(ImmutableMap.<String, Object>of())
54                                    .description(datacenter.getLongName())
55                                    .id(Long.toString(datacenter.getId()))
56                                    .iso3166Codes(createIso3166Codes(datacenter.getLocationAddress()))
57                                    .parent(Iterables.getOnlyElement(provider.get()))
58                                    .build();
59   }
60 
61   private Iterable<String> createIso3166Codes(Address address) {
62      if (address== null) return ImmutableSet.<String> of();
63 
64      final String country = nullToEmpty(address.getCountry()).trim();
65      if (country.isEmpty()) return ImmutableSet.<String> of();
66 
67      final String state = nullToEmpty(address.getState()).trim();
68      if (state.isEmpty()) return ImmutableSet.<String> of(address.getCountry());
69 
70      return ImmutableSet.<String> of("" + country + "-" + state);
71 
72               
73   }
74}

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