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

COVERAGE SUMMARY FOR SOURCE FILE [MapToDriveInfo.java]

nameclass, %method, %block, %line, %
MapToDriveInfo.java100% (1/1)100% (3/3)89%  (230/258)90%  (37/41)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapToDriveInfo100% (1/1)100% (3/3)89%  (230/258)90%  (37/41)
apply (Map): DriveInfo 100% (1/1)85%  (157/185)86%  (25/29)
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.elasticstack.functions;
20 
21import java.util.Map;
22import java.util.Map.Entry;
23 
24import javax.annotation.Resource;
25import javax.inject.Singleton;
26 
27import org.jclouds.elasticstack.domain.ClaimType;
28import org.jclouds.elasticstack.domain.DriveInfo;
29import org.jclouds.elasticstack.domain.DriveMetrics;
30import org.jclouds.elasticstack.domain.DriveStatus;
31import org.jclouds.logging.Logger;
32 
33import com.google.common.base.Function;
34import com.google.common.base.Splitter;
35import com.google.common.collect.Maps;
36 
37/**
38 * 
39 * @author Adrian Cole
40 */
41@Singleton
42public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo> {
43 
44   @Resource
45   protected Logger logger = Logger.NULL;
46 
47   @Override
48   public DriveInfo apply(Map<String, String> from) {
49      if (from.size() == 0)
50         return null;
51      DriveInfo.Builder builder = new DriveInfo.Builder();
52      builder.name(from.get("name"));
53      if (from.containsKey("tags"))
54         builder.tags(Splitter.on(' ').split(from.get("tags")));
55      if (from.containsKey("status"))
56         builder.status(DriveStatus.fromValue(from.get("status")));
57      builder.metrics(buildMetrics(from));
58      builder.user(from.get("user"));
59      builder.encryptionCipher(from.get("encryption:cipher"));
60      builder.uuid(from.get("drive"));
61      if (from.containsKey("claim:type"))
62         builder.claimType(ClaimType.fromValue(from.get("claim:type")));
63      if (from.containsKey("claimed"))
64         builder.claimed(Splitter.on(' ').split(from.get("claimed")));
65      if (from.containsKey("readers"))
66         builder.readers(Splitter.on(' ').split(from.get("readers")));
67      if (from.containsKey("size"))
68         builder.size(new Long(from.get("size")));
69      Map<String, String> metadata = Maps.newLinkedHashMap();
70      for (Entry<String, String> entry : from.entrySet()) {
71         if (entry.getKey().startsWith("user:"))
72            metadata.put(entry.getKey().substring(entry.getKey().indexOf(':') + 1), entry.getValue());
73      }
74      builder.userMetadata(metadata);
75      try {
76         return builder.build();
77      } catch (NullPointerException e) {
78         logger.trace("entry missing data: %s; %s", e.getMessage(), from);
79         return null;
80      }
81   }
82 
83   protected DriveMetrics buildMetrics(Map<String, String> from) {
84      DriveMetrics.Builder metricsBuilder = new DriveMetrics.Builder();
85      if (from.containsKey("read:bytes"))
86         metricsBuilder.readBytes(new Long(from.get("read:bytes")));
87      if (from.containsKey("read:requests"))
88         metricsBuilder.readRequests(new Long(from.get("read:requests")));
89      if (from.containsKey("write:bytes"))
90         metricsBuilder.writeBytes(new Long(from.get("write:bytes")));
91      if (from.containsKey("write:requests"))
92         metricsBuilder.writeRequests(new Long(from.get("write:requests")));
93      return metricsBuilder.build();
94   }
95}

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