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<Entry> entries
|
||||||
public List<Category> categories
|
public List<Category> categories
|
||||||
|
public List<CategorizationPlan> categorizationPlans
|
||||||
public String description
|
public String description
|
||||||
|
|
||||||
public Category() {
|
public Category() {
|
||||||
entries = []
|
entries = []
|
||||||
categories = []
|
categories = []
|
||||||
|
categorizationPlans = []
|
||||||
description = "Unnamed Category"
|
description = "Unnamed Category"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +28,8 @@ public abstract class Category implements Comparable<Category> {
|
|||||||
entry = addToSubcategory(e)
|
entry = addToSubcategory(e)
|
||||||
|
|
||||||
if (!entry) {
|
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
|
// if not, do we have another entry that could be grouped with
|
||||||
// this one to create a new category, based on the description?
|
// this one to create a new category, based on the description?
|
||||||
def existingEntry = entries.find
|
def existingEntry = entries.find
|
||||||
@ -66,9 +70,28 @@ public abstract class Category implements Comparable<Category> {
|
|||||||
|
|
||||||
if (matchingCategories)
|
if (matchingCategories)
|
||||||
return matchingCategories[0].addEvent(e)
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Entry
|
||||||
|
|
||||||
public Duration getDuration() {
|
public Duration getDuration() {
|
||||||
return categories.sum(new Duration(0)) { it.duration } +
|
return categories.sum(new Duration(0)) { it.duration } +
|
||||||
entries.sum(new Duration(0)) { it.duration }
|
entries.sum(new Duration(0)) { it.duration }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user