View Javadoc

1   package cz.cuni.amis.pogamut.defcon.communication.worldview.polygons.loaders.borders;
2   
3   import java.io.BufferedWriter;
4   import java.io.File;
5   import java.io.FileWriter;
6   import java.io.IOException;
7   import java.util.List;
8   
9   import cz.cuni.amis.pogamut.defcon.base3d.worldview.object.DefConLocation;
10  
11  /**
12   * Saves borders to given path.
13   * 
14   * @author Radek 'Black_Hand' Pibil
15   * 
16   */
17  public class FilePrecomputedBordersSaver implements IPrecomputedBordersSaver {
18  
19  	private String pathString;
20  	private File path;
21  
22  	public FilePrecomputedBordersSaver(String pathString) {
23  		this.pathString = pathString;
24  		this.path = new File(pathString);
25  
26  		if (!this.path.exists()) {
27  			this.path.mkdir();
28  		}
29  
30  		if (!this.path.isDirectory())
31  			throw new IllegalArgumentException(
32  					"FilePrecomputedBordersSaver: pathString has to point to a directory");
33  	}
34  
35  	@Override
36  	public void saveBorderOfTerritory(
37  			String fileName, List<List<DefConLocation>> territoryBorders)
38  			throws IOException {
39  		BufferedWriter output = new BufferedWriter(new FileWriter(new File(
40  				path, fileName)));
41  
42  		for (List<DefConLocation> locations : territoryBorders) {
43  			output.write(locations.toString());
44  			output.write("\n");
45  		}
46  		output.close();
47  	}
48  
49  	public final String getPathString() {
50  		return pathString;
51  	}
52  }