Update license to GPLv3, fix header comments
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / SimpleProgress.java
1 /*
2  * jFCPlib - SimpleProgress.java - Copyright © 2008–2016 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.fcp;
19
20 /**
21  * A “SimpleProgress” message tells the client about the progress of a
22  * {@link ClientGet} or {@link ClientPut} operation.
23  *
24  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
25  */
26 public class SimpleProgress extends BaseMessage implements Identifiable {
27
28         /**
29          * Creates a new “SimpleProgress” message that wraps the received message.
30          *
31          * @param receivedMessage
32          *            The received message
33          */
34         public SimpleProgress(FcpMessage receivedMessage) {
35                 super(receivedMessage);
36         }
37
38         /**
39          * Returns the total number of blocks. This number may increase as long as
40          * {@link #isFinalizedTotal()} returns <code>false</code>.
41          *
42          * @return The total number of blocks
43          */
44         public int getTotal() {
45                 return FcpUtils.safeParseInt(getField("Total"));
46         }
47
48         /**
49          * Returns the number of blocks that are required to completet the request.
50          * This number might actually be lower than {@link #getTotal} because of
51          * redundancy information. This number may also increase as long as
52          * {@link #isFinalizedTotal()} returns <code>false</code>.
53          *
54          * @return The number of required blocks
55          */
56         public int getRequired() {
57                 return FcpUtils.safeParseInt(getField("Required"));
58         }
59
60         /**
61          * Returns the number of blocks that have failed and run out of retries.
62          *
63          * @return The number of failed blocks
64          */
65         public int getFailed() {
66                 return FcpUtils.safeParseInt(getField("Failed"));
67         }
68
69         /**
70          * Returns the number of fatally failed blocks. A block that failed fatally
71          * can never be completed, even with infinite retries.
72          *
73          * @return The number of fatally failed blocks
74          */
75         public int getFatallyFailed() {
76                 return FcpUtils.safeParseInt(getField("FatallyFailed"));
77         }
78
79         /**
80          * Returns the number of blocks that have been successfully processed.
81          *
82          * @return The number of succeeded blocks
83          */
84         public int getSucceeded() {
85                 return FcpUtils.safeParseInt(getField("Succeeded"));
86         }
87
88         /**
89          * Returns whether the total number of blocks (see {@link #getTotal()} has
90          * been finalized. Once the total number of blocks has been finalized for a
91          * request it will not change any more, and this method of every further
92          * SimpleProgress message will always return <code>true</code>.
93          *
94          * @return <code>true</code> if the number of total blocks has been
95          *         finalized, <code>false</code> otherwise
96          */
97         public boolean isFinalizedTotal() {
98                 return Boolean.valueOf(getField("FinalizedTotal"));
99         }
100
101         public long getLastProgress() {
102                 return Long.valueOf(getField("LastProgress"));
103         }
104
105         public int getMinSuccessFetchBlocks() {
106                 return Integer.valueOf(getField("MinSuccessFetchBlocks"));
107         }
108
109         /**
110          * Returns the identifier of the request.
111          *
112          * @return The identifier of the request
113          */
114         @Override
115         public String getIdentifier() {
116                 return getField("Identifier");
117         }
118
119 }