create changelog entry
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / model / XYValueSeries.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 import org.achartengine.util.MathHelper;\r
22 \r
23 /**\r
24  * An extension of the XY series which adds a third dimension. It is used for XY\r
25  * charts like bubble.\r
26  */\r
27 public class XYValueSeries extends XYSeries {\r
28   /** A list to contain the series values. */\r
29   private List<Double> mValue = new ArrayList<Double>();\r
30   /** The minimum value. */\r
31   private double mMinValue = MathHelper.NULL_VALUE;\r
32   /** The maximum value. */\r
33   private double mMaxValue = -MathHelper.NULL_VALUE;\r
34 \r
35   /**\r
36    * Builds a new XY value series.\r
37    * \r
38    * @param title the series title.\r
39    */\r
40   public XYValueSeries(String title) {\r
41     super(title);\r
42   }\r
43 \r
44   /**\r
45    * Adds a new value to the series.\r
46    * \r
47    * @param x the value for the X axis\r
48    * @param y the value for the Y axis\r
49    * @param value the value\r
50    */\r
51   public synchronized void add(double x, double y, double value) {\r
52     super.add(x, y);\r
53     mValue.add(value);\r
54     updateRange(value);\r
55   }\r
56 \r
57   /**\r
58    * Initializes the values range.\r
59    */\r
60   private void initRange() {\r
61     mMinValue = MathHelper.NULL_VALUE;\r
62     mMaxValue = MathHelper.NULL_VALUE;\r
63     int length = getItemCount();\r
64     for (int k = 0; k < length; k++) {\r
65       updateRange(getValue(k));\r
66     }\r
67   }\r
68 \r
69   /**\r
70    * Updates the values range.\r
71    * \r
72    * @param value the new value\r
73    */\r
74   private void updateRange(double value) {\r
75     mMinValue = Math.min(mMinValue, value);\r
76     mMaxValue = Math.max(mMaxValue, value);\r
77   }\r
78 \r
79   /**\r
80    * Adds a new value to the series.\r
81    * \r
82    * @param x the value for the X axis\r
83    * @param y the value for the Y axis\r
84    */\r
85   public synchronized void add(double x, double y) {\r
86     add(x, y, 0d);\r
87   }\r
88 \r
89   /**\r
90    * Removes an existing value from the series.\r
91    * \r
92    * @param index the index in the series of the value to remove\r
93    */\r
94   public synchronized void remove(int index) {\r
95     super.remove(index);\r
96     double removedValue = mValue.remove(index);\r
97     if (removedValue == mMinValue || removedValue == mMaxValue) {\r
98       initRange();\r
99     }\r
100   }\r
101 \r
102   /**\r
103    * Removes all the values from the series.\r
104    */\r
105   public synchronized void clear() {\r
106     super.clear();\r
107     mValue.clear();\r
108     initRange();\r
109   }\r
110 \r
111   /**\r
112    * Returns the value at the specified index.\r
113    * \r
114    * @param index the index\r
115    * @return the value\r
116    */\r
117   public synchronized double getValue(int index) {\r
118     return mValue.get(index);\r
119   }\r
120 \r
121   /**\r
122    * Returns the minimum value.\r
123    * \r
124    * @return the minimum value\r
125    */\r
126   public double getMinValue() {\r
127     return mMinValue;\r
128   }\r
129 \r
130   /**\r
131    * Returns the maximum value.\r
132    * \r
133    * @return the maximum value\r
134    */\r
135   public double getMaxValue() {\r
136     return mMaxValue;\r
137   }\r
138 \r
139 }\r