Fixed ugly inheritance issue with Issue and FileIssue.
Added Filter unit tests.
This commit is contained in:
@ -4,54 +4,42 @@ import java.lang.IllegalArgumentException as IAE
|
||||
|
||||
public class FileIssue extends Issue {
|
||||
|
||||
File source
|
||||
protected File source
|
||||
|
||||
FileIssue(File file) {
|
||||
public FileIssue(File file) {
|
||||
|
||||
/* I do not like this construction, but groovy automatically
|
||||
* calls obj.setProperty(...) when you type obj.property = ...
|
||||
* There is an exception for fields accessed withing the class
|
||||
* that defines them, it does not catt eh setter/getter, but
|
||||
* this exception does not extend to subclasses accessing member
|
||||
* variables of their parent class. So instead of using Issue's
|
||||
* default constructor and setting the id, category, and priority
|
||||
* fields here, we have to let Issue's constructor initialize
|
||||
* those values.*/
|
||||
super('REPLACE_ME')
|
||||
|
||||
super((file.name =~ /(\d+)([bcft])(\d).*/)[0][1],
|
||||
Category.toCategory((file.name =~ /(\d+)([bcft])(\d).*/)[0][2]),
|
||||
(file.name =~ /(\d+)([bcft])(\d).*/)[0][3].toInteger())
|
||||
def matcher = file.name =~ /(\d{4})([bftc])(\d).*/
|
||||
if (!matcher) return null
|
||||
|
||||
//def matcher = file.name =~ /(\d{4})([bftc])(\d).*/
|
||||
/*if (!matcher) return null
|
||||
|
||||
id = matcher[0][1]
|
||||
category = Category.toCategory(matcher[0][2])
|
||||
priority = matcher[0][3].toInteger()*/
|
||||
super.@id = matcher[0][1]
|
||||
super.@category = Category.toCategory(matcher[0][2])
|
||||
super.@priority = matcher[0][3].toInteger()
|
||||
|
||||
this.source = file
|
||||
|
||||
file.withReader { title = it.readLine() }
|
||||
text = file.text
|
||||
}
|
||||
|
||||
void setCategory(Category c) {
|
||||
public void setCategory(Category c) {
|
||||
super.setCategory(c)
|
||||
source.renameTo(new File(source.canonicalFile.parentFile, getFilename()))
|
||||
}
|
||||
|
||||
void setPriority(int p) {
|
||||
public void setPriority(int p) {
|
||||
super.setPriority(p)
|
||||
source.renameTo(new File(source.canonicalFile.parentFile, getFilename()))
|
||||
}
|
||||
|
||||
String getFilename() { return makeFilename(id, category, priority) }
|
||||
public String getFilename() { return makeFilename(id, category, priority) }
|
||||
|
||||
static boolean isValidFilename(String name) {
|
||||
public static boolean isValidFilename(String name) {
|
||||
return name ==~ /(\d+)([bcft])(\d).*/
|
||||
}
|
||||
|
||||
static String makeFilename(String id, Category category, int priority) {
|
||||
public static String makeFilename(String id, Category category,
|
||||
int priority) {
|
||||
|
||||
// bounds check priority
|
||||
priority = Math.min(9, Math.max(0, priority))
|
||||
|
@ -2,9 +2,9 @@ package com.jdbernard.pit
|
||||
|
||||
class FileProject extends Project {
|
||||
|
||||
File source
|
||||
protected File source
|
||||
|
||||
FileProject(File dir) {
|
||||
public FileProject(File dir) {
|
||||
super(dir.name)
|
||||
|
||||
if (!dir.isDirectory())
|
||||
@ -32,10 +32,6 @@ class FileProject extends Project {
|
||||
}
|
||||
}
|
||||
|
||||
public void rename(String newName) {
|
||||
this.name = newName
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
super.setName(name)
|
||||
source.renameTo(new File(source.canonicalFile.parentFile, name))
|
||||
@ -54,15 +50,21 @@ class FileProject extends Project {
|
||||
id = (id.toInteger() + 1).toString().padLeft(id.length(), '0')
|
||||
}
|
||||
|
||||
def issueFile = new File(source, FileIssue.makeFilename(id, options.category, options.priority))
|
||||
def issueFile = new File(source, FileIssue.makeFilename(id,
|
||||
options.category, options.priority))
|
||||
|
||||
assert !issueFile.exists()
|
||||
|
||||
issueFile.createNewFile()
|
||||
issueFile.write(options.text)
|
||||
|
||||
return new FileIssue(issueFile)
|
||||
def issue = new FileIssue(issueFile)
|
||||
issues[(issue.id)] = issue
|
||||
|
||||
return issue
|
||||
}
|
||||
|
||||
@Override
|
||||
String toString() { return name }
|
||||
public String toString() { return name }
|
||||
|
||||
}
|
||||
|
@ -4,11 +4,10 @@ import java.lang.IllegalArgumentException as IAE
|
||||
|
||||
public class Issue {
|
||||
|
||||
String id
|
||||
Category category
|
||||
int priority
|
||||
String title
|
||||
String text
|
||||
protected String id
|
||||
protected Category category
|
||||
protected int priority
|
||||
protected String text
|
||||
|
||||
Issue(String id, Category c = Category.TASK, int p = 9) {
|
||||
this.id = id
|
||||
@ -16,15 +15,27 @@ public class Issue {
|
||||
this.priority = p
|
||||
}
|
||||
|
||||
void setCategory(Category c) {
|
||||
public String getId() { return id; }
|
||||
|
||||
public Category getCategory() { return category }
|
||||
|
||||
public void setCategory(Category c) {
|
||||
if (c == null)
|
||||
throw new IAE("Category cannot be null.")
|
||||
|
||||
this.category = c
|
||||
}
|
||||
|
||||
void setPriority(int p) { priority = Math.min(9, Math.max(0, p)) }
|
||||
public int getPriority() { return priority }
|
||||
|
||||
public void setPriority(int p) { 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 }
|
||||
|
||||
@Override
|
||||
String toString() { return "${id}(${priority}): ${category} ${title}" }
|
||||
public String toString() { return "${id}(${priority}): ${category} ${title}" }
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package com.jdbernard.pit
|
||||
|
||||
public abstract class Project {
|
||||
|
||||
String name
|
||||
protected String name
|
||||
Map<String, Issue> issues = [:]
|
||||
Map<String, Project> projects = [:]
|
||||
|
||||
@ -22,6 +22,10 @@ public abstract class Project {
|
||||
c.call(p)
|
||||
}
|
||||
|
||||
public void setName(String name) { this.name = name }
|
||||
|
||||
public String getName() { return name }
|
||||
|
||||
@Override
|
||||
String toString() { return name }
|
||||
|
||||
|
Reference in New Issue
Block a user