X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=crawler%2Fkiss%2Fsrc%2Forg%2Fwamblee%2Fcrawler%2Fkiss%2Fguide%2FProgram.java;h=5f1bb67eb6325857ec70906e6bab890bd9616b80;hb=94445186085ec1ec27bed5a5c07b634da957eb08;hp=6b1656478dd9ded48d8259f64d971406f76fa1cd;hpb=dbb0ee9cc1d8004ee4d8ad77678e1f396880d784;p=utils diff --git a/crawler/kiss/src/org/wamblee/crawler/kiss/guide/Program.java b/crawler/kiss/src/org/wamblee/crawler/kiss/guide/Program.java index 6b165647..5f1bb67e 100644 --- a/crawler/kiss/src/org/wamblee/crawler/kiss/guide/Program.java +++ b/crawler/kiss/src/org/wamblee/crawler/kiss/guide/Program.java @@ -31,29 +31,37 @@ import org.wamblee.crawler.kiss.main.SystemProperties; * Represents a television program. */ public class Program { - + /** - * Lexicographical comparison of programs based on (time, title, channel). - * + * Lexicographical comparison of programs based on (time, title, channel). + * */ - public static class TimeSorter implements Comparator { - - /* (non-Javadoc) - * @see java.util.Comparator#compare(T, T) + public static class TimeSorter implements Comparator { + + /** + * Lexicographical comparison based on start time, program name, and + * channel. + * + * @param aProgram1 + * First program. + * @param aProgram2 + * Second program. + * @return See {@link Comparator#compare(T, T)} */ - public int compare(Program o1, Program o2) { - int value = o1.getInterval().getBegin().compareTo(o2.getInterval().getBegin()); - if ( value != 0 ) { - return value; + public int compare(Program aProgram1, Program aProgram2) { + int value = aProgram1.getInterval().getBegin().compareTo( + aProgram2.getInterval().getBegin()); + if (value != 0) { + return value; } - value = o1.getName().compareTo(o2.getName()); - if (value != 0 ) { - return value; + value = aProgram1.getName().compareTo(aProgram2.getName()); + if (value != 0) { + return value; } - return o1.getChannel().compareTo(o2.getChannel()); + return aProgram1.getChannel().compareTo(aProgram2.getChannel()); } } - + private static final Log LOG = LogFactory.getLog(Program.class); /** @@ -63,12 +71,35 @@ public class Program { private static final String RESULT_ELEM = "result"; + /** + * Result of recording a program. + * + */ public enum RecordingResult { - OK("Successfully recorded programs"), DUPLICATE( - "Already recorded programs"), CONFLICT( - "Programs in conflict with another recorded program"), OLDSHOW( - "Programs that occurred in the past"), ERROR( - "Programs that could not be recorded for technical reasons"); + /** + * Successfully recorded. + */ + OK("Successfully recorded programs"), + + /** + * Already recorded program. + */ + DUPLICATE("Already recorded programs"), + + /** + * Recording conflict with another program. + */ + CONFLICT("Programs in conflict with another recorded program"), + + /** + * Program occurred in the past. + */ + OLDSHOW("Programs that occurred in the past"), + + /** + * Program could not be recorded for technical reasons. + */ + ERROR("Programs that could not be recorded for technical reasons"); private String _description; @@ -76,6 +107,10 @@ public class Program { _description = aDescription; } + /** + * Gets the description. + * @return Description. + */ public String getDescription() { return _description; } @@ -188,20 +223,21 @@ public class Program { public TimeInterval getInterval() { return _interval; } - + /** - * Checks if recording is possible. - * @return True iff recording is possible. + * Checks if recording is possible. + * + * @return True iff recording is possible. */ - public boolean isRecordingPossible() { + public boolean isRecordingPossible() { try { Action record = _programInfo.execute().getAction(RECORD_ACTION); if (record == null) { - return false; + return false; } - return true; + return true; } catch (PageException e) { - return false; + return false; } } @@ -212,7 +248,7 @@ public class Program { */ public RecordingResult record() { LOG.info("Recording " + this); - if ( SystemProperties.isRecordDisabled() ) { + if (SystemProperties.isRecordDisabled()) { return RecordingResult.OK; } try { @@ -222,7 +258,8 @@ public class Program { return RecordingResult.OLDSHOW; } Page result = record.execute(); - RecordingResult recordingResult = RecordingResult.valueOf(result.getContent().getText()); + RecordingResult recordingResult = RecordingResult.valueOf(result + .getContent().getText()); LOG.info(" result: " + recordingResult); return recordingResult; } catch (PageException e) { @@ -253,34 +290,48 @@ public class Program { + ")" + "\n" + (INDENT + _description).replaceAll("\n", "\n" + INDENT); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(Object obj) { - if ( !(obj instanceof Program)) { - return false; + public boolean equals(Object aObject) { + if (!(aObject instanceof Program)) { + return false; } - Program program = (Program)obj; - return getName().equals(program.getName()) && - _programInfo.equals(program._programInfo); + Program program = (Program) aObject; + return getName().equals(program.getName()) + && _programInfo.equals(program._programInfo); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return getName().hashCode(); } - + /** - * Converts program information to XML. - * @return XML representation of program information. + * Converts program information to XML. + * + * @return XML representation of program information. */ - public Element asXml() { + public Element asXml() { DocumentFactory factory = DocumentFactory.getInstance(); - Element program = factory.createElement("program"); + Element program = factory.createElement("program"); program.addElement("name").setText(getName()); program.addElement("description").setText(getDescription()); program.addElement("keywords").setText(getKeywords()); program.addElement("channel").setText(getChannel()); Element interval = program.addElement("interval"); - interval.addElement("begin").setText(getInterval().getBegin().toString()); + interval.addElement("begin").setText( + getInterval().getBegin().toString()); interval.addElement("end").setText(getInterval().getEnd().toString()); - return program; + return program; } }