Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / model / CategorySeries.java
diff --git a/android-libraries/achartengine/src/org/achartengine/model/CategorySeries.java b/android-libraries/achartengine/src/org/achartengine/model/CategorySeries.java
new file mode 100644 (file)
index 0000000..ae31c7d
--- /dev/null
@@ -0,0 +1,143 @@
+/**\r
+ * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL\r
+ *  \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *  \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *  \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.achartengine.model;\r
+\r
+import java.io.Serializable;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+/**\r
+ * A series for the category charts like the pie ones.\r
+ */\r
+public class CategorySeries implements Serializable {\r
+  /** The series title. */\r
+  private String mTitle;\r
+  /** The series categories. */\r
+  private List<String> mCategories = new ArrayList<String>();\r
+  /** The series values. */\r
+  private List<Double> mValues = new ArrayList<Double>();\r
+\r
+  /**\r
+   * Builds a new category series.\r
+   * \r
+   * @param title the series title\r
+   */\r
+  public CategorySeries(String title) {\r
+    mTitle = title;\r
+  }\r
+\r
+  /**\r
+   * Returns the series title.\r
+   * \r
+   * @return the series title\r
+   */\r
+  public String getTitle() {\r
+    return mTitle;\r
+  }\r
+\r
+  /**\r
+   * Adds a new value to the series\r
+   * \r
+   * @param value the new value\r
+   */\r
+  public synchronized void add(double value) {\r
+    add(mCategories.size() + "", value);\r
+  }\r
+\r
+  /**\r
+   * Adds a new value to the series.\r
+   * \r
+   * @param category the category\r
+   * @param value the new value\r
+   */\r
+  public synchronized void add(String category, double value) {\r
+    mCategories.add(category);\r
+    mValues.add(value);\r
+  }\r
+\r
+  /**\r
+   * Replaces the value at the specific index in the series.\r
+   * \r
+   * @param index the index in the series\r
+   * @param category the category\r
+   * @param value the new value\r
+   */\r
+  public synchronized void set(int index, String category, double value) {\r
+    mCategories.set(index, category);\r
+    mValues.set(index, value);\r
+  }\r
+\r
+  /**\r
+   * Removes an existing value from the series.\r
+   * \r
+   * @param index the index in the series of the value to remove\r
+   */\r
+  public synchronized void remove(int index) {\r
+    mCategories.remove(index);\r
+    mValues.remove(index);\r
+  }\r
+\r
+  /**\r
+   * Removes all the existing values from the series.\r
+   */\r
+  public synchronized void clear() {\r
+    mCategories.clear();\r
+    mValues.clear();\r
+  }\r
+\r
+  /**\r
+   * Returns the value at the specified index.\r
+   * \r
+   * @param index the index\r
+   * @return the value at the index\r
+   */\r
+  public synchronized double getValue(int index) {\r
+    return mValues.get(index);\r
+  }\r
+\r
+  /**\r
+   * Returns the category name at the specified index.\r
+   * \r
+   * @param index the index\r
+   * @return the category name at the index\r
+   */\r
+  public synchronized String getCategory(int index) {\r
+    return mCategories.get(index);\r
+  }\r
+\r
+  /**\r
+   * Returns the series item count.\r
+   * \r
+   * @return the series item count\r
+   */\r
+  public synchronized int getItemCount() {\r
+    return mCategories.size();\r
+  }\r
+\r
+  /**\r
+   * Transforms the category series to an XY series.\r
+   * \r
+   * @return the XY series\r
+   */\r
+  public XYSeries toXYSeries() {\r
+    XYSeries xySeries = new XYSeries(mTitle);\r
+    int k = 0;\r
+    for (double value : mValues) {\r
+      xySeries.add(++k, value);\r
+    }\r
+    return xySeries;\r
+  }\r
+}\r