MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / read

Method read

src/org/opensourcephysics/display/Histogram.java:185–217  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 10

lengthMethod · 0.80
parseDoubleMethod · 0.80
doubleValueMethod · 0.80
maxMethod · 0.80
minMethod · 0.80
equalsMethod · 0.65
getMethod · 0.65
closeMethod · 0.65
trimMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected