2 * © 2008 INA Service GmbH
4 package net.pterodactylus.util.fcp;
7 * Convenicence class for verbosity handling. This might come in handy with the
8 * {@link ClientPut} and {@link ClientGet} requests.
10 * The verbosity is a bit-mask that can be composed of several bits.
11 * {@link #PROGRESS} and {@link #COMPRESSION} are single bits in that mask and
12 * can be combined into a new verbosity using {@link #add(Verbosity)}.
14 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
17 public class Verbosity {
19 /** Constant for no verbosity at all. */
20 public static final Verbosity NONE = new Verbosity(0);
22 /** Constant for progress message verbosity. */
23 public static final Verbosity PROGRESS = new Verbosity(1);
25 /** Constant for compression message verbosity. */
26 public static final Verbosity COMPRESSION = new Verbosity(512);
28 /** Constant for all events. */
29 public static final Verbosity ALL = new Verbosity(-1);
31 /** The verbosity level. */
32 private final int level;
35 * Creates a new verbosity with the given level.
40 private Verbosity(int level) {
45 * Adds the given verbosity to this verbosity and returns a verbosity with
46 * the new value. The value of this verbosity is not changed.
49 * The verbosity to add to this verbosity
50 * @return The verbosity with the new level.
52 public Verbosity add(Verbosity verbosity) {
53 return new Verbosity(level | verbosity.level);
57 * Checks whether this Verbosity contains all bits of the given Verbosity.
60 * The verbosity to check for in this Verbosity
61 * @return <code>true</code> if and only if all set bits in the given
62 * Verbosity are also set in this Verbosity
64 public boolean contains(Verbosity verbosity) {
65 return (level & verbosity.level) == verbosity.level;
69 * @see java.lang.Object#toString()
72 public String toString() {
73 return String.valueOf(level);
77 * Parses the given string and creates a Verbosity with the given level.
81 * @return The parsed verbosity, or {@link #NONE} if the string could not be
84 public static Verbosity valueOf(String s) {
86 return new Verbosity(Integer.valueOf(s));
87 } catch (NumberFormatException nfe1) {