PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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