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.
		
			
				
	
	
		
			22 lines
		
	
	
		
			701 B
		
	
	
	
		
			Groovy
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			701 B
		
	
	
	
		
			Groovy
		
	
	
	
	
	
package com.jdbernard.timeanalyzer
 | 
						|
 | 
						|
public class TwoLevelCategorizationPlan implements CategorizationPlan {
 | 
						|
 | 
						|
    private static final def TWO_LEVEL_PATTERN = ~/(.+?):(.*)/
 | 
						|
 | 
						|
    public boolean deservesNewCategory(Event event, List<Entry> el) {
 | 
						|
        return event ==~ TWO_LEVEL_PATTERN
 | 
						|
    }
 | 
						|
 | 
						|
    public Category newCategory(Event event, List<Entry> el) {
 | 
						|
        def m = event.description =~ TWO_LEVEL_PATTERN
 | 
						|
        return new TwoLevelCategory(m[0][1])
 | 
						|
    }
 | 
						|
 | 
						|
    public List<Entry> findEntriesToRecategorize(Event event,
 | 
						|
    List<Entry> existingEntries) {
 | 
						|
        def m = event.description =~ TWO_LEVEL_PATTERN
 | 
						|
        return existingEntries.findAll { it.description ==~ /${m[0][1]}:.*/ }
 | 
						|
    }
 | 
						|
}
 |