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

COVERAGE SUMMARY FOR SOURCE FILE [MapToDriveMetrics.java]

nameclass, %method, %block, %line, %
MapToDriveMetrics.java100% (1/1)100% (6/6)94%  (346/368)93%  (32.6/35)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapToDriveMetrics100% (1/1)100% (6/6)94%  (346/368)93%  (32.6/35)
addBlockDevices (Map, ImmutableMap$Builder): void 100% (1/1)86%  (63/73)81%  (4.8/6)
addSCSIDevices (Map, ImmutableMap$Builder): void 100% (1/1)86%  (63/73)81%  (4.8/6)
addIDEDevices (Map, ImmutableMap$Builder): void 100% (1/1)97%  (77/79)99%  (7/7)
MapToDriveMetrics (): void 100% (1/1)100% (3/3)100% (1/1)
apply (Map): Map 100% (1/1)100% (17/17)100% (5/5)
buildMetrics (String, Map): DriveMetrics 100% (1/1)100% (123/123)100% (10/10)

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.Singleton;
24 
25import org.jclouds.cloudsigma.domain.DriveMetrics;
26 
27import com.google.common.base.Function;
28import com.google.common.collect.ImmutableMap;
29import com.google.common.collect.ImmutableMap.Builder;
30 
31/**
32 * 
33 * @author Adrian Cole
34 */
35@Singleton
36public class MapToDriveMetrics implements Function<Map<String, String>, Map<String, ? extends DriveMetrics>> {
37 
38   public Map<String, ? extends DriveMetrics> apply(Map<String, String> from) {
39      Builder<String, DriveMetrics> builder = ImmutableMap.<String, DriveMetrics> builder();
40      addIDEDevices(from, builder);
41      addSCSIDevices(from, builder);
42      addBlockDevices(from, builder);
43      return builder.build();
44   }
45 
46   protected void addBlockDevices(Map<String, String> from, Builder<String, DriveMetrics> devices) {
47      BLOCK: for (int index : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
48         String key = String.format("block:0:%d", index);
49         if (!from.containsKey(key))
50            break BLOCK;
51         devices.put(key, buildMetrics(key, from));
52      }
53   }
54 
55   protected void addSCSIDevices(Map<String, String> from, Builder<String, DriveMetrics> devices) {
56      SCSI: for (int unit : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
57         String key = String.format("scsi:0:%d", unit);
58         if (!from.containsKey(key))
59            break SCSI;
60         devices.put(key, buildMetrics(key, from));
61      }
62   }
63 
64   protected void addIDEDevices(Map<String, String> from, Builder<String, DriveMetrics> devices) {
65      IDE: for (int bus : new int[] { 0, 1 })
66         for (int unit : new int[] { 0, 1 }) {
67            String key = String.format("ide:%d:%d", bus, unit);
68            if (!from.containsKey(key))
69               break IDE;
70            devices.put(key, buildMetrics(key, from));
71         }
72   }
73 
74   protected DriveMetrics buildMetrics(String key, Map<String, String> from) {
75      DriveMetrics.Builder builder = new DriveMetrics.Builder();
76      if (from.containsKey(key + ":read:bytes"))
77         builder.readBytes(new Long(from.get(key + ":read:bytes")));
78      if (from.containsKey(key + ":read:requests"))
79         builder.readRequests(new Long(from.get(key + ":read:requests")));
80      if (from.containsKey(key + ":write:bytes"))
81         builder.writeBytes(new Long(from.get(key + ":write:bytes")));
82      if (from.containsKey(key + ":write:requests"))
83         builder.writeRequests(new Long(from.get(key + ":write:requests")));
84      return builder.build();
85   }
86}

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