KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > io > PropertyFileStaticDataCollector


1 /*
2  * PropertyFileStaticDataCollector, a collector fpr data
3  * to display in static charts.
4  * Copyright (C) Achim Westermann, created on 10.12.2004, 13:48:55
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  * If you modify or optimize the code in a useful way please let me know.
21  * Achim.Westermann@gmx.de
22  *
23  */

24 package info.monitorenter.gui.chart.io;
25
26 import info.monitorenter.gui.chart.ITrace2D;
27 import info.monitorenter.gui.chart.TracePoint2D;
28
29 import java.io.FileNotFoundException JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.util.Collections JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.LinkedList JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.Map JavaDoc;
37 import java.util.Properties JavaDoc;
38
39 /**
40  * Data collector that collects data in form of
41  * {@link info.monitorenter.gui.chart.TracePoint2D} instances from a property
42  * file ( {@link java.util.Properties}).
43  * <p>
44  *
45  * @author Achim Westermann
46  */

47 public class PropertyFileStaticDataCollector extends AStaticDataCollector {
48
49   /**
50    * The input stream in {@link java.util.Properties} format where
51    * {@link info.monitorenter.gui.chart.TracePoint2D} are parsed from.
52    * <p>
53    */

54   private InputStream JavaDoc m_source;
55
56   /**
57    * Constructor with target trace and property file.
58    * <p>
59    *
60    * @param trace
61    * the target trace to add data to.
62    *
63    * @param propertyFileStream
64    * the stream of the file in the {@link java.util.Properties} format
65    * where {@link info.monitorenter.gui.chart.TracePoint2D} instances
66    * (key is x, value is y) is parsed from.
67    */

68   public PropertyFileStaticDataCollector(final ITrace2D trace, final InputStream JavaDoc propertyFileStream) {
69     super(trace);
70     this.m_source = propertyFileStream;
71   }
72
73   /**
74    * @see info.monitorenter.gui.chart.io.AStaticDataCollector#collectData()
75    */

76   public void collectData() throws FileNotFoundException JavaDoc, IOException JavaDoc {
77     Properties JavaDoc props = new Properties JavaDoc();
78     props.load(this.m_source);
79     Map.Entry JavaDoc entry;
80     Iterator JavaDoc it = props.entrySet().iterator();
81     List JavaDoc sortList = new LinkedList JavaDoc();
82     while (it.hasNext()) {
83       entry = (Map.Entry JavaDoc) it.next();
84       sortList.add(new TracePoint2D(Double.parseDouble((String JavaDoc) entry.getKey()), Double
85           .parseDouble((String JavaDoc) entry.getValue())));
86     }
87     Collections.sort(sortList);
88     it = sortList.iterator();
89     while (it.hasNext()) {
90       m_trace.addPoint((TracePoint2D) it.next());
91     }
92   }
93 }
94
Popular Tags