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

COVERAGE SUMMARY FOR SOURCE FILE [ParseUserMetadataFromHeaders.java]

nameclass, %method, %block, %line, %
ParseUserMetadataFromHeaders.java100% (2/2)100% (7/7)98%  (149/152)99%  (15.8/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseUserMetadataFromHeaders100% (1/1)100% (5/5)98%  (138/141)99%  (14.8/15)
apply (HttpResponse): UserMetadata 100% (1/1)95%  (58/61)98%  (5.8/6)
<static initializer> 100% (1/1)100% (43/43)100% (2/2)
ParseUserMetadataFromHeaders (): void 100% (1/1)100% (3/3)100% (1/1)
access$000 (): Set 100% (1/1)100% (2/2)100% (1/1)
getMetaMap (String): Map 100% (1/1)100% (32/32)100% (6/6)
     
class ParseUserMetadataFromHeaders$1100% (1/1)100% (2/2)100% (11/11)100% (2/2)
ParseUserMetadataFromHeaders$1 (): void 100% (1/1)100% (3/3)100% (1/1)
apply (String): boolean 100% (1/1)100% (8/8)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.atmos.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Map;
24import java.util.Set;
25 
26import javax.inject.Singleton;
27 
28import org.jclouds.atmos.domain.UserMetadata;
29import org.jclouds.atmos.reference.AtmosHeaders;
30import org.jclouds.http.HttpResponse;
31 
32import com.google.common.base.Function;
33import com.google.common.base.Predicate;
34import com.google.common.base.Splitter;
35import com.google.common.collect.ImmutableMap;
36import com.google.common.collect.ImmutableMap.Builder;
37import com.google.common.collect.ImmutableSet;
38import com.google.common.collect.Maps;
39 
40/**
41 * @author Adrian Cole
42 */
43@Singleton
44public class ParseUserMetadataFromHeaders implements Function<HttpResponse, UserMetadata> {
45   private static final Set<String> sysKeys = ImmutableSet.of("atime", "ctime", "gid", "itime", "mtime", "nlink",
46         "policyname", "size", "uid", "content-md5", "objectid", "objname", "type");
47   private static final Predicate<String> filter = new Predicate<String>() {
48 
49      @Override
50      public boolean apply(String arg0) {
51         return !sysKeys.contains(arg0);
52      }
53 
54   };
55 
56   public UserMetadata apply(HttpResponse from) {
57      checkNotNull(from, "http response");
58 
59      Map<String, String> meta = Maps.filterKeys(
60            getMetaMap(checkNotNull(from.getFirstHeaderOrNull(AtmosHeaders.META), AtmosHeaders.META)),
61            filter);
62 
63      Map<String, String> listableMeta = (from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META) != null) ? getMetaMap(from
64            .getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META)) : ImmutableMap.<String, String> of();
65 
66      Iterable<String> tags = (from.getFirstHeaderOrNull(AtmosHeaders.TAGS) != null) ? Splitter.on(", ").split(
67            from.getFirstHeaderOrNull(AtmosHeaders.TAGS)) : ImmutableSet.<String> of();
68 
69      Iterable<String> listableTags = (from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_TAGS) != null) ? Splitter
70            .on(", ").split(from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_TAGS)) : ImmutableSet.<String> of();
71 
72      return new UserMetadata(meta, listableMeta, tags, listableTags);
73   }
74 
75   // TODO: change to guava
76   private Map<String, String> getMetaMap(String meta) {
77      Builder<String, String> metaMap = ImmutableMap.<String, String> builder();
78      for (String entry : Splitter.on(", ").split(meta)) {
79         String[] entrySplit = entry.split("=");
80         metaMap.put(entrySplit[0], entrySplit[1]);
81      }
82      return metaMap.build();
83   }
84}

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