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

COVERAGE SUMMARY FOR SOURCE FILE [BindMapToHeadersWithPrefix.java]

nameclass, %method, %block, %line, %
BindMapToHeadersWithPrefix.java100% (2/2)80%  (4/5)84%  (62/74)90%  (9.9/11)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindMapToHeadersWithPrefix$1100% (1/1)67%  (2/3)69%  (27/39)72%  (2.9/4)
toString (): String 0%   (0/1)0%   (0/10)0%   (0/1)
apply (String): String 100% (1/1)90%  (18/20)95%  (1.9/2)
BindMapToHeadersWithPrefix$1 (BindMapToHeadersWithPrefix, String): void 100% (1/1)100% (9/9)100% (1/1)
     
class BindMapToHeadersWithPrefix100% (1/1)100% (2/2)100% (35/35)100% (8/8)
BindMapToHeadersWithPrefix (String): void 100% (1/1)100% (14/14)100% (4/4)
bindToRequest (HttpRequest, Object): HttpRequest 100% (1/1)100% (21/21)100% (4/4)

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.binders;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
24 
25import java.util.Map;
26 
27import javax.inject.Inject;
28import javax.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.http.HttpRequest;
32import org.jclouds.http.utils.ModifyRequest;
33import org.jclouds.rest.Binder;
34import org.jclouds.util.Maps2;
35 
36import com.google.common.base.Function;
37import com.google.common.collect.Multimaps;
38 
39/**
40 * 
41 * @author Adrian Cole
42 */
43@Singleton
44public class BindMapToHeadersWithPrefix implements Binder {
45   private final Function<String, String> FN;
46 
47   @Inject
48   public BindMapToHeadersWithPrefix(@Named(PROPERTY_USER_METADATA_PREFIX) final String metadataPrefix) {
49      checkNotNull(metadataPrefix, PROPERTY_USER_METADATA_PREFIX);
50      FN = new Function<String, String>() {
51 
52         @Override
53         public String apply(String arg0) {
54            String inLowercase = arg0.toLowerCase();
55            return (inLowercase.startsWith(metadataPrefix)) ? inLowercase : metadataPrefix + inLowercase;
56         }
57 
58         @Override
59         public String toString() {
60            return "prefix: " + metadataPrefix;
61         }
62 
63      };
64 
65   }
66 
67   @Override
68   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
69      checkArgument(checkNotNull(input, "input") instanceof Map<?,?>, "this binder is only valid for Maps!");
70      checkNotNull(request, "request");
71 
72      @SuppressWarnings("unchecked")
73      Map<String, String> userMetadata = Maps2.transformKeys((Map<String, String>) input, FN);
74      return ModifyRequest.putHeaders(request, Multimaps.forMap(userMetadata));
75   }
76 
77}

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