Reads a file and appends the data contained in the file to this Histogram. The format of the file is bins \t occurrences. Lines beginning with # and empty lines are ignored. @param inputPathName A pathname string. @exception java.io.IOException Description of the Exception
(String inputPathName)
| 183 | * @exception java.io.IOException Description of the Exception |
| 184 | */ |
| 185 | public void read(String inputPathName) throws java.io.IOException { |
| 186 | java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.FileReader(inputPathName)); |
| 187 | String s = null; |
| 188 | while ((s = reader.readLine()) != null) { |
| 189 | s = s.trim(); |
| 190 | if (s.equals("") || (s.length() == 0) || (s.charAt(0) == '#')) { // ignore empty lines and //$NON-NLS-1$ |
| 191 | // lines beginning with # |
| 192 | continue; |
| 193 | } |
| 194 | try { |
| 195 | java.util.StringTokenizer st = new java.util.StringTokenizer(s, "\t"); //$NON-NLS-1$ |
| 196 | int binNumber = Integer.parseInt(st.nextToken()); |
| 197 | double numberOfoccurrences = Double.parseDouble(st.nextToken()); |
| 198 | Double prioroccurrences = bins.get(Integer.valueOf(binNumber)); |
| 199 | if (prioroccurrences == null) { // first occurence for this bin |
| 200 | bins.put(Integer.valueOf(binNumber), new Double(numberOfoccurrences)); |
| 201 | } else { |
| 202 | numberOfoccurrences += prioroccurrences.doubleValue(); // increase occurrences for bin by |
| 203 | // prioroccurrences |
| 204 | bins.put(Integer.valueOf(binNumber), new Double(numberOfoccurrences)); |
| 205 | } |
| 206 | ymax = Math.max(numberOfoccurrences, ymax); |
| 207 | xmin = Math.min(binNumber * binWidth + binOffset, xmin); |
| 208 | xmax = Math.max(binNumber * binWidth + binWidth + binOffset, xmax); |
| 209 | } catch (java.util.NoSuchElementException nsee) { |
| 210 | nsee.printStackTrace(); |
| 211 | } catch (NumberFormatException nfe) { |
| 212 | nfe.printStackTrace(); |
| 213 | } |
| 214 | } |
| 215 | reader.close(); |
| 216 | dataChanged = true; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Creates a string representation of this Histogram. The bins are displayed in |
nothing calls this directly
no test coverage detected