PageRenderTime 28ms CodeModel.GetById 2ms app.highlight 19ms RepoModel.GetById 2ms app.codeStats 0ms

/edu/uncc/parsets/data/old/CSVDataSet.java

https://code.google.com/p/parsets/
Java | 155 lines | 89 code | 34 blank | 32 comment | 3 complexity | c7a75e2269f84352a17b6e1e5bde036f MD5 | raw file
  1package edu.uncc.parsets.data.old;
  2
  3import java.io.File;
  4import java.util.ArrayList;
  5import java.util.HashMap;
  6import java.util.Iterator;
  7import java.util.List;
  8import java.util.Map;
  9
 10import edu.uncc.parsets.data.DataType;
 11
 12/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
 13 * Copyright (c) 2009, Robert Kosara, Caroline Ziemkiewicz,
 14 *                     and others (see Authors.txt for full list)
 15 * All rights reserved.
 16 * 
 17 * Redistribution and use in source and binary forms, with or without
 18 * modification, are permitted provided that the following conditions are met:
 19 * 
 20 *    * Redistributions of source code must retain the above copyright
 21 *      notice, this list of conditions and the following disclaimer.
 22 *    * Redistributions in binary form must reproduce the above copyright
 23 *      notice, this list of conditions and the following disclaimer in the
 24 *      documentation and/or other materials provided with the distribution.
 25 *    * Neither the name of UNC Charlotte nor the names of its contributors
 26 *      may be used to endorse or promote products derived from this software
 27 *      without specific prior written permission.
 28 *      
 29 * THIS SOFTWARE IS PROVIDED BY ITS AUTHORS ''AS IS'' AND ANY
 30 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 31 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 32 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
 33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 38 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 39\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 40
 41public class CSVDataSet implements Iterable<DataDimension> {
 42
 43	// List of dimensions, in order of appearance in data file
 44	protected List<DataDimension> dimensions = new ArrayList<DataDimension>();
 45
 46	// Map the dimension key and/or name to the dimension. Dimensions can be
 47	// included more than once under different names here.
 48	protected Map<String, DataDimension> dimensionsmap = new HashMap<String, DataDimension>();
 49
 50	protected String filename;
 51	
 52	// The name of the dataset, or the filename if nothing specified in the XML file.
 53	private String name;
 54
 55	private String section = "Misc";
 56	
 57	private String url;
 58
 59	private String sourceName = "";
 60
 61	private String sourceURL = "";
 62
 63	private int numRecords = 0;
 64	
 65	public CSVDataSet(String filename) {
 66		this.filename = filename;
 67		name = (new File(filename)).getName();
 68		int lastPeriod = name.lastIndexOf('.');
 69		if (lastPeriod > 0)
 70			name = name.substring(0, lastPeriod);
 71	}
 72
 73	public DataDimension addDimension(String key, DataDimension dim) {
 74		dimensionsmap.put(key, dim);
 75		return dim;
 76	}
 77
 78	public void instantiateDimension(String key) {
 79		if (dimensionsmap.containsKey(key))
 80			dimensions.add(dimensionsmap.get(key));
 81		else {
 82			DataDimension dim = new DataDimension(key, DataType.numerical);
 83			dimensions.add(dim);
 84		}
 85	}
 86	
 87	public DataDimension getDimension(int index) {
 88		return dimensions.get(index);
 89	}
 90
 91	public int getNumDimensions() {
 92		return dimensions.size();
 93	}
 94
 95	public Iterator<DataDimension> iterator() {
 96		return dimensions.iterator();
 97	}
 98
 99	
100	public String getFilename() {
101		return filename;
102	}
103
104	public String getFileBaseName() {
105		return (new File(filename)).getName();
106	}
107
108	public String getName() {
109		return name;
110	}
111	
112	public void setName(String newName) {
113		name = newName;
114	}
115
116	public void setSection(String value) {
117		section = value;
118	}
119	
120	public String getSection() {
121		return section;
122	}
123	
124	public void setURL(String newURL) {
125		url = newURL;
126	}
127	
128	public String getURL() {
129		return url;
130	}
131	
132	public void setSource(String text) {
133		sourceName = text;
134	}
135
136	public String getSource() {
137		return sourceName;
138	}
139	
140	public void setSourceURL(String text) {
141		sourceURL = text;
142	}
143	
144	public String getSourceURL() {
145		return sourceURL;
146	}
147	
148	public void setNumRecords(int newNum) {
149		numRecords = newNum;
150	}
151	
152	public int getNumRecords() {
153		return numRecords;
154	}
155}