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

COVERAGE SUMMARY FOR SOURCE FILE [MapToNICs.java]

nameclass, %method, %block, %line, %
MapToNICs.java100% (1/1)100% (3/3)99%  (187/188)100% (22.9/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapToNICs100% (1/1)100% (3/3)99%  (187/188)100% (22.9/23)
getDhcpIp (Map, String): String 100% (1/1)98%  (40/41)99%  (4.9/5)
MapToNICs (String): void 100% (1/1)100% (6/6)100% (3/3)
apply (Map): List 100% (1/1)100% (141/141)100% (15/15)

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.elasticstack.functions;
20 
21import java.util.List;
22import java.util.Map;
23 
24import javax.inject.Singleton;
25 
26import com.google.inject.Inject;
27import org.jclouds.elasticstack.domain.Model;
28import org.jclouds.elasticstack.domain.NIC;
29 
30import com.google.common.base.Function;
31import com.google.common.base.Splitter;
32import com.google.common.collect.ImmutableList;
33import org.jclouds.rest.annotations.ApiVersion;
34 
35/**
36 * @author Adrian Cole
37 */
38@Singleton
39public class MapToNICs implements Function<Map<String, String>, List<NIC>> {
40 
41   private String apiVersion;
42 
43   @Inject
44   public MapToNICs(@ApiVersion String apiVersion) {
45      this.apiVersion = apiVersion;
46   }
47 
48   @Override
49   public List<NIC> apply(Map<String, String> from) {
50      ImmutableList.Builder<NIC> nics = ImmutableList.builder();
51      NIC:
52      for (int id : new int[]{0, 1}) {
53         String key = String.format("nic:%d", id);
54         if (!from.containsKey(key + ":model"))
55            break NIC;
56 
57         NIC.Builder nicBuilder = new NIC.Builder();
58         final String ip = getDhcpIp(from, key);
59         nicBuilder.dhcp(ip);
60         nicBuilder.model(Model.fromValue(from.get(key + ":model")));
61         nicBuilder.vlan(from.get(key + ":vlan"));
62         nicBuilder.mac(from.get(key + ":mac"));
63         if (from.containsKey(key + ":block"))
64            nicBuilder.block(Splitter.on(' ').split(from.get(key + ":block")));
65         nics.add(nicBuilder.build());
66      }
67 
68      return nics.build();
69   }
70 
71   private String getDhcpIp(Map<String, String> from, String key) {
72      if (apiVersion.equals("2.0")) {
73         final String ip = from.get(key + ":dhcp:ip");
74         return (ip == null ? "auto" : ip);
75      } else {
76         final String ip = from.get(key + ":dhcp");
77         return (ip == null ? "auto" : ip);
78      }
79   }
80}

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