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