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

COVERAGE SUMMARY FOR SOURCE FILE [ListBlobsResponseToResourceList.java]

nameclass, %method, %block, %line, %
ListBlobsResponseToResourceList.java100% (2/2)50%  (2/4)25%  (21/85)38%  (5/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ListBlobsResponseToResourceList100% (1/1)50%  (1/2)20%  (15/76)42%  (5/12)
apply (ListBlobsResponse): PageSet 0%   (0/1)0%   (0/61)0%   (0/7)
ListBlobsResponseToResourceList (BlobPropertiesToBlobMetadata, PrefixToResour... 100% (1/1)100% (15/15)100% (5/5)
     
class ListBlobsResponseToResourceList$1100% (1/1)50%  (1/2)67%  (6/9)50%  (1/2)
apply (StorageMetadata): String 0%   (0/1)0%   (0/3)0%   (0/1)
ListBlobsResponseToResourceList$1 (ListBlobsResponseToResourceList): void 100% (1/1)100% (6/6)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.azureblob.blobstore.functions;
20 
21import java.util.Map;
22import java.util.Set;
23 
24import javax.inject.Inject;
25import javax.inject.Singleton;
26 
27import org.jclouds.azureblob.domain.ListBlobsResponse;
28import org.jclouds.blobstore.domain.PageSet;
29import org.jclouds.blobstore.domain.StorageMetadata;
30import org.jclouds.blobstore.domain.StorageType;
31import org.jclouds.blobstore.domain.internal.PageSetImpl;
32import org.jclouds.blobstore.functions.PrefixToResourceMetadata;
33 
34import com.google.common.base.Function;
35import com.google.common.collect.Iterables;
36import com.google.common.collect.Maps;
37import com.google.common.collect.Sets;
38 
39/**
40 * @author Adrian Cole
41 */
42@Singleton
43public class ListBlobsResponseToResourceList implements
44         Function<ListBlobsResponse, PageSet<? extends StorageMetadata>> {
45   private final BlobPropertiesToBlobMetadata object2blobMd;
46   private final PrefixToResourceMetadata prefix2ResourceMd;
47 
48   protected final Function<StorageMetadata, String> indexer = new Function<StorageMetadata, String>() {
49      @Override
50      public String apply(StorageMetadata from) {
51         return from.getName();
52      }
53   };
54 
55   @Inject
56   public ListBlobsResponseToResourceList(BlobPropertiesToBlobMetadata object2blobMd,
57            PrefixToResourceMetadata prefix2ResourceMd) {
58      this.object2blobMd = object2blobMd;
59      this.prefix2ResourceMd = prefix2ResourceMd;
60   }
61 
62   public PageSet<? extends StorageMetadata> apply(ListBlobsResponse from) {
63      Set<StorageMetadata> contents = Sets.<StorageMetadata> newHashSet(Iterables.transform(from,
64               object2blobMd));
65 
66      Map<String, StorageMetadata> nameToMd = Maps.uniqueIndex(contents, indexer);
67      for (String prefix : from.getBlobPrefixes()) {
68         prefix = prefix.endsWith("/") ? prefix.substring(0, prefix.lastIndexOf('/')) : prefix;
69         if (!nameToMd.containsKey(prefix)
70                  || nameToMd.get(prefix).getType() != StorageType.RELATIVE_PATH)
71            contents.add(prefix2ResourceMd.apply(prefix));
72      }
73      return new PageSetImpl<StorageMetadata>(contents, from.getNextMarker());
74   }
75}

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