Put in CategorizationPlan architecture.
This commit is contained in:
parent
ba04aae34e
commit
24600b46d9
@ -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);
|
||||
}
|
@ -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
|
||||
@ -61,14 +65,33 @@ public abstract class Category implements Comparable<Category> {
|
||||
|
||||
public Entry addToSubcategory(Event e) {
|
||||
|
||||
// find all matching subcategories
|
||||
def matchingCategories = categories.findAll { it.matchesEvent(e) }
|
||||
// find all matching subcategories
|
||||
def matchingCategories = categories.findAll { it.matchesEvent(e) }
|
||||
|
||||
if (matchingCategories)
|
||||
if (matchingCategories)
|
||||
return matchingCategories[0].addEvent(e)
|
||||
return null
|
||||
|
||||
// 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 }
|
||||
|
Loading…
x
Reference in New Issue
Block a user