EMMA Coverage Report (generated Fri Aug 26 14:14:05 EDT 2011)
[all classes][org.jclouds.s3.blobstore.functions]

COVERAGE SUMMARY FOR SOURCE FILE [BucketToResourceList.java]

nameclass, %method, %block, %line, %
BucketToResourceList.java0%   (0/2)0%   (0/4)0%   (0/85)0%   (0/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BucketToResourceList0%   (0/1)0%   (0/2)0%   (0/76)0%   (0/12)
BucketToResourceList (ObjectToBlobMetadata, CommonPrefixesToResourceMetadata)... 0%   (0/1)0%   (0/15)0%   (0/5)
apply (ListBucketResponse): PageSet 0%   (0/1)0%   (0/61)0%   (0/7)
     
class BucketToResourceList$10%   (0/1)0%   (0/2)0%   (0/9)0%   (0/2)
BucketToResourceList$1 (BucketToResourceList): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (StorageMetadata): String 0%   (0/1)0%   (0/3)0%   (0/1)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.s3.blobstore.functions;
20 
21import java.util.Map;
22import java.util.Set;
23 
24import javax.inject.Inject;
25import javax.inject.Singleton;
26 
27import org.jclouds.s3.domain.ListBucketResponse;
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;
32 
33import com.google.common.base.Function;
34import com.google.common.collect.Iterables;
35import com.google.common.collect.Maps;
36import com.google.common.collect.Sets;
37 
38/**
39 * @author Adrian Cole
40 */
41@Singleton
42public class BucketToResourceList implements
43         Function<ListBucketResponse, PageSet<? extends StorageMetadata>> {
44   private final ObjectToBlobMetadata object2blobMd;
45   private final CommonPrefixesToResourceMetadata prefix2ResourceMd;
46 
47   protected final Function<StorageMetadata, String> indexer = new Function<StorageMetadata, String>() {
48      @Override
49      public String apply(StorageMetadata from) {
50         return from.getName();
51      }
52   };
53 
54   @Inject
55   public BucketToResourceList(ObjectToBlobMetadata object2blobMd,
56            CommonPrefixesToResourceMetadata prefix2ResourceMd) {
57      this.object2blobMd = object2blobMd;
58      this.prefix2ResourceMd = prefix2ResourceMd;
59   }
60 
61   public PageSet<? extends StorageMetadata> apply(ListBucketResponse from) {
62      Set<StorageMetadata> contents = Sets.<StorageMetadata> newHashSet(Iterables.transform(from,
63               object2blobMd));
64 
65      Map<String, StorageMetadata> nameToMd = Maps.uniqueIndex(contents, indexer);
66      for (String prefix : from.getCommonPrefixes()) {
67         prefix = prefix.endsWith("/") ? prefix.substring(0, prefix.lastIndexOf('/')) : prefix;
68         if (!nameToMd.containsKey(prefix)
69                  || nameToMd.get(prefix).getType() != StorageType.RELATIVE_PATH)
70            contents.add(prefix2ResourceMd.apply(prefix));
71      }
72      return new PageSetImpl<StorageMetadata>(contents, from.getNextMarker());
73   }
74}

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