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

COVERAGE SUMMARY FOR SOURCE FILE [ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java]

nameclass, %method, %block, %line, %
ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java100% (1/1)100% (2/2)100% (78/78)100% (17/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ListOfKeyValuesDelimitedByBlankLinesToListOfMaps100% (1/1)100% (2/2)100% (78/78)100% (17/17)
ListOfKeyValuesDelimitedByBlankLinesToListOfMaps (): void 100% (1/1)100% (3/3)100% (1/1)
apply (String): List 100% (1/1)100% (75/75)100% (16/16)

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.cloudsigma.functions;
20 
21import java.util.List;
22import java.util.Map;
23 
24import javax.inject.Singleton;
25 
26import com.google.common.base.Function;
27import com.google.common.base.Splitter;
28import com.google.common.collect.Lists;
29import com.google.common.collect.Maps;
30 
31/**
32 * 
33 * @author Adrian Cole
34 */
35@Singleton
36public class ListOfKeyValuesDelimitedByBlankLinesToListOfMaps implements Function<String, List<Map<String, String>>> {
37 
38   @Override
39   public List<Map<String, String>> apply(String from) {
40      List<Map<String, String>> maps = Lists.newArrayList();
41      for (String listOfKeyValues : Splitter.on("\n\n").split(from)) {
42         if (!"".equals(listOfKeyValues)) {
43            Map<String, String> map = Maps.newLinkedHashMap();
44            for (String keyValueLine : Splitter.on('\n').split(listOfKeyValues)) {
45               if (!"".equals(keyValueLine)) {
46                  int firstIndex = keyValueLine.indexOf(' ');
47                  if (firstIndex != -1) {
48                     String key = keyValueLine.substring(0, firstIndex);
49                     String value = keyValueLine.substring(firstIndex + 1).replace("\\n", "\n");
50                     map.put(key, value);
51                  }
52               }
53            }
54            if (map.size() != 0)
55               maps.add(map);
56         }
57      }
58      return maps;
59   }
60}

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