import java.awt.geom.*; import java.awt.Rectangle; import java.util.ArrayList; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.File; import java.io.FileReader; import java.io.InputStreamReader; import java.io.IOException; //Don't change this file -- it is provided only for reference. /** Static methods to create a BufferedReader for a "map" character stream. * The stream doesn't necessarily come from a file, but can be thought of as a file anyway. * The map is a sequence of line segments * The segments are read from a file * Each line of the file contains the two endpoints of the segment, as follows: * x1 y1 x2 y2 * The map reader builds a list of the line segments * Comment lines start with // and are ignored * Later there will be lines with city or county information */ public class MapReaderFactory { /** Create a buffered reader, given a file name **/ public static BufferedReader createMapReader(String filePath) throws IOException { BufferedReader input; File inFile = new File(filePath); if (inFile == null || !inFile.exists()) { throw new FileNotFoundException("Map Reader can't open " + filePath); } try { input = new BufferedReader(new InputStreamReader (new FileInputStream(inFile))); } catch (Exception e) { throw new FileNotFoundException("Map reader can't get stream from " + filePath + "\n" + e); } return input; } //end constructor /**This constructor builds a stream object that gets data from a / * randomly generated map. The size of the map is also random. */ public static BufferedReader createMapReader() { return new BufferedReader(new RandomMapGeneratorReader()); } /**This constructor builds a stream object that gets data from a / * randomly generated map of an indicated size (number of edges) */ public static BufferedReader createMapReader(int size) { return new BufferedReader(new RandomMapGeneratorReader(size)); } } //end MapFileReader