package journal.action; import java.util.HashMap; import java.util.List; import java.util.Map; import journal.reader.ActionType; import journal.reader.DataJournalEntry; import journal.reader.JournalEntry; import journal.schema.TableVersion; public abstract class BaseRenamerAction extends BaseAction { protected boolean patch; protected Map<String, String> renameMap = new HashMap<String, String>(); protected Map<TableVersion, RenameAction> actionMap = new HashMap<TableVersion, RenameAction>(); interface RenameAction { boolean rename(DataJournalEntry data); } static class CompoundActions implements RenameAction { public boolean rename(DataJournalEntry data) { boolean renamed = false; for( RenameAction action : list) { renamed = renamed | action.rename(data); } return renamed; } private List<RenameAction> list = null; CompoundActions(List<RenameAction> actions) { list = actions; } } class SimpleRenameAction implements RenameAction { private String field; public boolean rename(DataJournalEntry data) { String value = (String) data.getValue(field); if( renameMap.containsKey(value) ) { value = renameMap.get(value); data.setValue(field, value); return true; } return false; } SimpleRenameAction(String field) { this.field = field; } } class FileRenameAction implements RenameAction { private String field; public boolean rename(DataJournalEntry data) { String file = (String) data.getValue(field); if( file.length() > 0 && file.charAt(0) == '/') { String value = file.substring(2, file.indexOf('/', 2)); if( renameMap.containsKey(value) ) { String newValue = renameMap.get(value); String newValueFile = file.replaceFirst("//"+value+"/", "//" + newValue + "/"); data.setValue(field, newValueFile); return true; } } return false; } FileRenameAction(String field) { this.field = field; } } static class EmptyAction implements RenameAction { public boolean rename(DataJournalEntry data) { return false; } private EmptyAction() { } public static final EmptyAction instance = new EmptyAction(); } abstract RenameAction getAction(TableVersion version); @Override public void putValue(JournalEntry entry) throws Exception { DataJournalEntry data = (DataJournalEntry) entry; TableVersion version = data.getTableVersion(); RenameAction action = getAction(version); boolean renamed = action.rename(data); if( renamed && patch) { out.println(data.toJournalString(ActionType.DELETE_VALUE)); } if( renamed || !patch ) { out.println(data.toJournalString()); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#9 | 8296 | Sven Erik Knop |
Clean-up: instead of casting in every action, cast only once in the dispatcher. Should make code saner and safer. No functional change. |
||
#8 | 8180 | Sven Erik Knop |
BaseRenamerAction now stores oldValue in 2 separate tables, one in lowercase form, the other untouched. This is because at the time when the table is filled we do not know whether the checkpoint is going to be case-insensitive, so we have to store both variants. |
||
#7 | 8027 | Sven Erik Knop |
Moved exceptions to their own package. Enabled new Action FilepathRenamer (not fully tested yet). |
||
#6 | 8023 | Sven Erik Knop |
Complete rewrite of the configuration file, now based on an ini-file format. The ini file has a general [reader] section for settings like verbose, outputFile, case-sensitivity and so on. It also allows to set up a range of Actions and Filters. The section name here is the fully classified class name, followed by settings for the particular actions. An example will make this clearer: ================================================================ [reader] verbose=true [journal.action.UserRenamer] fileName=user.txt patch=True outputFile=user.out [journal.action.ClientRenamer] fileName=client.txt outputFile=client.out patch=true ================================================================ I will provide more example set-ups in the near future. Filters are classes implementing journal.action.Filter (soon to be journal.filter.Filter) which can be chained together and are all executed before the actions. Actions are applied in order that they are given in the config file. |
||
#5 | 8020 | Sven Erik Knop | Replace public Option attributes with setters and getters. | ||
#4 | 8017 | Sven Erik Knop | Fixed patching by adding copy constructor. | ||
#3 | 8016 | Sven Erik Knop | In the middle of refactoring the Renamer classes into the BaseRenamer. | ||
#2 | 8015 | Sven Erik Knop | Now with counter reestablished. | ||
#1 | 8014 | Sven Erik Knop |
Extracted a base class. Not quite finished since I need a counter class as well. |