EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.json.internal]

COVERAGE SUMMARY FOR SOURCE FILE [ParseObjectFromElement.java]

nameclass, %method, %block, %line, %
ParseObjectFromElement.java100% (1/1)60%  (3/5)86%  (74/86)92%  (15.7/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseObjectFromElement100% (1/1)60%  (3/5)86%  (74/86)92%  (15.7/17)
valueOf (String): ParseObjectFromElement 0%   (0/1)0%   (0/5)0%   (0/1)
values (): ParseObjectFromElement [] 0%   (0/1)0%   (0/4)0%   (0/1)
apply (JsonElement): Object 100% (1/1)95%  (55/58)93%  (14/15)
<static initializer> 100% (1/1)100% (14/14)100% (2/2)
ParseObjectFromElement (String, int): void 100% (1/1)100% (5/5)100% (1/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.json.internal;
20 
21import com.google.common.base.Function;
22import com.google.common.collect.Iterables;
23import com.google.common.collect.Lists;
24import com.google.common.collect.Maps;
25import com.google.gson.JsonElement;
26import com.google.gson.JsonPrimitive;
27 
28/**
29 * This is a class that helps the default {@link MapTypeAdapter} make a sane object graph when the
30 * value is set to {@code Object}
31 * http://code.google.com/p/google-gson/issues/detail?id=325
32 * @author Adrian Cole
33 */
34public enum ParseObjectFromElement implements Function<JsonElement, Object> {
35   SINGLETON;
36   public Object apply(JsonElement input) {
37      Object value = null;
38      if (input == null || input.isJsonNull()) {
39         value = null;
40      } else if (input.isJsonPrimitive()) {
41         JsonPrimitive primitive = input.getAsJsonPrimitive();
42         if (primitive.isNumber()) {
43            value = primitive.getAsNumber();
44         } else if (primitive.isBoolean()) {
45            value = primitive.getAsBoolean();
46         } else {
47            value = primitive.getAsString();
48         }
49      } else if (input.isJsonArray()) {
50         value = Lists.newArrayList(Iterables.transform(input.getAsJsonArray(), this));
51      } else if (input.isJsonObject()) {
52         value = Maps.<String,Object>newLinkedHashMap(Maps.transformValues(JsonObjectAsMap.INSTANCE.apply(input.getAsJsonObject()),
53               this));
54      }
55      return value;
56   }
57}

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