create changelog entry
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / model / RangeCategorySeries.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.util.ArrayList;\r
19 import java.util.List;\r
20 /**\r
21  * A series for the range category charts like the range bar.\r
22  */\r
23 public class RangeCategorySeries extends CategorySeries {\r
24   /** The series values. */\r
25   private List<Double> mMaxValues = new ArrayList<Double>();\r
26   /**\r
27    * Builds a new category series.\r
28    * \r
29    * @param title the series title\r
30    */\r
31   public RangeCategorySeries(String title) {\r
32     super(title);\r
33   }\r
34   /**\r
35    * Adds new values to the series\r
36    * \r
37    * @param minValue the new minimum value\r
38    * @param maxValue the new maximum value\r
39    */\r
40   public synchronized void add(double minValue, double maxValue) {\r
41     super.add(minValue);\r
42     mMaxValues.add(maxValue);\r
43   }\r
44 \r
45   /**\r
46    * Adds new values to the series.\r
47    * \r
48    * @param category the category\r
49    * @param minValue the new minimum value\r
50    * @param maxValue the new maximum value\r
51    */\r
52   public synchronized void add(String category, double minValue, double maxValue) {\r
53     super.add(category, minValue);\r
54     mMaxValues.add(maxValue);\r
55   }\r
56 \r
57   /**\r
58    * Removes existing values from the series.\r
59    * \r
60    * @param index the index in the series of the values to remove\r
61    */\r
62   public synchronized void remove(int index) {\r
63     super.remove(index);\r
64     mMaxValues.remove(index);\r
65   }\r
66 \r
67   /**\r
68    * Removes all the existing values from the series.\r
69    */\r
70   public synchronized void clear() {\r
71     super.clear();\r
72     mMaxValues.clear();\r
73   }\r
74 \r
75   /**\r
76    * Returns the minimum value at the specified index.\r
77    * \r
78    * @param index the index\r
79    * @return the minimum value at the index\r
80    */\r
81   public double getMinimumValue(int index) {\r
82     return getValue(index);\r
83   }\r
84 \r
85   /**\r
86    * Returns the maximum value at the specified index.\r
87    * \r
88    * @param index the index\r
89    * @return the maximum value at the index\r
90    */\r
91   public double getMaximumValue(int index) {\r
92     return mMaxValues.get(index);\r
93   }\r
94 \r
95   /**\r
96    * Transforms the range category series to an XY series.\r
97    * \r
98    * @return the XY series\r
99    */\r
100   public XYSeries toXYSeries() {\r
101     XYSeries xySeries = new XYSeries(getTitle());\r
102     int length = getItemCount();\r
103     for (int k = 0; k < length; k++) {\r
104       xySeries.add(k + 1, getMinimumValue(k));\r
105       // the new fast XYSeries implementation doesn't allow 2 values at the same X,\r
106       // so I had to do a hack until I find a better solution\r
107       xySeries.add(k + 1.000001, getMaximumValue(k));\r
108     }\r
109     return xySeries;\r
110   }\r
111 }\r