+ /**
+ * Container for the current state of the command reader.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+ private static class State {
+
+ /** The last connections displayed. */
+ private final List<Connection> lastConnections;
+
+ /** The last results displayed. */
+ private final List<Result> lastResults;
+
+ /** The last downloads displayed. */
+ private final List<Download> lastDownloads;
+
+ public State() {
+ this(Lists.<Connection>newArrayList(), Lists.<Result>newArrayList(), Lists.<Download>newArrayList());
+ }
+
+ /**
+ * Creates a new state.
+ *
+ * @param lastConnections
+ * The last connections
+ * @param lastResults
+ * The last results
+ * @param lastDownloads
+ * The last downloads
+ */
+ private State(List<Connection> lastConnections, List<Result> lastResults, List<Download> lastDownloads) {
+ this.lastConnections = lastConnections;
+ this.lastResults = lastResults;
+ this.lastDownloads = lastDownloads;
+ }
+
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Returns the last connections displayed.
+ *
+ * @return The last connections displayed
+ */
+ public List<Connection> getLastConnections() {
+ return lastConnections;
+ }
+
+ /**
+ * Returns the last results displayed.
+ *
+ * @return The last results displayed
+ */
+ public List<Result> getLastResults() {
+ return lastResults;
+ }
+
+ /**
+ * Returns the last downloads displayed.
+ *
+ * @return The last downloads displayed
+ */
+ public List<Download> getLastDownloads() {
+ return lastDownloads;
+ }
+
+ //
+ // MUTATORS
+ //
+
+ /**
+ * Returns a new state with the given last connections and the last downloads
+ * and results of this state.
+ *
+ * @param lastConnections
+ * The new last connections displayed
+ * @return The new state
+ */
+ public State setLastConnections(List<Connection> lastConnections) {
+ return new State(lastConnections, lastResults, lastDownloads);
+ }
+
+ /**
+ * Returns a new state with the given last results and the last downloads and
+ * connections of this state.
+ *
+ * @param lastResults
+ * The new last results displayed
+ * @return The new state
+ */
+ public State setLastResults(List<Result> lastResults) {
+ return new State(lastConnections, lastResults, lastDownloads);
+ }
+
+ /**
+ * Returns a new state with the given last downloads and the last connections
+ * and results of this state.
+ *
+ * @param lastDownloads
+ * The new last downloads displayed
+ * @return The new state
+ */
+ public State setLastDownloads(List<Download> lastDownloads) {
+ return new State(lastConnections, lastResults, lastDownloads);
+ }
+
+ }
+