Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / model / MultipleCategorySeries.java
diff --git a/android-libraries/achartengine/src/org/achartengine/model/MultipleCategorySeries.java b/android-libraries/achartengine/src/org/achartengine/model/MultipleCategorySeries.java
new file mode 100644 (file)
index 0000000..992db4c
--- /dev/null
@@ -0,0 +1,145 @@
+/**\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 multiple category charts like the doughnut.\r
+ */\r
+public class MultipleCategorySeries implements Serializable {\r
+  /** The series title. */\r
+  private String mTitle;\r
+  /** The series local keys. */\r
+  private List<String> mCategories = new ArrayList<String>();\r
+  /** The series name. */\r
+  private List<String[]> mTitles = 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 MultipleCategorySeries(String title) {\r
+    mTitle = title;\r
+  }\r
+\r
+  /**\r
+   * Adds a new value to the series\r
+   * \r
+   * @param titles the titles to be used as labels\r
+   * @param values the new value\r
+   */\r
+  public void add(String[] titles, double[] values) {\r
+    add(mCategories.size() + "", titles, values);\r
+  }\r
+\r
+  /**\r
+   * Adds a new value to the series.\r
+   * \r
+   * @param category the category name\r
+   * @param titles the titles to be used as labels\r
+   * @param values the new value\r
+   */\r
+  public void add(String category, String[] titles, double[] values) {\r
+    mCategories.add(category);\r
+    mTitles.add(titles);\r
+    mValues.add(values);\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 void remove(int index) {\r
+    mCategories.remove(index);\r
+    mTitles.remove(index);\r
+    mValues.remove(index);\r
+  }\r
+\r
+  /**\r
+   * Removes all the existing values from the series.\r
+   */\r
+  public void clear() {\r
+    mCategories.clear();\r
+    mTitles.clear();\r
+    mValues.clear();\r
+  }\r
+\r
+  /**\r
+   * Returns the values at the specified index.\r
+   * \r
+   * @param index the index\r
+   * @return the value at the index\r
+   */\r
+  public double[] getValues(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 String getCategory(int index) {\r
+    return mCategories.get(index);\r
+  }\r
+\r
+  /**\r
+   * Returns the categories count.\r
+   * \r
+   * @return the categories count\r
+   */\r
+  public int getCategoriesCount() {\r
+    return mCategories.size();\r
+  }\r
+\r
+  /**\r
+   * Returns the series item count.\r
+   * \r
+   * @param index the index\r
+   * @return the series item count\r
+   */\r
+  public int getItemCount(int index) {\r
+    return mValues.get(index).length;\r
+  }\r
+\r
+  /**\r
+   * Returns the series titles.\r
+   * \r
+   * @param index the index\r
+   * @return the series titles\r
+   */\r
+  public String[] getTitles(int index) {\r
+    return mTitles.get(index);\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
+    return xySeries;\r
+  }\r
+}\r