create changelog entry
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / model / CategorySeries.java
1 /**\r
2  * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL\r
3  *  \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *  \r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *  \r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 package org.achartengine.model;\r
17 \r
18 import java.io.Serializable;\r
19 import java.util.ArrayList;\r
20 import java.util.List;\r
21 \r
22 /**\r
23  * A series for the category charts like the pie ones.\r
24  */\r
25 public class CategorySeries implements Serializable {\r
26   /** The series title. */\r
27   private String mTitle;\r
28   /** The series categories. */\r
29   private List<String> mCategories = new ArrayList<String>();\r
30   /** The series values. */\r
31   private List<Double> mValues = new ArrayList<Double>();\r
32 \r
33   /**\r
34    * Builds a new category series.\r
35    * \r
36    * @param title the series title\r
37    */\r
38   public CategorySeries(String title) {\r
39     mTitle = title;\r
40   }\r
41 \r
42   /**\r
43    * Returns the series title.\r
44    * \r
45    * @return the series title\r
46    */\r
47   public String getTitle() {\r
48     return mTitle;\r
49   }\r
50 \r
51   /**\r
52    * Adds a new value to the series\r
53    * \r
54    * @param value the new value\r
55    */\r
56   public synchronized void add(double value) {\r
57     add(mCategories.size() + "", value);\r
58   }\r
59 \r
60   /**\r
61    * Adds a new value to the series.\r
62    * \r
63    * @param category the category\r
64    * @param value the new value\r
65    */\r
66   public synchronized void add(String category, double value) {\r
67     mCategories.add(category);\r
68     mValues.add(value);\r
69   }\r
70 \r
71   /**\r
72    * Replaces the value at the specific index in the series.\r
73    * \r
74    * @param index the index in the series\r
75    * @param category the category\r
76    * @param value the new value\r
77    */\r
78   public synchronized void set(int index, String category, double value) {\r
79     mCategories.set(index, category);\r
80     mValues.set(index, value);\r
81   }\r
82 \r
83   /**\r
84    * Removes an existing value from the series.\r
85    * \r
86    * @param index the index in the series of the value to remove\r
87    */\r
88   public synchronized void remove(int index) {\r
89     mCategories.remove(index);\r
90     mValues.remove(index);\r
91   }\r
92 \r
93   /**\r
94    * Removes all the existing values from the series.\r
95    */\r
96   public synchronized void clear() {\r
97     mCategories.clear();\r
98     mValues.clear();\r
99   }\r
100 \r
101   /**\r
102    * Returns the value at the specified index.\r
103    * \r
104    * @param index the index\r
105    * @return the value at the index\r
106    */\r
107   public synchronized double getValue(int index) {\r
108     return mValues.get(index);\r
109   }\r
110 \r
111   /**\r
112    * Returns the category name at the specified index.\r
113    * \r
114    * @param index the index\r
115    * @return the category name at the index\r
116    */\r
117   public synchronized String getCategory(int index) {\r
118     return mCategories.get(index);\r
119   }\r
120 \r
121   /**\r
122    * Returns the series item count.\r
123    * \r
124    * @return the series item count\r
125    */\r
126   public synchronized int getItemCount() {\r
127     return mCategories.size();\r
128   }\r
129 \r
130   /**\r
131    * Transforms the category series to an XY series.\r
132    * \r
133    * @return the XY series\r
134    */\r
135   public XYSeries toXYSeries() {\r
136     XYSeries xySeries = new XYSeries(mTitle);\r
137     int k = 0;\r
138     for (double value : mValues) {\r
139       xySeries.add(++k, value);\r
140     }\r
141     return xySeries;\r
142   }\r
143 }\r