src/main/java/de/uapcore/sudoku/DocumentHandler.java

changeset 10
369903afbb29
parent 9
576e7a2861ae
child 11
f7433671fec5
equal deleted inserted replaced
9:576e7a2861ae 10:369903afbb29
30 import java.util.regex.Matcher; 30 import java.util.regex.Matcher;
31 import java.util.regex.Pattern; 31 import java.util.regex.Pattern;
32 32
33 /** 33 /**
34 * 34 *
35 * @author mike
36 */ 35 */
37 public class DocumentHandler { 36 public class DocumentHandler {
38 37
39 private String filename; 38 private String filename;
40 39
40 /**
41 * Loads data into the specified field.
42 *
43 * @param field the field to populated with the loaded data
44 * @throws IOException if loading fails or no file name has been set before
45 * @see #setFilename(String)
46 */
41 public void load(Field field) throws IOException { 47 public void load(Field field) throws IOException {
42 if (!isFilenameSet()) { 48 if (!isFilenameSet()) {
43 throw new IOException("no filename supplied"); 49 throw new IOException("no filename supplied");
44 } 50 }
45 int row = 0; 51 int row = 0;
70 throw new IOException("Kein Sudoku-Feld enthalten!"); 76 throw new IOException("Kein Sudoku-Feld enthalten!");
71 } 77 }
72 } 78 }
73 field.setAllCellsModified(false); 79 field.setAllCellsModified(false);
74 } 80 }
75 81
82 /**
83 * Saves the specified field to a file.
84 *
85 * @param field the field to save
86 * @throws IOException if saving fails or the file name has not been set before
87 * @see #setFilename(String)
88 */
76 public void save(Field field) throws IOException { 89 public void save(Field field) throws IOException {
77 if (!isFilenameSet()) { 90 if (!isFilenameSet()) {
78 throw new IOException("no filename supplied"); 91 throw new IOException("no filename supplied");
79 } 92 }
80 93
87 out.append(j == 8 ? '\n': ' '); 100 out.append(j == 8 ? '\n': ' ');
88 } 101 }
89 } 102 }
90 } 103 }
91 } 104 }
92 105
106 /**
107 * Sets the file name for loading and saving data.
108 *
109 * @param filename the file name
110 */
93 public void setFilename(String filename) { 111 public void setFilename(String filename) {
94 this.filename = filename; 112 this.filename = filename;
95 } 113 }
96 114
115 /**
116 * Clears the file name.
117 */
97 public void clearFilename() { 118 public void clearFilename() {
98 filename = null; 119 filename = null;
99 } 120 }
100 121
122 /**
123 * Checks whether a file name has been set.
124 *
125 * @return true if a file name is known, false otherwise
126 */
101 public boolean isFilenameSet() { 127 public boolean isFilenameSet() {
102 return filename != null; 128 return filename != null;
103 } 129 }
104 } 130 }

mercurial