Implement hashCode() and equals().
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Preferences.java
1 /*
2  * Sone - Preferences.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.sone.core;
19
20 import net.pterodactylus.sone.fcp.FcpInterface;
21 import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
22
23 /**
24  * Convenience interface for external classes that want to access the core’s
25  * configuration.
26  *
27  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28  */
29 public class Preferences {
30
31         /** The wrapped options. */
32         private final Options options;
33
34         /**
35          * Creates a new preferences object wrapped around the given options.
36          *
37          * @param options
38          *            The options to wrap
39          */
40         public Preferences(Options options) {
41                 this.options = options;
42         }
43
44         /**
45          * Returns the insertion delay.
46          *
47          * @return The insertion delay
48          */
49         public int getInsertionDelay() {
50                 return options.getIntegerOption("InsertionDelay").get();
51         }
52
53         /**
54          * Validates the given insertion delay.
55          *
56          * @param insertionDelay
57          *            The insertion delay to validate
58          * @return {@code true} if the given insertion delay was valid,
59          *         {@code false} otherwise
60          */
61         public boolean validateInsertionDelay(Integer insertionDelay) {
62                 return options.getIntegerOption("InsertionDelay").validate(insertionDelay);
63         }
64
65         /**
66          * Sets the insertion delay
67          *
68          * @param insertionDelay
69          *            The new insertion delay, or {@code null} to restore it to
70          *            the default value
71          * @return This preferences
72          */
73         public Preferences setInsertionDelay(Integer insertionDelay) {
74                 options.getIntegerOption("InsertionDelay").set(insertionDelay);
75                 return this;
76         }
77
78         /**
79          * Returns the number of posts to show per page.
80          *
81          * @return The number of posts to show per page
82          */
83         public int getPostsPerPage() {
84                 return options.getIntegerOption("PostsPerPage").get();
85         }
86
87         /**
88          * Validates the number of posts per page.
89          *
90          * @param postsPerPage
91          *            The number of posts per page
92          * @return {@code true} if the number of posts per page was valid,
93          *         {@code false} otherwise
94          */
95         public boolean validatePostsPerPage(Integer postsPerPage) {
96                 return options.getIntegerOption("PostsPerPage").validate(postsPerPage);
97         }
98
99         /**
100          * Sets the number of posts to show per page.
101          *
102          * @param postsPerPage
103          *            The number of posts to show per page
104          * @return This preferences object
105          */
106         public Preferences setPostsPerPage(Integer postsPerPage) {
107                 options.getIntegerOption("PostsPerPage").set(postsPerPage);
108                 return this;
109         }
110
111         /**
112          * Returns the number of images to show per page.
113          *
114          * @return The number of images to show per page
115          */
116         public int getImagesPerPage() {
117                 return options.getIntegerOption("ImagesPerPage").get();
118         }
119
120         /**
121          * Validates the number of images per page.
122          *
123          * @param imagesPerPage
124          *            The number of images per page
125          * @return {@code true} if the number of images per page was valid,
126          *         {@code false} otherwise
127          */
128         public boolean validateImagesPerPage(Integer imagesPerPage) {
129                 return options.getIntegerOption("ImagesPerPage").validate(imagesPerPage);
130         }
131
132         /**
133          * Sets the number of images per page.
134          *
135          * @param imagesPerPage
136          *            The number of images per page
137          * @return This preferences object
138          */
139         public Preferences setImagesPerPage(Integer imagesPerPage) {
140                 options.getIntegerOption("ImagesPerPage").set(imagesPerPage);
141                 return this;
142         }
143
144         /**
145          * Returns the number of characters per post, or <code>-1</code> if the
146          * posts should not be cut off.
147          *
148          * @return The numbers of characters per post
149          */
150         public int getCharactersPerPost() {
151                 return options.getIntegerOption("CharactersPerPost").get();
152         }
153
154         /**
155          * Validates the number of characters per post.
156          *
157          * @param charactersPerPost
158          *            The number of characters per post
159          * @return {@code true} if the number of characters per post was valid,
160          *         {@code false} otherwise
161          */
162         public boolean validateCharactersPerPost(Integer charactersPerPost) {
163                 return options.getIntegerOption("CharactersPerPost").validate(charactersPerPost);
164         }
165
166         /**
167          * Sets the number of characters per post.
168          *
169          * @param charactersPerPost
170          *            The number of characters per post, or <code>-1</code> to
171          *            not cut off the posts
172          * @return This preferences objects
173          */
174         public Preferences setCharactersPerPost(Integer charactersPerPost) {
175                 options.getIntegerOption("CharactersPerPost").set(charactersPerPost);
176                 return this;
177         }
178
179         /**
180          * Returns the number of characters the shortened post should have.
181          *
182          * @return The number of characters of the snippet
183          */
184         public int getPostCutOffLength() {
185                 return options.getIntegerOption("PostCutOffLength").get();
186         }
187
188         /**
189          * Validates the number of characters after which to cut off the post.
190          *
191          * @param postCutOffLength
192          *            The number of characters of the snippet
193          * @return {@code true} if the number of characters of the snippet is
194          *         valid, {@code false} otherwise
195          */
196         public boolean validatePostCutOffLength(Integer postCutOffLength) {
197                 return options.getIntegerOption("PostCutOffLength").validate(postCutOffLength);
198         }
199
200         /**
201          * Sets the number of characters the shortened post should have.
202          *
203          * @param postCutOffLength
204          *            The number of characters of the snippet
205          * @return This preferences
206          */
207         public Preferences setPostCutOffLength(Integer postCutOffLength) {
208                 options.getIntegerOption("PostCutOffLength").set(postCutOffLength);
209                 return this;
210         }
211
212         /**
213          * Returns whether Sone requires full access to be even visible.
214          *
215          * @return {@code true} if Sone requires full access, {@code false}
216          *         otherwise
217          */
218         public boolean isRequireFullAccess() {
219                 return options.getBooleanOption("RequireFullAccess").get();
220         }
221
222         /**
223          * Sets whether Sone requires full access to be even visible.
224          *
225          * @param requireFullAccess
226          *            {@code true} if Sone requires full access, {@code false}
227          *            otherwise
228          */
229         public void setRequireFullAccess(Boolean requireFullAccess) {
230                 options.getBooleanOption("RequireFullAccess").set(requireFullAccess);
231         }
232
233         /**
234          * Returns the positive trust.
235          *
236          * @return The positive trust
237          */
238         public int getPositiveTrust() {
239                 return options.getIntegerOption("PositiveTrust").get();
240         }
241
242         /**
243          * Validates the positive trust.
244          *
245          * @param positiveTrust
246          *            The positive trust to validate
247          * @return {@code true} if the positive trust was valid, {@code false}
248          *         otherwise
249          */
250         public boolean validatePositiveTrust(Integer positiveTrust) {
251                 return options.getIntegerOption("PositiveTrust").validate(positiveTrust);
252         }
253
254         /**
255          * Sets the positive trust.
256          *
257          * @param positiveTrust
258          *            The new positive trust, or {@code null} to restore it to
259          *            the default vlaue
260          * @return This preferences
261          */
262         public Preferences setPositiveTrust(Integer positiveTrust) {
263                 options.getIntegerOption("PositiveTrust").set(positiveTrust);
264                 return this;
265         }
266
267         /**
268          * Returns the negative trust.
269          *
270          * @return The negative trust
271          */
272         public int getNegativeTrust() {
273                 return options.getIntegerOption("NegativeTrust").get();
274         }
275
276         /**
277          * Validates the negative trust.
278          *
279          * @param negativeTrust
280          *            The negative trust to validate
281          * @return {@code true} if the negative trust was valid, {@code false}
282          *         otherwise
283          */
284         public boolean validateNegativeTrust(Integer negativeTrust) {
285                 return options.getIntegerOption("NegativeTrust").validate(negativeTrust);
286         }
287
288         /**
289          * Sets the negative trust.
290          *
291          * @param negativeTrust
292          *            The negative trust, or {@code null} to restore it to the
293          *            default value
294          * @return The preferences
295          */
296         public Preferences setNegativeTrust(Integer negativeTrust) {
297                 options.getIntegerOption("NegativeTrust").set(negativeTrust);
298                 return this;
299         }
300
301         /**
302          * Returns the trust comment. This is the comment that is set in the web
303          * of trust when a trust value is assigned to an identity.
304          *
305          * @return The trust comment
306          */
307         public String getTrustComment() {
308                 return options.getStringOption("TrustComment").get();
309         }
310
311         /**
312          * Sets the trust comment.
313          *
314          * @param trustComment
315          *            The trust comment, or {@code null} to restore it to the
316          *            default value
317          * @return This preferences
318          */
319         public Preferences setTrustComment(String trustComment) {
320                 options.getStringOption("TrustComment").set(trustComment);
321                 return this;
322         }
323
324         /**
325          * Returns whether the {@link FcpInterface FCP interface} is currently
326          * active.
327          *
328          * @see FcpInterface#setActive(boolean)
329          * @return {@code true} if the FCP interface is currently active,
330          *         {@code false} otherwise
331          */
332         public boolean isFcpInterfaceActive() {
333                 return options.getBooleanOption("ActivateFcpInterface").get();
334         }
335
336         /**
337          * Sets whether the {@link FcpInterface FCP interface} is currently
338          * active.
339          *
340          * @see FcpInterface#setActive(boolean)
341          * @param fcpInterfaceActive
342          *            {@code true} to activate the FCP interface, {@code false}
343          *            to deactivate the FCP interface
344          * @return This preferences object
345          */
346         public Preferences setFcpInterfaceActive(boolean fcpInterfaceActive) {
347                 options.getBooleanOption("ActivateFcpInterface").set(fcpInterfaceActive);
348                 return this;
349         }
350
351         /**
352          * Returns the action level for which full access to the FCP interface
353          * is required.
354          *
355          * @return The action level for which full access to the FCP interface
356          *         is required
357          */
358         public FullAccessRequired getFcpFullAccessRequired() {
359                 return FullAccessRequired.values()[options.getIntegerOption("FcpFullAccessRequired").get()];
360         }
361
362         /**
363          * Sets the action level for which full access to the FCP interface is
364          * required
365          *
366          * @param fcpFullAccessRequired
367          *            The action level
368          * @return This preferences
369          */
370         public Preferences setFcpFullAccessRequired(FullAccessRequired fcpFullAccessRequired) {
371                 options.getIntegerOption("FcpFullAccessRequired").set((fcpFullAccessRequired != null) ? fcpFullAccessRequired.ordinal() : null);
372                 return this;
373         }
374
375 }