Initial commit

This commit is contained in:
Jonathan Bernard 2011-01-09 15:11:36 -06:00
commit 9f4008a775
17 changed files with 129 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
build/
*.sw*

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,15 @@
package com.jdbernard.timeanalyzer
public abstract class Category implements Comparable<T extends Category> {
List<Entry> entries
public abstract boolean matchesEvent(Event e)
public abstract Entry addEvent(Event e)
public Category() { entries = [] }
public int compareTo(C other) {
}
}

View File

@ -0,0 +1,6 @@
package com.jdbernard.timanalyzer;
public class Entry extends Event {
public Category category;
}

View File

@ -0,0 +1,13 @@
package com.jdbernard.timeanalyzer;
import org.joda.time.DateTime;
import org.joda.time.Duration;
public class Event {
public String description;
public String notes;
public DateTime start;
public Duration duration;
}

View File

@ -0,0 +1,25 @@
package com.jdbernard.timeanalyzer;
public abstract class EventTransformation {
private Category category;
public EventTransformation(Category cat) {
this.category = cat;
}
/**
* Determine if this transformation is applicable for a given event.
* @param e An event to match.
* @return *true* if this transformation is applicable to the given event,
* *false* otherwise.
*/
public abstract boolean matches(Event e);
/**
* Transform an entry.
* @param e The Event to transform.
* @return A new Entry.
*/
public abstract Entry transform(Event e);
}

View File

@ -0,0 +1,21 @@
package com.jdbernard.timeanalyzer
public class EventTransformer {
List transformations
public EventTransformer(List transformations) {
this.transformations = transformations
}
/**
* Transform an event. The first matching transformation is used.
* @param e The event to transform.
* @return The resulting Entry.
*/
public Entry transform(Event e) {
for (t : transformations)
if (t.matches(e))
return t.transform(t)
}
}

View File

@ -0,0 +1,15 @@
package com.quantumdigital.ithelp.timeanalyzer
import com.jdbernard.timeanalyzer.Category
public class ITHelpCategory extends Category {
public boolean matchesEvent(Event e) {
return (e.description ==~ /^ITHelp:.*/)
}
public ITHelpEntry addEvent(Event e) {
assert eventMatches(e)
}
}

View File

@ -0,0 +1,5 @@
package com.quantumdigital.ithelp.timeanalyzer
import com.jdbernard.timeanalyzer.Event
public class ITHelpEntry extends Entry

View File

@ -0,0 +1,12 @@
package com.quantumdigital.ithelp.timeanalyzer
import com.jdbernard.timeanalyzer.EventTransformation
public class ITHelpEventTransformation extends EventTransformation {
public boolean matches(Event e) {
return e.description ==~ /^ITHelp: .*/
}
public Entry
}

View File

@ -0,0 +1,15 @@
package com.quantumdigital.ithelp.timeanalyzer
import com.jdbernard.timeanalyzer.Category
public class TicketCategory extends Category {
public boolean matchesEvent(Event e) {
return (e.description ==~ /ITHelp:.*#\d+.*/)
}
public TicketEntry addEvent(Event e) {
assert eventMatches(e)
TicketEntry entry = new TicketEntry(e)
entries << entry