source: xssim/trunk/src/test/local/db/loader/StatsReader.java @ 104

Revision 104, 1.2 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.local.db.loader;
2
3import java.io.IOException;
4import java.text.NumberFormat;
5import java.text.ParseException;
6
7import simulator.GridSchedulingSimulator;
8
9/**
10 *
11 * @author Marcin Krystek
12 *
13 */
14public abstract class StatsReader {
15
16        protected StatsParser parser;
17        protected String[] values;
18       
19        protected NumberFormat format = GridSchedulingSimulator.DFAULT_NUMBER_FORMAT;
20       
21        public StatsReader(StatsParser p){
22                this.parser = p;
23        }
24       
25        public boolean next(){
26                try {
27                        this.values = parser.readValues();
28                } catch (IOException e) {
29                        e.printStackTrace();
30                        return false;
31                }
32               
33                return (this.values != null);
34        }
35       
36        protected double getAsDouble(int position){
37                try {
38                        double value = format.parse(values[position]).doubleValue();
39                        return value;
40                } catch (ParseException e) {
41                        e.printStackTrace();
42                }
43                return -1;
44        }
45       
46        protected long getAsLong(int position){
47                try {
48                        long value = format.parse(values[position]).longValue();
49                        return value;
50                } catch (ParseException e) {
51                        e.printStackTrace();
52                }
53                return -1;
54        }
55       
56        protected int getAsInt(int position){
57                try {
58                        int value = format.parse(values[position]).intValue();
59                        return value;
60                } catch (ParseException e) {
61                        e.printStackTrace();
62                }
63                return -1;
64        }
65}
Note: See TracBrowser for help on using the repository browser.