X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=crawler%2Fkiss%2Fsrc%2Forg%2Fwamblee%2Fcrawler%2Fkiss%2Fmain%2FProgramActionExecutor.java;h=b9c103b7a7a46bcbef9e723e4a69f48b94515cf6;hb=0119c69858055c84592338a202e9d1b18510a29b;hp=27297a6f0d2c625c9383bf069f81821a60817819;hpb=01c0abdc7d3339b36216665ff70c99ba3e50c180;p=utils diff --git a/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramActionExecutor.java b/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramActionExecutor.java index 27297a6f..b9c103b7 100644 --- a/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramActionExecutor.java +++ b/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramActionExecutor.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.wamblee.crawler.kiss.main; @@ -28,111 +28,118 @@ import org.wamblee.crawler.kiss.guide.Program; import org.wamblee.crawler.kiss.guide.Program.RecordingResult; /** - * Provides execution of actions for programs. Actions use - * this class to tell the executor what to do. The executor then decide - * on exactly what to do and in what order and makes decisions in case - * of conflicts. + * Provides execution of actions for programs. Actions use this class to tell + * the executor what to do. The executor then decides on exactly what to do and + * in what order and makes decisions in case of conflicts. */ public class ProgramActionExecutor { - + /** - * A map of category name to a set of program. Useful for displaying the output of - * possibly interesting programs on a per category basis. + * A map of category name to a set of program. Useful for displaying the + * output of possibly interesting programs on a per category basis. */ private Map> _interestingShows; - + /** - * Set of programs to record. + * Set of programs to record. */ private Set _showsToRecord; - + /** - * Map or recording result to a set of programs. + * Map or recording result to a set of programs. */ private EnumMap> _recordings; - + /** - * Constructs the program action executor. - * + * Constructs the program action executor. + * */ - public ProgramActionExecutor() { - _interestingShows = new TreeMap>(); + public ProgramActionExecutor() { + _interestingShows = new TreeMap>(); _showsToRecord = new TreeSet(new Program.TimeSorter()); _recordings = new EnumMap>( RecordingResult.class); for (RecordingResult result : RecordingResult.values()) { - _recordings.put(result, new TreeSet(new Program.TimeSorter())); + _recordings.put(result, new TreeSet( + new Program.TimeSorter())); } } - + /** * Called by an action to indicate the desire to record a program. - * @param aPriority Priority of the program. Used to resolve conflicts. - * @param aProgram Program to record. + * + * @param aPriority + * Priority of the program. Used to resolve conflicts. + * @param aProgram + * Program to record. */ - public void recordProgram(int aPriority, Program aProgram) { + public void recordProgram(int aPriority, Program aProgram) { _showsToRecord.add(aProgram); } - + /** - * Called by an action to indicate that a program is interesting. - * @param aCategory Category of the program. - * @param aProgram Program. + * Called by an action to indicate that a program is interesting. + * + * @param aCategory + * Category of the program. + * @param aProgram + * Program. */ - public void interestingProgram(String aCategory, Program aProgram) { - Set programs = _interestingShows.get(aCategory); - if ( programs == null ) { + public void interestingProgram(String aCategory, Program aProgram) { + Set programs = _interestingShows.get(aCategory); + if (programs == null) { programs = new TreeSet(new Program.TimeSorter()); _interestingShows.put(aCategory, programs); } programs.add(aProgram); } - + /** * Makes sure that the actions are performed. - * + * */ - public void commit() { - for (Program program: _showsToRecord) { - RecordingResult result = program.record(); + public void commit() { + for (Program program : _showsToRecord) { + RecordingResult result = program.record(); _recordings.get(result).add(program); } } - + /** - * Get report as XML. - * @return XML report + * Get report as XML. + * + * @return XML report */ - public Element getReport() { - DocumentFactory factory = DocumentFactory.getInstance(); - Element report = factory.createElement("report"); - + public Element getReport() { + DocumentFactory factory = DocumentFactory.getInstance(); + Element report = factory.createElement("report"); + for (RecordingResult result : RecordingResult.values()) { if (_recordings.get(result).size() > 0) { - Element recordingResult = report.addElement("recorded").addAttribute("result", result.toString()); - + Element recordingResult = report.addElement("recorded") + .addAttribute("result", result.toString()); + for (Program program : _recordings.get(result)) { - recordingResult.add(program.asXml()); + recordingResult.add(program.asXml()); } } } - - - if ( _interestingShows.size() > 0 ) { + + if (_interestingShows.size() > 0) { Element interesting = report.addElement("interesting"); - for (String category: _interestingShows.keySet()) { - Element categoryElem = interesting; - if ( category.length() > 0 ) { + for (String category : _interestingShows.keySet()) { + Element categoryElem = interesting; + if (category.length() > 0) { categoryElem = interesting.addElement("category"); categoryElem.addAttribute("name", category); } - for (Program program: _interestingShows.get(category)) { - categoryElem.add(program.asXml()); + for (Program program : _interestingShows.get(category)) { + categoryElem.add(program.asXml()); } } - + } - - return report; + + return report; } }