Fleshed out CategorizationPlan implementation.

Added findEntriesToRecategorize() to CategorizationPlan
Refactored createNewCategory() to newCategory() on CategorizationPlan
Refactored Category to use CategorizationPlans
Created CatPlan for DescriptionBasedCategory
Made Event cloneable.
Refactored Category implementations to be aware of the single arg
  Category constructor.
Created TwoLevelCategory, for entries which inherently have two levels
  of categorization in them.
Created a CatPlan for TwoLevelCategory
Removed the specialization implementation, ITHelpCategory: the new
  TwoLevelCategory is a more general version of the same.
Created CatPlan for TicketCategory
Fixed TicketCategory and TicketPlan to adjust for small difference between
  the old behavour of ITHelpCategory and new TwoLevelCategory
Updated testing starter script.
This commit is contained in:
Jonathan Bernard
2011-01-12 17:21:39 -06:00
parent 24600b46d9
commit ab1c7f2393
16 changed files with 159 additions and 117 deletions

View File

@ -1,58 +0,0 @@
package com.quantumdigital.ithelp.timeanalyzer
import com.jdbernard.timeanalyzer.Category
import com.jdbernard.timeanalyzer.Entry
import com.jdbernard.timeanalyzer.Event
public class ITHelpCategory extends Category {
private def ithelpPattern = ~/^ITHelp:\s*(.*)$/
private def ticketPattern = ~/^ITHelp:.*#(\d+).*/
public boolean matchesEvent(Event e) {
return (e.description ==~ ithelpPattern)
}
public Entry addEvent(Event e) {
Entry entry
// try to add to an existing category
entry = addToSubcategory(e)
// no existing category matches
if (!entry) {
// see if it is a new ticket entry
def ticketMatch = e.description =~ ticketPattern
// if is a new ticket
if(ticketMatch) {
// parse the ticket number
int ticketId = ticketMatch[0][1] as int
// create the category
TicketCategory category = new TicketCategory(ticketId)
// add the category to our list
categories << category
// add the event to the category
entry = category.addEvent(e)
}
// not a new ticket, use the general logic for adding
else {
// add a general entry to this category
entry = super.addEvent(e)
// adjust the description (remove the ITHelp tag)
def m = entry.description =~ ithelpPattern
entry.description = m[0][1]
}
}
return entry
}
}

View File

@ -0,0 +1,30 @@
package com.quantumdigital.ithelp.timeanalyzer
import com.jdbernard.timeanalyzer.Category
import com.jdbernard.timeanalyzer.CategorizationPlan
import com.jdbernard.timeanalyzer.Event
import com.jdbernard.timeanalyzer.Entry
public class TicketCategorizationPlan implements CategorizationPlan {
private static def TICKET_PATTERN = ~/.*#(\d+).*/
public boolean deservesNewCategory(Event e, List<Entry> el) {
return e.description ==~ TICKET_PATTERN
}
public Category newCategory(Event e, List<Entry> el) {
def m = e.description =~ TICKET_PATTERN
return new TicketCategory(m[0][1] as int)
}
public List<Entry> findEntriesToRecategorize(Event e,
List<Entry> existingEntries) {
def m = e.description =~ TICKET_PATTERN
int ticketId = m[0][1] as int
return existingEntries.findAll {
it.description ==~ /.*#${ticketId}.*/ }
}
}

View File

@ -14,7 +14,7 @@ public class TicketCategory extends Category {
}
public boolean matchesEvent(Event e) {
return (e.description ==~ /ITHelp:.*#${ticketId}.*/)
return (e.description ==~ /.*#${ticketId}.*/)
}
public TicketEntry addEvent(Event e) {

View File

@ -10,8 +10,7 @@ public class TicketEntry extends Entry {
public TicketEntry(TicketCategory category, Event e) {
super(category, e)
def m = e.description =~ /^ITHelp:\s*(.*#(\d+).*)$/
this.description = m[0][1]
this.id = m[0][2] as int
def m = e.description =~ /.*#(\d+).*/
this.id = m[0][1] as int
}
}