/edu/uncc/parsets/data/DataSet.java

https://code.google.com/p/parsets/ · Java · 119 lines · 49 code · 27 blank · 43 comment · 6 complexity · c4a09484faf05a38b7531ad319a0cbdb MD5 · raw file

  1. package edu.uncc.parsets.data;
  2. import edu.uncc.parsets.parsets.SelectionChangeListener;
  3. import java.util.Iterator;
  4. import java.util.List;
  5. import javax.swing.tree.DefaultMutableTreeNode;
  6. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  7. * Copyright (c) 2009, Robert Kosara, Caroline Ziemkiewicz,
  8. * and others (see Authors.txt for full list)
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * * Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * * Neither the name of UNC Charlotte nor the names of its contributors
  20. * may be used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY ITS AUTHORS ''AS IS'' AND ANY
  24. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
  27. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  30. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  32. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  34. /**
  35. * A data source that can produce a {@link CategoryTree}.
  36. */
  37. public abstract class DataSet implements Iterable<DimensionHandle>, Comparable<DataSet>, SelectionChangeListener {
  38. public abstract Iterator<DimensionHandle> iterator();
  39. public abstract CategoryTree getTree(List<DimensionHandle> dimensions);
  40. protected String name;
  41. public String getName() {
  42. return name;
  43. }
  44. /**
  45. * Returns the number of records in this data set. 0 means number unknown
  46. * or not applicable.
  47. *
  48. * @return number of records or 0
  49. */
  50. public abstract int getNumRecords();
  51. /**
  52. * Return the database handle for this data set. This function calls {@link #getName()}
  53. * unless overridden. Only use for talking directly to a database.
  54. *
  55. * @return the database handle of this data set
  56. */
  57. protected String getHandle() {
  58. return getName();
  59. }
  60. public abstract String getURL();
  61. public abstract int getNumDimensions();
  62. public abstract int getNumCategoricalDimensions();
  63. public abstract int getNumNumericDimensions();
  64. public abstract DimensionHandle[] getNumericDimensions();
  65. public DefaultMutableTreeNode getCategoricalDimensionsAsTree() {
  66. DefaultMutableTreeNode root = new DefaultMutableTreeNode(name);
  67. for (DimensionHandle d : this)
  68. if (d.getDataType() == DataType.categorical) {
  69. DefaultMutableTreeNode node = new DefaultMutableTreeNode(d);
  70. for (CategoryHandle cat : d.getCategories())
  71. node.add(new DefaultMutableTreeNode(cat));
  72. root.add(node);
  73. }
  74. return root;
  75. }
  76. public abstract String getSection();
  77. public int compareTo(DataSet o) {
  78. return name.compareToIgnoreCase(o.name);
  79. }
  80. @Override
  81. public boolean equals(Object o) {
  82. if (o instanceof DataSet)
  83. return compareTo((DataSet)o) == 0;
  84. else
  85. return false;
  86. }
  87. @Override
  88. public int hashCode() {
  89. assert false : "hashCode not designed";
  90. return 42; // any arbitrary constant will do
  91. }
  92. }