1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */18package org.apache.hadoop.chukwa.hicc.bean;
1920import javax.xml.bind.annotation.XmlAccessType;
21import javax.xml.bind.annotation.XmlAccessorType;
22import javax.xml.bind.annotation.XmlRootElement;
23import javax.xml.bind.annotation.XmlType;
2425import org.apache.hadoop.chukwa.util.ExceptionUtil;
26import org.apache.log4j.Logger;
27import org.json.simple.JSONArray;
28import org.json.simple.JSONObject;
2930 @XmlRootElement
31 @XmlAccessorType(XmlAccessType.FIELD)
32 @XmlType(propOrder={})
33publicclassSeries {
34private JSONObject series;
35static Logger log = Logger.getLogger(Series.class);
3637publicSeries(String name) {
38 series = new JSONObject();
39try {
40 series.put("name", name);
41 } catch (Exception e) {
42 log.error(ExceptionUtil.getStackTrace(e));
43 }
44 }
4546publicvoid add(long x, double y) {
47try {
48if(!series.containsKey("data")) {
49 series.put("data", new JSONArray());
50 }
51 JSONArray xy = new JSONArray();
52 xy.add(x);
53 xy.add(y);
54 ((JSONArray)series.get("data")).add(xy);
55 } catch(Exception e) {
56 log.error(ExceptionUtil.getStackTrace(e));
57 }
58 }
5960public String toString() {
61return series.toString();
62 }
6364public Object toJSONObject() {
65return series;
66 }
6768public String getData() {
69return (String) series.get("data");
70 }
71 }