*/
boolean success();
+ boolean isEmpty();
+
/**
* Returns the number of consecutive failures. This method only returns a
* meaningful number iff {@link #success()} returns {@code false}. If
private Output createErrorOutput(Reaction reaction, State state) {
DefaultOutput output = new DefaultOutput(String.format("Error while processing “%s!”", reaction.name()));
- output.addText("text/plain; charset=utf-8", createEmailText(reaction, state));
+ output.addText("text/plain; charset=utf-8", createErrorEmailText(reaction, state));
return output;
}
- private String createEmailText(Reaction reaction, State state) {
+ private String createErrorEmailText(Reaction reaction, State state) {
StringBuilder emailText = new StringBuilder();
emailText.append(String.format("An error occured while processing “.”\n\n", reaction.name()));
appendExceptionToEmailText(state.exception(), emailText);
logger.debug(format("Filtering state through %s...", filter.getClass().getSimpleName()));
try {
currentState = filter.filter(currentState);
+ if (currentState.success() && currentState.isEmpty()) {
+ errorEmailAction.execute(createEmptyStateOutput(reaction, state));
+ }
} catch (Throwable t1) {
logger.warn(format("Error during filter %s for %s.", filter.getClass().getSimpleName(), reaction.name()), t1);
return new FailedState(t1);
return currentState;
}
+ private Output createEmptyStateOutput(Reaction reaction, State state) {
+ DefaultOutput defaultOutput = new DefaultOutput(String.format("Reached Empty State for “%s!”", reaction.name()));
+ defaultOutput.addText("text/plain; charset=utf-8", String.format("The %s for %s was empty.", state.getClass().getSimpleName(), reaction.name()));
+ return defaultOutput;
+ }
+
}
/** Whether the state was successfully retrieved. */
private final boolean success;
+ private final boolean empty;
/** The optional exception that occured while retrieving the state. */
private final Throwable exception;
* otherwise
*/
protected AbstractState(boolean success) {
- this(success, null);
+ this(success, true, null);
+ }
+
+ protected AbstractState(boolean success, boolean empty) {
+ this(success, empty, null);
}
/**
* The exception that occured while retrieving the state
*/
protected AbstractState(Throwable exception) {
- this(false, exception);
+ this(false, true, exception);
}
/**
* @param exception
* The exception that occured while retrieving the state
*/
- protected AbstractState(boolean success, Throwable exception) {
+ protected AbstractState(boolean success, boolean empty, Throwable exception) {
this.time = System.currentTimeMillis();
this.success = success;
+ this.empty = empty;
this.exception = exception;
}
return success;
}
+ @Override
+ public boolean isEmpty() {
+ return empty;
+ }
+
/**
* {@inheritDoc}
*/
@JsonProperty
private final List<Comic> comics = Lists.newArrayList();
+ @Override
+ public boolean isEmpty() {
+ return comics.isEmpty();
+ }
+
public List<Comic> comics() {
return comics;
}
// ACCESSORS
//
+ @Override
+ public boolean isEmpty() {
+ return episodes.isEmpty();
+ }
+
/**
* Returns all episodes contained in this state.
*
super(exception);
}
+ @Override
+ public boolean isEmpty() {
+ return true;
+ }
+
//
// STATIC METHODS
//
// ACCESSORS
//
+ @Override
+ public boolean isEmpty() {
+ return !exists;
+ }
+
/**
* Returns whether the file exists.
*
// ACCESSORS
//
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
/**
* Returns the URI of the parsed document.
*
return copyOf(rawResult, rawResult.length);
}
+ @Override
+ public boolean isEmpty() {
+ return rawResult.length == 0;
+ }
+
/**
* Returns the decoded content of the reply. This method uses the charset
* information from the {@link #contentType()}, if present, or UTF-8 if no
this.htmlOutput = htmlOutput;
}
+ @Override
+ public boolean isEmpty() {
+ return !plainTextOutput.isPresent() && !htmlOutput.isPresent();
+ }
+
public Optional<String> plainTextOutput() {
return plainTextOutput;
}
return value;
}
+ @Override
+ public boolean isEmpty() {
+ return value.isEmpty();
+ }
+
}
// ACCESSORS
//
+ @Override
+ public boolean isEmpty() {
+ return files.isEmpty();
+ }
+
/**
* Returns all torrent files of this state.
*