package mapGenerator; 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; /** Produces a buffered reader which reads a "map" from a file. * All methods at present are static. * The map is a sequence of lines representing segments and other information. * The segments are read from a file * Each line representing a segement 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 // * "COUNTY" lines have county information */ public class MapReaderFactory { /** Create a buffered reader, given a file name * @param filePath * @throws IOException In case of any lower, unhandled exception * @return A buffered reader, open and ready to go. * No data has yet been taken from the stream. */ 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 method builds an object that gets data from a * / * randomly generated map * @return */ public static BufferedReader createMapReader() { return new BufferedReader(new RandomMapGeneratorReader()); } /** This method builds an object that gets data from a * / * randomly generated map of an indicated size (number of edges) * @param size Number of border segments in the first or only county * @return A buffered Reader, open and ready, but unread so far. */ public static BufferedReader createMapReader(int size) { return new BufferedReader(new RandomMapGeneratorReader(size)); } /** This method builds an object that reads data from a * randomly generated map of an indicated size (number of edges) * and a random number of "counties". * @param size Number of border segments in the first or only county * @return A buffered Reader, open and ready, but unread so far. */ public static BufferedReader createMapReader(int size, int howManyCounties) { return new BufferedReader(new RandomMapGeneratorReader(size, howManyCounties)); } } //end MapFileReader