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

COVERAGE SUMMARY FOR SOURCE FILE [MapToDriveInfo.java]

nameclass, %method, %block, %line, %
MapToDriveInfo.java100% (1/1)100% (3/3)95%  (361/381)93%  (56/60)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapToDriveInfo100% (1/1)100% (3/3)95%  (361/381)93%  (56/60)
apply (Map): DriveInfo 100% (1/1)94%  (288/308)92%  (44/48)
MapToDriveInfo (): void 100% (1/1)100% (6/6)100% (2/2)
buildMetrics (Map): DriveMetrics 100% (1/1)100% (67/67)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.net.URI;
22import java.util.Map;
23import java.util.Map.Entry;
24 
25import javax.annotation.Resource;
26import javax.inject.Singleton;
27 
28import org.jclouds.cloudsigma.domain.ClaimType;
29import org.jclouds.cloudsigma.domain.DriveInfo;
30import org.jclouds.cloudsigma.domain.DriveMetrics;
31import org.jclouds.cloudsigma.domain.DriveStatus;
32import org.jclouds.cloudsigma.domain.DriveType;
33import org.jclouds.logging.Logger;
34 
35import com.google.common.base.Function;
36import com.google.common.base.Splitter;
37import com.google.common.collect.Maps;
38 
39/**
40 * 
41 * @author Adrian Cole
42 */
43@Singleton
44public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo> {
45 
46   @Resource
47   protected Logger logger = Logger.NULL;
48 
49   @Override
50   public DriveInfo apply(Map<String, String> from) {
51      if (from.size() == 0)
52         return null;
53      if (from.size() == 0)
54         return null;
55      DriveInfo.Builder builder = new DriveInfo.Builder();
56      builder.name(from.get("name"));
57      if (from.containsKey("use"))
58         builder.use(Splitter.on(' ').split(from.get("use")));
59      if (from.containsKey("status"))
60         builder.status(DriveStatus.fromValue(from.get("status")));
61      builder.metrics(buildMetrics(from));
62      builder.user(from.get("user"));
63      builder.encryptionCipher(from.get("encryption:cipher"));
64      builder.uuid(from.get("drive"));
65      if (from.containsKey("claim:type"))
66         builder.claimType(ClaimType.fromValue(from.get("claim:type")));
67      if (from.containsKey("claimed"))
68         builder.claimed(Splitter.on(' ').split(from.get("claimed")));
69      if (from.containsKey("readers"))
70         builder.readers(Splitter.on(' ').split(from.get("readers")));
71      if (from.containsKey("size"))
72         builder.size(new Long(from.get("size")));
73      Map<String, String> metadata = Maps.newLinkedHashMap();
74      for (Entry<String, String> entry : from.entrySet()) {
75         if (entry.getKey().startsWith("user:"))
76            metadata.put(entry.getKey().substring(entry.getKey().indexOf(':') + 1), entry.getValue());
77      }
78      if (from.containsKey("use"))
79         builder.use(Splitter.on(' ').split(from.get("use")));
80      if (from.containsKey("bits"))
81         builder.bits(new Integer(from.get("bits")));
82      if (from.containsKey("url"))
83         builder.url(URI.create(from.get("url")));
84      builder.encryptionKey(from.get("encryption:key"));
85      builder.description(from.get("description"));
86      builder.installNotes(from.get("install_notes"));
87      builder.os(from.get("os"));
88      if (from.containsKey("drive_type"))
89         builder.driveType(Splitter.on(',').split(from.get("drive_type")));
90      if (from.containsKey("autoexpanding"))
91         builder.autoexpanding(new Boolean(from.get("autoexpanding")));
92      if (from.containsKey("free"))
93         builder.free(new Boolean(from.get("free")));
94      if (from.containsKey("type"))
95         builder.type(DriveType.fromValue(from.get("type")));
96      try {
97         return builder.build();
98      } catch (NullPointerException e) {
99         logger.trace("entry missing data: %s; %s", e.getMessage(), from);
100         return null;
101      }
102   }
103 
104   protected DriveMetrics buildMetrics(Map<String, String> from) {
105      DriveMetrics.Builder metricsBuilder = new DriveMetrics.Builder();
106      if (from.containsKey("read:bytes"))
107         metricsBuilder.readBytes(new Long(from.get("read:bytes")));
108      if (from.containsKey("read:requests"))
109         metricsBuilder.readRequests(new Long(from.get("read:requests")));
110      if (from.containsKey("write:bytes"))
111         metricsBuilder.writeBytes(new Long(from.get("write:bytes")));
112      if (from.containsKey("write:requests"))
113         metricsBuilder.writeRequests(new Long(from.get("write:requests")));
114      return metricsBuilder.build();
115   }
116}

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