Update license to GPLv3, fix header comments
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / SubscribeUSK.java
1 /*
2  * jFCPlib - SubscribeUSK.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  * With a “SubscribeUSK” a client requests to be notified if the edition number
22  * of a USK changes.
23  *
24  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
25  */
26 public class SubscribeUSK extends FcpMessage implements Identifiable {
27
28         public SubscribeUSK(String identifier) {
29                 super("SubscribeUSK");
30                 setField("Identifier", identifier);
31         }
32
33         public SubscribeUSK(String uri, String identifier) {
34                 this(identifier);
35                 setField("URI", uri);
36         }
37
38         @Override
39         public String getIdentifier() {
40                 return getField("Identifier");
41         }
42
43         public String getUri() {
44                 return getField("URI");
45         }
46
47         public void setUri(String uri) {
48                 setField("URI", uri);
49         }
50
51         public boolean isActive() {
52                 return !Boolean.parseBoolean(getField("DontPoll"));
53         }
54
55         /**
56          * Sets whether updates for the USK are actively searched.
57          *
58          * @param active
59          *            <code>true</code> to actively search for newer editions,
60          *            <code>false</code> to only watch for newer editions that are
61          *            found from other requests
62          */
63         public void setActive(boolean active) {
64                 setField("DontPoll", String.valueOf(!active));
65         }
66
67         public boolean isSparse() {
68                 return Boolean.valueOf(getField("SparsePoll"));
69         }
70
71         public void setSparse(boolean sparse) {
72                 setField("SparsePoll", String.valueOf(sparse));
73         }
74
75         public Priority getPriority() {
76                 String priorityClass = getField("PriorityClass");
77                 if (priorityClass != null) {
78                         return Priority.valueOf(priorityClass);
79                 }
80                 return Priority.bulkSplitfile;
81         }
82
83         public void setPriority(Priority priority) {
84                 setField("PriorityClass", priority.toString());
85         }
86
87         public Priority getActivePriority() {
88                 String priorityClass = getField("PriorityClassProgress");
89                 if (priorityClass != null) {
90                         return Priority.valueOf(priorityClass);
91                 }
92                 return Priority.update;
93         }
94
95         public void setActivePriority(Priority activePriority) {
96                 setField("PriorityClassProgress", activePriority.toString());
97         }
98
99         public boolean isRealTime() {
100                 return Boolean.valueOf(getField("RealTimeFlag"));
101         }
102
103         public void setRealTime(boolean realTime) {
104                 setField("RealTimeFlag", String.valueOf(realTime));
105         }
106
107         public boolean isIgnoreDateHints() {
108                 return Boolean.valueOf(getField("IgnoreUSKDatehints"));
109         }
110
111         public void setIgnoreDateHints(boolean ignoreDateHints) {
112                 setField("IgnoreUSKDatehints", String.valueOf(ignoreDateHints));
113         }
114
115 }