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 <a href="mailto:dr@ina-germany.de">David Roden</a>
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 /** The verbosity level. */
29 private final int level;
32 * Creates a new verbosity with the given level.
37 private Verbosity(int level) {
42 * Adds the given verbosity to this verbosity and returns a verbosity with
43 * the new value. The value of this verbosity is not changed.
46 * The verbosity to add to this verbosity
47 * @return The verbosity with the new level.
49 public Verbosity add(Verbosity verbosity) {
50 return new Verbosity(level | verbosity.level);
54 * Checks whether this Verbosity contains all bits of the given Verbosity.
57 * The verbosity to check for in this Verbosity
58 * @return <code>true</code> if and only if all set bits in the given
59 * Verbosity are also set in this Verbosity
61 public boolean contains(Verbosity verbosity) {
62 return (level & verbosity.level) == verbosity.level;
66 * @see java.lang.Object#toString()
69 public String toString() {
70 return String.valueOf(level);
74 * Parses the given string and creates a Verbosity with the given level.
78 * @return The parsed verbosity, or {@link #NONE} if the string could not be
81 public static Verbosity valueOf(String s) {
83 return new Verbosity(Integer.valueOf(s));
84 } catch (NumberFormatException nfe1) {