* Represents a television program.
*/
public class Program {
-
+
+ private static final String ELEM_PROGRAM = "program";
+
+ private static final String ELEM_NAME = "name";
+
+ private static final String ELEM_KEYWORDS = "keywords";
+
+ private static final String ELEM_DESCRIPTION = "description";
+
+ private static final String ELEM_CHANNEL = "channel";
+
+ private static final String ELEM_INTERVAL = "interval";
+
+ private static final String ELEM_END_TIME = "end";
+
+ private static final String ELEM_BEGIN_TIME = "begin";
+
/**
- * Lexicographical comparison of programs based on (time, title, channel).
- *
+ * Lexicographical comparison of programs based on (time, title, channel).
+ *
*/
- public static class TimeSorter implements Comparator<Program> {
-
- /* (non-Javadoc)
- * @see java.util.Comparator#compare(T, T)
+ public static class TimeSorter implements Comparator<Program> {
+
+ /**
+ * 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);
/**
*/
private static final String RECORD_ACTION = "record";
- 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,
- private String _description;
+ /**
+ * Already recorded program.
+ */
+ DUPLICATE,
- private RecordingResult(String aDescription) {
- _description = aDescription;
- }
+ /**
+ * Recording conflict with another program.
+ */
+ CONFLICT,
- public String getDescription() {
- return _description;
- }
+ /**
+ * Program occurred in the past.
+ */
+ OLDSHOW,
+
+ /**
+ * Program could not be recorded for technical reasons.
+ */
+ ERROR;
};
/**
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;
}
}
*/
public RecordingResult record() {
LOG.info("Recording " + this);
- if ( SystemProperties.isRecordDisabled() ) {
+ if (SystemProperties.isRecordDisabled()) {
return RecordingResult.OK;
}
try {
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) {
+ ")" + "\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");
- 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("end").setText(getInterval().getEnd().toString());
- return program;
+ Element program = factory.createElement(ELEM_PROGRAM);
+ program.addElement(ELEM_NAME).setText(getName());
+ program.addElement(ELEM_DESCRIPTION).setText(getDescription());
+ program.addElement(ELEM_KEYWORDS).setText(getKeywords());
+ program.addElement(ELEM_CHANNEL).setText(getChannel());
+ Element interval = program.addElement(ELEM_INTERVAL);
+ interval.addElement(ELEM_BEGIN_TIME).setText(
+ getInterval().getBegin().toString());
+ interval.addElement(ELEM_END_TIME).setText(
+ getInterval().getEnd().toString());
+ return program;
}
}