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

COVERAGE SUMMARY FOR SOURCE FILE [MapToDevices.java]

nameclass, %method, %block, %line, %
MapToDevices.java100% (2/2)100% (8/8)90%  (275/305)93%  (30.6/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapToDevices100% (1/1)100% (6/6)90%  (269/299)92%  (28.6/31)
addBlockDevices (Map, ImmutableSet$Builder): void 100% (1/1)82%  (63/77)80%  (4.8/6)
addSCSIDevices (Map, ImmutableSet$Builder): void 100% (1/1)82%  (63/77)80%  (4.8/6)
addIDEDevices (Map, ImmutableSet$Builder): void 100% (1/1)98%  (82/84)99%  (7/7)
MapToDevices (Function): void 100% (1/1)100% (6/6)100% (3/3)
apply (Map): Map 100% (1/1)100% (20/20)100% (5/5)
populateBuilder (Device$Builder, String, Map): Device$Builder 100% (1/1)100% (35/35)100% (4/4)
     
class MapToDevices$DeviceToId100% (1/1)100% (2/2)100% (6/6)100% (2/2)
MapToDevices$DeviceToId (): void 100% (1/1)100% (3/3)100% (1/1)
apply (Device): String 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 java.util.Map;
22 
23import javax.inject.Inject;
24import javax.inject.Singleton;
25 
26import org.jclouds.cloudsigma.domain.BlockDevice;
27import org.jclouds.cloudsigma.domain.Device;
28import org.jclouds.cloudsigma.domain.IDEDevice;
29import org.jclouds.cloudsigma.domain.MediaType;
30import org.jclouds.cloudsigma.domain.SCSIDevice;
31 
32import com.google.common.base.Function;
33import com.google.common.collect.ImmutableSet;
34import com.google.common.collect.ImmutableSet.Builder;
35import com.google.common.collect.Maps;
36 
37/**
38 * 
39 * @author Adrian Cole
40 */
41@Singleton
42public class MapToDevices implements Function<Map<String, String>, Map<String, ? extends Device>> {
43   @Singleton
44   public static class DeviceToId implements Function<Device, String> {
45      @Override
46      public String apply(Device input) {
47         return input.getId();
48      }
49   }
50 
51   private final Function<Device, String> deviceToId;
52 
53   @Inject
54   public MapToDevices(Function<Device, String> deviceToId) {
55      this.deviceToId = deviceToId;
56   }
57 
58   public Map<String, ? extends Device> apply(Map<String, String> from) {
59      Builder<Device> devices = ImmutableSet.builder();
60      addIDEDevices(from, devices);
61      addSCSIDevices(from, devices);
62      addBlockDevices(from, devices);
63 
64      return Maps.uniqueIndex(devices.build(), deviceToId);
65   }
66 
67   protected void addBlockDevices(Map<String, String> from, Builder<Device> devices) {
68      BLOCK: for (int index : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
69         String key = String.format("block:0:%d", index);
70         if (!from.containsKey(key))
71            break BLOCK;
72         devices.add(populateBuilder(new BlockDevice.Builder(index), key, from).build());
73      }
74   }
75 
76   protected void addSCSIDevices(Map<String, String> from, Builder<Device> devices) {
77      SCSI: for (int unit : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
78         String key = String.format("scsi:0:%d", unit);
79         if (!from.containsKey(key))
80            break SCSI;
81         devices.add(populateBuilder(new SCSIDevice.Builder(unit), key, from).build());
82      }
83   }
84 
85   protected void addIDEDevices(Map<String, String> from, Builder<Device> devices) {
86      IDE: for (int bus : new int[] { 0, 1 })
87         for (int unit : new int[] { 0, 1 }) {
88            String key = String.format("ide:%d:%d", bus, unit);
89            if (!from.containsKey(key))
90               break IDE;
91            devices.add(populateBuilder(new IDEDevice.Builder(bus, unit), key, from).build());
92         }
93   }
94 
95   protected Device.Builder populateBuilder(Device.Builder deviceBuilder, String key, Map<String, String> from) {
96      deviceBuilder.uuid(from.get(key));
97      if (from.containsKey(key + ":media"))
98         deviceBuilder.mediaType(MediaType.fromValue(from.get(key + ":media")));
99      return deviceBuilder;
100   }
101}

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