View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.maven.issue.util;
17  
18  import java.io.Serializable;
19  
20  /**
21   * The log level.
22   */
23  public final class LogLevel implements Serializable
24  {
25    // ********************************* Fields *********************************
26  
27    // --- constants ------------------------------------------------------------
28  
29    /**
30     * The class version identifier.
31     * <p>
32     * The value of this constant is {@value}.
33     * </p>
34     */
35    private static final long serialVersionUID = 1L;
36  
37    /**
38     * The quiet level: prints no info messages.
39     * <p>
40     * The value of this constant is {@value}.
41     * </p>
42     */
43    public static final String QUIET = "QUIET";
44  
45    /**
46     * The normal level: writes only command result descriptions.
47     * <p>
48     * The value of this constant is {@value}.
49     * </p>
50     */
51    public static final String NORMAL = "NORMAL";
52  
53    /**
54     * The verbose level: adds information about the called service and
55    * parameters
56     * <p>
57     * The value of this constant is {@value}.
58     * </p>
59     */
60    public static final String VERBOSE = "VERBOSE";
61  
62    /**
63     * The verbose level: provides the most verbose output with dumping the
64    * contents of the returned pages.
65     * <p>
66     * The value of this constant is {@value}.
67     * </p>
68     */
69    public static final String TRACE = "TRACE";
70  
71    // --- members --------------------------------------------------------------
72  
73    /**
74     * The name of the current level.
75     *
76     * @serial
77     */
78    private final String level;
79  
80    // ****************************** Initializer *******************************
81  
82    // ****************************** Constructors ******************************
83  
84    /**
85     * Default constructor.
86     *
87     * @param level the name of the current level.
88     */
89    public LogLevel(final String level)
90    {
91      this.level = level;
92    }
93  
94    // ****************************** Inner Classes *****************************
95  
96    // ********************************* Methods ********************************
97  
98    // --- init -----------------------------------------------------------------
99  
100   // --- get&set --------------------------------------------------------------
101 
102   /**
103    * Returns the name of the current level.
104    *
105    * @return the name of the current level.
106    */
107   public String getLevel()
108   {
109     return level;
110   }
111 
112   // --- business -------------------------------------------------------------
113 
114   /**
115    * Checks if the current level is quiet.
116    *
117    * @return <code>true</code> if the current level is quiet.
118    */
119   public boolean isQuiet()
120   {
121     return QUIET.equals(level) || isVerbose();
122   }
123 
124   /**
125    * Checks if the current level is normal or greater.
126    *
127    * @return <code>true</code> if the current level is normal or greater.
128    */
129   public boolean isNormal()
130   {
131     return NORMAL.equals(level) || isVerbose();
132   }
133 
134   /**
135    * Checks if the current level is verbose or greater.
136    *
137    * @return <code>true</code> if the current level is verbose or greater.
138    */
139   public boolean isVerbose()
140   {
141     return VERBOSE.equals(level) || isTrace();
142   }
143 
144   /**
145    * Checks if the current level is trace.
146    *
147    * @return <code>true</code> if the current level is trace.
148    */
149   public boolean isTrace()
150   {
151     return TRACE.equals(level);
152   }
153 
154   // --- object basics --------------------------------------------------------
155 
156   /**
157    * {@inheritDoc}
158    *
159    * @see java.lang.Object#toString()
160    */
161   @Override
162   public String toString()
163   {
164     return level;
165   }
166 }