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

COVERAGE SUMMARY FOR SOURCE FILE [DatapointHandler.java]

nameclass, %method, %block, %line, %
DatapointHandler.java100% (1/1)100% (5/5)86%  (145/168)87%  (33/38)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DatapointHandler100% (1/1)100% (5/5)86%  (145/168)87%  (33/38)
endElement (String, String, String): void 100% (1/1)76%  (66/87)78%  (14/18)
doubleOrNull (): Double 100% (1/1)88%  (14/16)75%  (3/4)
DatapointHandler (DateService): void 100% (1/1)100% (11/11)100% (4/4)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
getResult (): Datapoint 100% (1/1)100% (46/46)100% (10/10)

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.cloudwatch.xml;
20 
21import java.util.Date;
22 
23import javax.inject.Inject;
24 
25import org.jclouds.cloudwatch.domain.Datapoint;
26import org.jclouds.cloudwatch.domain.StandardUnit;
27import org.jclouds.date.DateService;
28import org.jclouds.http.functions.ParseSax;
29 
30/**
31 * 
32 * @author Adrian Cole
33 */
34public class DatapointHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Datapoint> {
35   private StringBuilder currentText = new StringBuilder();
36 
37   protected final DateService dateService;
38   private Double average;
39   private Double maximum;
40   private Double minimum;
41   private Date timestamp;
42   private Double samples;
43   private Double sum;
44   private StandardUnit unit;
45   private String customUnit;
46 
47   @Inject
48   public DatapointHandler(DateService dateService) {
49      this.dateService = dateService;
50   }
51 
52   public Datapoint getResult() {
53      Datapoint datapoint = new Datapoint(average, maximum, minimum, timestamp, samples, sum, unit, customUnit);
54      this.average = null;
55      this.maximum = null;
56      this.minimum = null;
57      this.timestamp = null;
58      this.samples = null;
59      this.sum = null;
60      this.unit = null;
61      this.customUnit = null;
62      return datapoint;
63   }
64 
65   public void endElement(String uri, String name, String qName) {
66      if (qName.equals("Average")) {
67         average = doubleOrNull();
68      } else if (qName.equals("Maximum")) {
69         maximum = doubleOrNull();
70      } else if (qName.equals("Minimum")) {
71         minimum = doubleOrNull();
72      } else if (qName.equals("Timestamp")) {
73         timestamp = dateService.iso8601SecondsDateParse(currentText.toString().trim());
74      } else if (qName.equals("Samples")) {
75         samples = doubleOrNull();
76      } else if (qName.equals("Sum")) {
77         sum = doubleOrNull();
78      } else if (qName.equals("Unit")) {
79         unit = StandardUnit.fromValue(currentText.toString().trim());
80      } else if (qName.equals("CustomUnit")) {
81         customUnit = currentText.toString().trim();
82      }
83      currentText = new StringBuilder();
84   }
85 
86   private Double doubleOrNull() {
87      String string = currentText.toString().trim();
88      if (!string.equals("")) {
89         return new Double(string);
90      }
91      return null;
92   }
93 
94   public void characters(char ch[], int start, int length) {
95      currentText.append(ch, start, length);
96   }
97}

[all classes][org.jclouds.cloudwatch.xml]
EMMA 2.0.5312 (C) Vladimir Roubtsov