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

COVERAGE SUMMARY FOR SOURCE FILE [BlobMapImpl.java]

nameclass, %method, %block, %line, %
BlobMapImpl.java0%   (0/2)0%   (0/12)0%   (0/161)0%   (0/30)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BlobMapImpl0%   (0/1)0%   (0/9)0%   (0/133)0%   (0/24)
BlobMapImpl (BlobStore, GetBlobsInListStrategy, ContainsValueInListStrategy, ... 0%   (0/1)0%   (0/23)0%   (0/4)
blobBuilder (): BlobBuilder 0%   (0/1)0%   (0/5)0%   (0/1)
get (Object): Blob 0%   (0/1)0%   (0/24)0%   (0/3)
getLastValue (Object): Blob 0%   (0/1)0%   (0/12)0%   (0/5)
newBlob (String): Blob 0%   (0/1)0%   (0/6)0%   (0/1)
put (String, Blob): Blob 0%   (0/1)0%   (0/19)0%   (0/3)
putAll (Map): void 0%   (0/1)0%   (0/14)0%   (0/2)
remove (Object): Blob 0%   (0/1)0%   (0/21)0%   (0/4)
values (): Collection 0%   (0/1)0%   (0/9)0%   (0/1)
     
class BlobMapImpl$CorrectBlobName0%   (0/1)0%   (0/3)0%   (0/28)0%   (0/6)
BlobMapImpl$CorrectBlobName (Function): void 0%   (0/1)0%   (0/9)0%   (0/3)
apply (Map$Entry): Blob 0%   (0/1)0%   (0/9)0%   (0/1)
apply (String, Blob): Blob 0%   (0/1)0%   (0/10)0%   (0/2)

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.blobstore.internal;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static com.google.common.collect.Iterables.transform;
23 
24import java.util.Collection;
25import java.util.Map;
26 
27import javax.inject.Inject;
28import javax.inject.Provider;
29 
30import org.jclouds.blobstore.BlobMap;
31import org.jclouds.blobstore.BlobStore;
32import org.jclouds.blobstore.KeyNotFoundException;
33import org.jclouds.blobstore.domain.Blob;
34import org.jclouds.blobstore.domain.BlobBuilder;
35import org.jclouds.blobstore.options.ListContainerOptions;
36import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
37import org.jclouds.blobstore.strategy.GetBlobsInListStrategy;
38import org.jclouds.blobstore.strategy.PutBlobsStrategy;
39import org.jclouds.blobstore.strategy.internal.ListContainerAndRecurseThroughFolders;
40 
41import com.google.common.base.Function;
42import com.google.common.collect.ImmutableSet;
43 
44/**
45 * Map representation of a live connection to a Blob Service.
46 * 
47 * @see BlobStore
48 * @see BaseBlobMap
49 * 
50 * @author Adrian Cole
51 */
52public class BlobMapImpl extends BaseBlobMap<Blob> implements BlobMap {
53   public static class CorrectBlobName implements Function<java.util.Map.Entry<? extends String, ? extends Blob>, Blob> {
54      private final Function<String, String> prefixer;
55 
56      public CorrectBlobName(Function<String, String> prefixer) {
57         this.prefixer = checkNotNull(prefixer, "prefixer");
58      }
59 
60      @Override
61      public Blob apply(java.util.Map.Entry<? extends String, ? extends Blob> arg0) {
62         return apply(arg0.getKey(), arg0.getValue());
63      }
64 
65      public Blob apply(String key, Blob blob) {
66         blob.getMetadata().setName(prefixer.apply(key));
67         return blob;
68      }
69   }
70 
71   private final CorrectBlobName correctBlobName;
72   private final Provider<BlobBuilder> blobBuilders;
73 
74   @Inject
75   public BlobMapImpl(BlobStore blobstore, GetBlobsInListStrategy getAllBlobs,
76         ContainsValueInListStrategy containsValueStrategy, PutBlobsStrategy putBlobsStrategy,
77         ListContainerAndRecurseThroughFolders listStrategy, String containerName, ListContainerOptions options,
78         Provider<BlobBuilder> blobBuilders) {
79      super(blobstore, getAllBlobs, containsValueStrategy, putBlobsStrategy, listStrategy, containerName, options);
80      this.correctBlobName = new CorrectBlobName(prefixer);
81      this.blobBuilders = checkNotNull(blobBuilders, "blobBuilders");
82   }
83 
84   @Override
85   public Blob get(Object key) {
86      String realKey = prefixer.apply(checkNotNull(key, "key").toString());
87      Blob blob = blobstore.getBlob(containerName, realKey);
88      return blob != null ? stripPrefix(blob) : null;
89   }
90 
91   @Override
92   public Blob put(String key, Blob value) {
93      Blob returnVal = getLastValue(checkNotNull(key, "key"));
94      blobstore.putBlob(containerName, correctBlobName.apply(key, value));
95      return returnVal;
96   }
97 
98   @Override
99   public void putAll(Map<? extends String, ? extends Blob> map) {
100      putBlobsStrategy.execute(containerName, transform(checkNotNull(map, "map").entrySet(), correctBlobName));
101   }
102 
103   @Override
104   public Blob remove(Object key) {
105      Blob old = getLastValue(checkNotNull(key, "key"));
106      String realKey = prefixer.apply(key.toString());
107      blobstore.removeBlob(containerName, realKey);
108      return old;
109   }
110 
111   private Blob getLastValue(Object key) {
112      Blob old;
113      try {
114         old = get(checkNotNull(key, "key"));
115      } catch (KeyNotFoundException e) {
116         old = null;
117      }
118      return old;
119   }
120 
121   @Override
122   public Collection<Blob> values() {
123      return ImmutableSet.copyOf(getAllBlobs.execute(containerName, options));
124   }
125 
126   @Override
127   public Blob newBlob(String name) {
128      return blobBuilder().name(name).build();
129   }
130 
131   @Override
132   public BlobBuilder blobBuilder() {
133      return blobBuilders.get();
134   }
135}

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