Subversion Repositories programming

Rev

Rev 412 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 412 Rev 415
Line 1... Line 1...
1
/*******************************************************************************
1
/*******************************************************************************
2
 * File: ConfigParser.java
2
 * ConfigParser.java
3
 *
3
 *
4
 * Holds the ConfigParser class, which automatically parses the given
4
 * Holds the ConfigParser class, which automatically parses the given
5
 * configuration file.
5
 * configuration file.
6
 *
6
 *
7
 * Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)
7
 * Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)
Line 27... Line 27...
27
 
27
 
28
import java.io.*;
28
import java.io.*;
29
import java.lang.String;
29
import java.lang.String;
30
import java.util.Vector;
30
import java.util.Vector;
31
 
31
 
-
 
32
/**
-
 
33
 * Automatic parser for the CS431 Project #1 configuration format. This will
-
 
34
 * read from the keyboard unless a filename is given.
-
 
35
 *
-
 
36
 * @class CS431 Spring 2006
-
 
37
 * @author Ira W. Snyder (devel@irasnyder.com)
-
 
38
 */
32
class ConfigParser
39
public class ConfigParser
33
{
40
{
-
 
41
    /** Current input device: keyboard or file */
34
    private BufferedReader input;
42
    private BufferedReader input;
-
 
43
 
-
 
44
    /** Flag specifying the input type */
35
    private boolean kbd_input = false;
45
    private boolean kbd_input = false;
-
 
46
 
-
 
47
    /** The Round Robin Interval listed in the configuration */
36
    private int RRInterval;
48
    private int RRInterval;
-
 
49
 
-
 
50
    /** The Processes that were listed in the configuration */
37
    private Vector<Process> Processes = new Vector<Process> ();
51
    private Vector<Process> Processes = new Vector<Process> ();
38
 
52
 
-
 
53
    /**
-
 
54
     * Constructor for the ConfigParser class. This is the default constructor,
-
 
55
     * which will read from the keyboard.
-
 
56
     */
39
    public ConfigParser ()
57
    public ConfigParser ()
40
    {
58
    {
41
        input = new BufferedReader (
59
        input = new BufferedReader (
42
                    new InputStreamReader (System.in));
60
                    new InputStreamReader (System.in));
43
        kbd_input = true;
61
        kbd_input = true;
44
 
62
 
45
        parse ();
63
        parse ();
46
    }
64
    }
47
 
65
 
-
 
66
    /**
-
 
67
     * Constructor for the the ConfigParser class. This constructor reads its
-
 
68
     * input from a file.
-
 
69
     *
-
 
70
     * @param filename the file to read input from
-
 
71
     */
48
    public ConfigParser (String filename)
72
    public ConfigParser (String filename)
49
    {
73
    {
50
        try
74
        try
51
        {
75
        {
52
            input = new BufferedReader (
76
            input = new BufferedReader (
Line 60... Line 84...
60
        }
84
        }
61
 
85
 
62
        parse ();
86
        parse ();
63
    }
87
    }
64
 
88
 
-
 
89
    /**
-
 
90
     * Read all values via the current input method, and store them so that
-
 
91
     * they can be read later.
-
 
92
     * <p>
-
 
93
     * This method is automatically called by the constructors of this class.
-
 
94
     */
65
    private void parse ()
95
    private void parse ()
66
    {
96
    {
67
        String s = null;
97
        String s = null;
68
        int ptime;
98
        int ptime;
69
        String pname;
99
        String pname;
Line 90... Line 120...
90
            System.err.println ("Error reading file!");
120
            System.err.println ("Error reading file!");
91
            System.exit (2);
121
            System.exit (2);
92
        }
122
        }
93
    }
123
    }
94
 
124
 
-
 
125
    /**
-
 
126
     * Accessor method for the private variable Processes.
-
 
127
     * <p>
-
 
128
     * NOTE: this is NOT a copy, so don't modify this! Make a copy first.
-
 
129
     *
-
 
130
     * @return the private variable Processes.
-
 
131
     */
95
    public Vector<Process> getProcesses ()
132
    public Vector<Process> getProcesses ()
96
    {
133
    {
97
        return this.Processes;
134
        return this.Processes;
98
    }
135
    }
99
 
136
 
-
 
137
    /**
-
 
138
     * Accessor method for the private variable RRInterval.
-
 
139
     *
-
 
140
     * @return the Round Robin Interval from the configuration file
-
 
141
     */
100
    public int getRRInterval ()
142
    public int getRRInterval ()
101
    {
143
    {
102
        return this.RRInterval;
144
        return this.RRInterval;
103
    }
145
    }
104
}
146
}