EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.blobstore.internal]

COVERAGE SUMMARY FOR SOURCE FILE [BaseBlobMap.java]

nameclass, %method, %block, %line, %
BaseBlobMap.java14%  (1/7)4%   (1/26)21%  (78/380)26%  (14.7/57)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BaseBlobMap$10%   (0/1)0%   (0/2)0%   (0/19)0%   (0/2)
BaseBlobMap$1 (BaseBlobMap): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (BlobMetadata): Map$Entry 0%   (0/1)0%   (0/13)0%   (0/1)
     
class BaseBlobMap$20%   (0/1)0%   (0/2)0%   (0/9)0%   (0/2)
BaseBlobMap$2 (BaseBlobMap): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (BlobMetadata): String 0%   (0/1)0%   (0/3)0%   (0/1)
     
class BaseBlobMap$30%   (0/1)0%   (0/2)0%   (0/27)0%   (0/5)
BaseBlobMap$3 (BaseBlobMap): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (BlobMetadata): BlobMetadata 0%   (0/1)0%   (0/21)0%   (0/4)
     
class BaseBlobMap$Entry0%   (0/1)0%   (0/4)0%   (0/33)0%   (0/6)
BaseBlobMap$Entry (BaseBlobMap, String): void 0%   (0/1)0%   (0/9)0%   (0/3)
getKey (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getValue (): Object 0%   (0/1)0%   (0/10)0%   (0/1)
setValue (Object): Object 0%   (0/1)0%   (0/11)0%   (0/1)
     
class BaseBlobMap$PrefixKey0%   (0/1)0%   (0/2)0%   (0/28)0%   (0/5)
BaseBlobMap$PrefixKey (String, String): void 0%   (0/1)0%   (0/15)0%   (0/4)
apply (String): String 0%   (0/1)0%   (0/13)0%   (0/1)
     
class BaseBlobMap$StripPath0%   (0/1)0%   (0/2)0%   (0/29)0%   (0/5)
BaseBlobMap$StripPath (String, String): void 0%   (0/1)0%   (0/15)0%   (0/4)
apply (String): String 0%   (0/1)0%   (0/14)0%   (0/1)
     
class BaseBlobMap100% (1/1)8%   (1/12)33%  (78/235)42%  (14.7/35)
clear (): void 0%   (0/1)0%   (0/8)0%   (0/2)
containsKey (Object): boolean 0%   (0/1)0%   (0/16)0%   (0/2)
containsValue (Object): boolean 0%   (0/1)0%   (0/9)0%   (0/1)
entrySet (): Set 0%   (0/1)0%   (0/9)0%   (0/1)
getAllBlobs (): Iterable 0%   (0/1)0%   (0/28)0%   (0/5)
isEmpty (): boolean 0%   (0/1)0%   (0/7)0%   (0/1)
keySet (): Set 0%   (0/1)0%   (0/9)0%   (0/1)
list (): Iterable 0%   (0/1)0%   (0/13)0%   (0/1)
size (): int 0%   (0/1)0%   (0/9)0%   (0/1)
stripPrefix (Blob): Blob 0%   (0/1)0%   (0/12)0%   (0/2)
toString (): String 0%   (0/1)0%   (0/17)0%   (0/1)
BaseBlobMap (BlobStore, GetBlobsInListStrategy, ContainsValueInListStrategy, ... 100% (1/1)80%  (78/98)87%  (14.7/17)

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.blobstore.internal;
20 
21import static com.google.common.base.Functions.identity;
22import static com.google.common.base.Preconditions.checkArgument;
23import static com.google.common.base.Preconditions.checkNotNull;
24import static com.google.common.collect.Iterables.transform;
25 
26import java.util.Map;
27import java.util.Set;
28 
29import javax.inject.Inject;
30 
31import org.jclouds.blobstore.BlobStore;
32import org.jclouds.blobstore.ListableMap;
33import org.jclouds.blobstore.domain.Blob;
34import org.jclouds.blobstore.domain.BlobMetadata;
35import org.jclouds.blobstore.domain.MutableBlobMetadata;
36import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
37import org.jclouds.blobstore.options.ListContainerOptions;
38import org.jclouds.blobstore.options.ListContainerOptions.ImmutableListContainerOptions;
39import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
40import org.jclouds.blobstore.strategy.GetBlobsInListStrategy;
41import org.jclouds.blobstore.strategy.PutBlobsStrategy;
42import org.jclouds.blobstore.strategy.internal.ListContainerAndRecurseThroughFolders;
43 
44import com.google.common.base.Function;
45import com.google.common.collect.ImmutableSet;
46 
47/**
48 * Implements core Map functionality with a {@link BlobStore}
49 * 
50 * 
51 * @author Adrian Cole
52 */
53public abstract class BaseBlobMap<V> implements ListableMap<String, V> {
54   protected final BlobStore blobstore;
55   protected final String containerName;
56   protected final Function<String, String> prefixer;
57   protected final Function<String, String> pathStripper;
58   protected final ListContainerOptions options;
59   protected final GetBlobsInListStrategy getAllBlobs;
60   protected final ContainsValueInListStrategy containsValueStrategy;
61   protected final ListContainerAndRecurseThroughFolders listStrategy;
62   protected final PutBlobsStrategy putBlobsStrategy;
63 
64   static class StripPath implements Function<String, String> {
65      private final String prefix;
66      private final String delimiter;
67 
68      StripPath(String prefix, String delimiter) {
69         this.prefix = checkNotNull(prefix, "prefix");
70         this.delimiter = checkNotNull(delimiter, "delimiter");
71      }
72 
73      public String apply(String from) {
74         return from.replaceFirst(prefix + delimiter, "");
75      }
76   }
77 
78   static class PrefixKey implements Function<String, String> {
79      private final String prefix;
80      private final String delimiter;
81 
82      PrefixKey(String prefix, String delimiter) {
83         this.prefix = checkNotNull(prefix, "prefix");
84         this.delimiter = checkNotNull(delimiter, "delimiter");
85      }
86 
87      public String apply(String from) {
88         return prefix + delimiter + from;
89      }
90   }
91 
92   @Inject
93   public BaseBlobMap(BlobStore blobstore, GetBlobsInListStrategy getAllBlobs,
94         ContainsValueInListStrategy containsValueStrategy, PutBlobsStrategy putBlobsStrategy,
95         ListContainerAndRecurseThroughFolders listStrategy, String containerName, ListContainerOptions options) {
96      this.blobstore = checkNotNull(blobstore, "blobstore");
97      this.containerName = checkNotNull(containerName, "container");
98      checkArgument(containerName.indexOf('/') == -1,
99            "please specify directory path using the option: inDirectory, not encoded in the container name");
100      this.options = checkNotNull(options, "options") instanceof ImmutableListContainerOptions ? options
101            : new ImmutableListContainerOptions(options);
102      String dir = options.getDir();
103      if (dir == null) {
104         prefixer = identity();
105         pathStripper = prefixer;
106      } else {
107         prefixer = new PrefixKey(dir, "/");
108         pathStripper = new StripPath(dir, "/");
109      }
110      this.getAllBlobs = checkNotNull(getAllBlobs, "getAllBlobs");
111      this.listStrategy = checkNotNull(listStrategy, "listStrategy");
112      this.containsValueStrategy = checkNotNull(containsValueStrategy, "containsValueStrategy");
113      this.putBlobsStrategy = checkNotNull(putBlobsStrategy, "putBlobsStrategy");
114      checkArgument(!containerName.equals(""), "container name must not be a blank string!");
115   }
116 
117   @Override
118   public Set<java.util.Map.Entry<String, V>> entrySet() {
119      return ImmutableSet.copyOf(transform(list(), new Function<BlobMetadata, Map.Entry<String, V>>() {
120         @Override
121         public java.util.Map.Entry<String, V> apply(BlobMetadata from) {
122            return new Entry(pathStripper.apply(from.getName()));
123         }
124      }));
125   }
126 
127   public class Entry implements java.util.Map.Entry<String, V> {
128 
129      private final String key;
130 
131      Entry(String key) {
132         this.key = key;
133      }
134 
135      @Override
136      public String getKey() {
137         return key;
138      }
139 
140      @Override
141      public V getValue() {
142         return get(prefixer.apply(key));
143      }
144 
145      @Override
146      public V setValue(V value) {
147         return put(prefixer.apply(key), value);
148      }
149 
150   }
151 
152   @Override
153   public int size() {
154      return (int) blobstore.countBlobs(containerName, options);
155   }
156 
157   protected Iterable<Blob> getAllBlobs() {
158      Iterable<Blob> returnVal = getAllBlobs.execute(containerName, options);
159      if (options != null) {
160         for (Blob from : returnVal)
161            stripPrefix(from);
162      }
163      return returnVal;
164   }
165 
166   protected Blob stripPrefix(Blob from) {
167      from.getMetadata().setName(pathStripper.apply(from.getMetadata().getName()));
168      return from;
169   }
170 
171   @Override
172   public boolean containsValue(Object value) {
173      return containsValueStrategy.execute(containerName, value, options);
174   }
175 
176   @Override
177   public void clear() {
178      blobstore.clearContainer(containerName, options);
179   }
180 
181   @Override
182   public Set<String> keySet() {
183      return ImmutableSet.copyOf(transform(list(), new Function<BlobMetadata, String>() {
184         @Override
185         public String apply(BlobMetadata from) {
186            return from.getName();
187         }
188      }));
189   }
190 
191   @Override
192   public boolean containsKey(Object key) {
193      String realKey = prefixer.apply(checkNotNull(key, "key").toString());
194      return blobstore.blobExists(containerName, realKey);
195   }
196 
197   @Override
198   public boolean isEmpty() {
199      return size() == 0;
200   }
201 
202   public Iterable<? extends BlobMetadata> list() {
203      return transform(listStrategy.execute(containerName, options), new Function<BlobMetadata, BlobMetadata>() {
204         public BlobMetadata apply(BlobMetadata from) {
205            MutableBlobMetadata md = new MutableBlobMetadataImpl(from);
206            if (options.getDir() != null)
207               md.setName(pathStripper.apply(from.getName()));
208            return md;
209         }
210 
211      });
212   }
213 
214   @Override
215   public String toString() {
216      return "[containerName=" + containerName + ", options=" + options + "]";
217   }
218 
219}

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