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

COVERAGE SUMMARY FOR SOURCE FILE [ServerToMap.java]

nameclass, %method, %block, %line, %
ServerToMap.java100% (1/1)100% (2/2)71%  (187/263)81%  (26.8/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ServerToMap100% (1/1)100% (2/2)71%  (187/263)81%  (26.8/33)
apply (Server): Map 100% (1/1)71%  (184/260)81%  (25.8/32)
ServerToMap (): void 100% (1/1)100% (3/3)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.cloudsigma.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Map;
24import java.util.Map.Entry;
25 
26import javax.inject.Singleton;
27 
28import org.jclouds.cloudsigma.domain.Device;
29import org.jclouds.cloudsigma.domain.NIC;
30import org.jclouds.cloudsigma.domain.Server;
31 
32import com.google.common.base.Function;
33import com.google.common.base.Joiner;
34import com.google.common.collect.ImmutableMap;
35 
36/**
37 * 
38 * @author Adrian Cole
39 */
40@Singleton
41public class ServerToMap implements Function<Server, Map<String, String>> {
42   @Override
43   public Map<String, String> apply(Server from) {
44      checkNotNull(from, "server");
45      ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
46      builder.put("name", from.getName());
47      builder.put("cpu", from.getCpu() + "");
48      if (from.getSmp() != null)
49         builder.put("smp", from.getSmp() + "");
50      else
51         builder.put("smp", "auto");
52      builder.put("mem", from.getMem() + "");
53      builder.put("persistent", from.isPersistent() + "");
54      if (from.getBootDeviceIds().size() != 0)
55         builder.put("boot", Joiner.on(' ').join(from.getBootDeviceIds()));
56      for (Entry<String, ? extends Device> entry : from.getDevices().entrySet()) {
57         builder.put(entry.getKey(), entry.getValue().getDriveUuid());
58         builder.put(entry.getKey() + ":media", entry.getValue().getMediaType().toString());
59      }
60      int nicId = 0;
61      for (NIC nic : from.getNics()) {
62         builder.put("nic:" + nicId + ":model", nic.getModel().toString());
63         if (nic.getDhcp() != null)
64            builder.put("nic:" + nicId + ":dhcp", nic.getDhcp());
65         if (nic.getVlan() != null)
66            builder.put("nic:" + nicId + ":vlan", nic.getVlan());
67         if (nic.getMac() != null)
68            builder.put("nic:" + nicId + ":mac", nic.getMac());
69         nicId++;
70      }
71      builder.put("vnc:ip", from.getVnc().getIp() == null ? "auto" : from.getVnc().getIp());
72      if (from.getVnc().getPassword() != null)
73         builder.put("vnc:password", from.getVnc().getPassword());
74      if (from.getVnc().isTls())
75         builder.put("vnc:tls", "on");
76      if (from.getUse().size() != 0)
77         builder.put("use", Joiner.on(' ').join(from.getUse()));
78      return builder.build();
79   }
80}

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