2 * jFCPlib - Verbosity.java - Copyright © 2008–2016 David Roden
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.
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.
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/>.
18 package net.pterodactylus.fcp;
21 * Convenicence class for verbosity handling. This might come in handy with the
22 * {@link ClientPut} and {@link ClientGet} requests. The verbosity is a
23 * bit-mask that can be composed of several bits. {@link #PROGRESS} and
24 * {@link #COMPRESSION} are single bits in that mask and can be combined into a
25 * new verbosity using {@link #add(Verbosity)}.
27 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
29 public class Verbosity {
31 /** Constant for no verbosity at all. */
32 public static final Verbosity NONE = new Verbosity(0);
34 /** Constant for progress message verbosity. */
35 public static final Verbosity PROGRESS = new Verbosity(1);
37 /** Constant for compression message verbosity. */
38 public static final Verbosity COMPRESSION = new Verbosity(512);
40 /** Constant for all events. */
41 public static final Verbosity ALL = new Verbosity(-1);
43 /** The verbosity level. */
44 private final int level;
47 * Creates a new verbosity with the given level.
52 private Verbosity(int level) {
57 * Adds the given verbosity to this verbosity and returns a verbosity with
58 * the new value. The value of this verbosity is not changed.
61 * The verbosity to add to this verbosity
62 * @return The verbosity with the new level.
64 public Verbosity add(Verbosity verbosity) {
65 return new Verbosity(level | verbosity.level);
69 * Checks whether this Verbosity contains all bits of the given Verbosity.
72 * The verbosity to check for in this Verbosity
73 * @return <code>true</code> if and only if all set bits in the given
74 * Verbosity are also set in this Verbosity
76 public boolean contains(Verbosity verbosity) {
77 return (level & verbosity.level) == verbosity.level;
81 * @see java.lang.Object#toString()
84 public String toString() {
85 return String.valueOf(level);
89 * Parses the given string and creates a Verbosity with the given level.
93 * @return The parsed verbosity, or {@link #NONE} if the string could not
96 public static Verbosity valueOf(String s) {
98 return new Verbosity(Integer.valueOf(s));
99 } catch (NumberFormatException nfe1) {