Put in CategorizationPlan architecture.

This commit is contained in:
Jonathan Bernard 2011-01-12 06:54:03 -06:00
parent ba04aae34e
commit 24600b46d9
2 changed files with 36 additions and 4 deletions

View File

@ -0,0 +1,9 @@
package com.jdbernard.timeanalyzer;
import java.util.List;
import java.util.Map;
public interface CategorizationPlan {
boolean deservesNewCategory(Event event, List<Entry> existingEntries);
Map createNewCategory(Event event, List<Entry> existingEntries);
}

View File

@ -9,11 +9,13 @@ public abstract class Category implements Comparable<Category> {
public List<Entry> entries
public List<Category> categories
public List<CategorizationPlan> categorizationPlans
public String description
public Category() {
entries = []
categories = []
categorizationPlans = []
description = "Unnamed Category"
}
@ -26,6 +28,8 @@ public abstract class Category implements Comparable<Category> {
entry = addToSubcategory(e)
if (!entry) {
// if not, do we have a plan for categorizing this event?
// if not, do we have another entry that could be grouped with
// this one to create a new category, based on the description?
def existingEntry = entries.find
@ -66,9 +70,28 @@ public abstract class Category implements Comparable<Category> {
if (matchingCategories)
return matchingCategories[0].addEvent(e)
// no matching subcategories, can we create a new one based on one
// of our plans?
def matchingPlans = categorizationPlans.findAll
{ it.deservesNewCategory(e, entries) }
if (matchingPlans) {
// create the new category
def result = matchingPlans.createNewCategory(e, entries)
// add it to our list of cateogries
categories << result.category
// return new entry
return result.entry
}
return null
}
public Entry
public Duration getDuration() {
return categories.sum(new Duration(0)) { it.duration } +
entries.sum(new Duration(0)) { it.duration }