Add possibility to restart/research failed downloads.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / ui / stdin / State.java
1 /*
2  * XdccDownloader - State.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.xdcc.ui.stdin;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import net.pterodactylus.irc.Connection;
24 import net.pterodactylus.xdcc.data.Download;
25
26 import com.google.common.collect.Lists;
27
28 /**
29  * Container for the current state of the command reader.
30  *
31  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32  */
33 public class State {
34
35         /** The last connections displayed. */
36         private final List<Connection> lastConnections;
37
38         /** The last results displayed. */
39         private final List<Result> lastResults;
40
41         /** The last downloads displayed. */
42         private final List<Download> lastDownloads;
43
44         private final List<Download> lastFailedDownloads;
45
46         /** Creates a new empty state. */
47         public State() {
48                 this(Lists.<Connection>newArrayList(), Lists.<Result>newArrayList(), Lists.<Download>newArrayList(), new ArrayList<>());
49         }
50
51         /**
52          * Creates a new state.
53          *
54          * @param lastConnections
55          *              The last connections
56          * @param lastResults
57          *              The last results
58          * @param lastDownloads
59          * @param lastFailedDownloads
60          *              The last failed downloads shown
61          */
62         State(List<Connection> lastConnections, List<Result> lastResults, List<Download> lastDownloads, List<Download> lastFailedDownloads) {
63                 this.lastConnections = lastConnections;
64                 this.lastResults = lastResults;
65                 this.lastDownloads = lastDownloads;
66                 this.lastFailedDownloads = lastFailedDownloads;
67         }
68
69         //
70         // ACCESSORS
71         //
72
73         /**
74          * Returns the last connections displayed.
75          *
76          * @return The last connections displayed
77          */
78         public List<Connection> getLastConnections() {
79                 return lastConnections;
80         }
81
82         /**
83          * Returns the last results displayed.
84          *
85          * @return The last results displayed
86          */
87         public List<Result> getLastResults() {
88                 return lastResults;
89         }
90
91         /**
92          * Returns the last downloads displayed.
93          *
94          * @return The last downloads displayed
95          */
96         public List<Download> getLastDownloads() {
97                 return lastDownloads;
98         }
99
100         public List<Download> getLastFailedDownloads() {
101                 return lastFailedDownloads;
102         }
103
104         //
105         // MUTATORS
106         //
107
108         /**
109          * Returns a new state with the given last connections and the last downloads
110          * and results of this state.
111          *
112          * @param lastConnections
113          *              The new last connections displayed
114          * @return The new state
115          */
116         public State setLastConnections(List<Connection> lastConnections) {
117                 return new State(lastConnections, lastResults, lastDownloads, lastFailedDownloads);
118         }
119
120         /**
121          * Returns a new state with the given last results and the last downloads and
122          * connections of this state.
123          *
124          * @param lastResults
125          *              The new last results displayed
126          * @return The new state
127          */
128         public State setLastResults(List<Result> lastResults) {
129                 return new State(lastConnections, lastResults, lastDownloads, lastFailedDownloads);
130         }
131
132         /**
133          * Returns a new state with the given last downloads and the last connections
134          * and results of this state.
135          *
136          * @param lastDownloads
137          *              The new last downloads displayed
138          * @return The new state
139          */
140         public State setLastDownloads(List<Download> lastDownloads) {
141                 return new State(lastConnections, lastResults, lastDownloads, lastFailedDownloads);
142         }
143
144         public State setLastFailedDownloads(List<Download> lastFailedDownloads) {
145                 return new State(lastConnections, lastResults, lastDownloads, lastFailedDownloads);
146         }
147
148 }