/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

  1. package edu.uncc.parsets.data.old;
  2. import java.io.File;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Iterator;
  6. import java.util.List;
  7. import java.util.Map;
  8. import edu.uncc.parsets.data.DataType;
  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. public class CSVDataSet implements Iterable<DataDimension> {
  38. // List of dimensions, in order of appearance in data file
  39. protected List<DataDimension> dimensions = new ArrayList<DataDimension>();
  40. // Map the dimension key and/or name to the dimension. Dimensions can be
  41. // included more than once under different names here.
  42. protected Map<String, DataDimension> dimensionsmap = new HashMap<String, DataDimension>();
  43. protected String filename;
  44. // The name of the dataset, or the filename if nothing specified in the XML file.
  45. private String name;
  46. private String section = "Misc";
  47. private String url;
  48. private String sourceName = "";
  49. private String sourceURL = "";
  50. private int numRecords = 0;
  51. public CSVDataSet(String filename) {
  52. this.filename = filename;
  53. name = (new File(filename)).getName();
  54. int lastPeriod = name.lastIndexOf('.');
  55. if (lastPeriod > 0)
  56. name = name.substring(0, lastPeriod);
  57. }
  58. public DataDimension addDimension(String key, DataDimension dim) {
  59. dimensionsmap.put(key, dim);
  60. return dim;
  61. }
  62. public void instantiateDimension(String key) {
  63. if (dimensionsmap.containsKey(key))
  64. dimensions.add(dimensionsmap.get(key));
  65. else {
  66. DataDimension dim = new DataDimension(key, DataType.numerical);
  67. dimensions.add(dim);
  68. }
  69. }
  70. public DataDimension getDimension(int index) {
  71. return dimensions.get(index);
  72. }
  73. public int getNumDimensions() {
  74. return dimensions.size();
  75. }
  76. public Iterator<DataDimension> iterator() {
  77. return dimensions.iterator();
  78. }
  79. public String getFilename() {
  80. return filename;
  81. }
  82. public String getFileBaseName() {
  83. return (new File(filename)).getName();
  84. }
  85. public String getName() {
  86. return name;
  87. }
  88. public void setName(String newName) {
  89. name = newName;
  90. }
  91. public void setSection(String value) {
  92. section = value;
  93. }
  94. public String getSection() {
  95. return section;
  96. }
  97. public void setURL(String newURL) {
  98. url = newURL;
  99. }
  100. public String getURL() {
  101. return url;
  102. }
  103. public void setSource(String text) {
  104. sourceName = text;
  105. }
  106. public String getSource() {
  107. return sourceName;
  108. }
  109. public void setSourceURL(String text) {
  110. sourceURL = text;
  111. }
  112. public String getSourceURL() {
  113. return sourceURL;
  114. }
  115. public void setNumRecords(int newNum) {
  116. numRecords = newNum;
  117. }
  118. public int getNumRecords() {
  119. return numRecords;
  120. }
  121. }