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