Added throws declarations for IOExceptions on Issue setters.

The FileIssue implementation now checks to ensure the success of the setters.
This commit is contained in:
Jonathan Bernard
2010-05-19 09:54:18 -05:00
parent c39061f771
commit b7670e69f3
11 changed files with 160 additions and 27 deletions

View File

@ -23,31 +23,64 @@ public class FileIssue extends Issue {
this.source = file
text = file.text
super.@text = file.text
}
public void setCategory(Category c) {
super.setCategory(c)
source.renameTo(new File(source.canonicalFile.parentFile, getFilename()))
public void setCategory(Category c) throws IOException {
boolean renamed
renamed = source.renameTo(new File(source.canonicalFile.parentFile,
makeFilename(id, c, status, priority)))
if (!renamed)
throw new IOException("I was unable to set the category. "
+ "I need to rename the file for this issue, but something is "
+ "preventing me from doing so (maybe the path to the file is "
+ "no longer valid, or maybe the file is currently open in "
+ "some other program).")
else super.setCategory(c)
}
public void setStatus(Status s) {
super.setStatus(s)
source.renameTo(new File(source.canonicalFile.parentFile, getFilename()))
public void setStatus(Status s) throws IOException {
boolean renamed
renamed = source.renameTo(new File(source.canonicalFile.parentFile,
makeFilename(id, category, s, priority)))
if (!renamed)
throw new IOException("I was unable to set the status. "
+ "I need to rename the file for this issue, but something is "
+ "preventing me from doing so (maybe the path to the file is "
+ "no longer valid, or maybe the file is currently open in "
+ "some other program).")
else super.setStatus(s)
}
public void setPriority(int p) {
super.setPriority(p)
source.renameTo(new File(source.canonicalFile.parentFile, getFilename()))
public void setPriority(int p) throws IOException {
boolean renamed
renamed = source.renameTo(new File(source.canonicalFile.parentFile,
makeFilename(id, category, status, p)))
if (!renamed)
throw new IOException("I was unable to set the priority. "
+ "I need to rename the file for this issue, but something is "
+ "preventing me from doing so (maybe the path to the file is "
+ "no longer valid, or maybe the file is currently open in "
+ "some other program).")
else super.setPriority(p)
}
public String getFilename() {
return makeFilename(id, category, status, priority)
}
public void setText(String text) {
public void setText(String text) throws IOException {
try { source.write(text) }
catch (IOException ioe) {
throw new IOException("I could not save the new text for this "
+ "issue. I can not write to the file for this issue. I do not"
+ " know why, I am sorry (maybe the file can not be reached).")
}
super.setText(text)
source.write(text)
}
public boolean delete() { return source.delete() }

View File

@ -26,7 +26,7 @@ public abstract class Issue {
public Category getCategory() { return category }
public void setCategory(Category c) {
public void setCategory(Category c) throws IOException {
if (c == null)
throw new IAE("Category cannot be null.")
@ -35,7 +35,7 @@ public abstract class Issue {
public Status getStatus() { return status }
public void setStatus(Status s) {
public void setStatus(Status s) throws IOException {
if (s == null)
throw new IAE("Status cannot be null.")
@ -44,13 +44,15 @@ public abstract class Issue {
public int getPriority() { return priority }
public void setPriority(int p) { priority = Math.min(9, Math.max(0, p)) }
public void setPriority(int p) throws IOException {
priority = Math.min(9, Math.max(0, p))
}
public String getTitle() { return text.readLines()[0] }
public String getText() { return text }
public void setText(String t) { text = t }
public void setText(String t) throws IOException { text = t }
public boolean hasDelivery() { return deliveryDate == null }