View Javadoc

1   package org.apache.maven.shared.io.logging;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Arrays;
24  import java.util.Collections;
25  import java.util.List;
26  
27  
28  public final class MessageLevels
29  {
30  
31      public static final int LEVEL_DEBUG = 0;
32      public static final int LEVEL_INFO = 1;
33      public static final int LEVEL_WARNING = 2;
34      public static final int LEVEL_ERROR = 3;
35      public static final int LEVEL_SEVERE = 4;
36      public static final int LEVEL_DISABLED = 5;
37  
38      private static final List LEVEL_NAMES;
39  
40      static
41      {
42          List names = new ArrayList();
43          names.add( "DEBUG" );
44          names.add( "INFO" );
45          names.add( "WARN" );
46          names.add( "ERROR" );
47          names.add( "SEVERE" );
48  
49          LEVEL_NAMES = Collections.unmodifiableList( names );
50      }
51  
52      private MessageLevels()
53      {
54      }
55  
56      public static boolean[] getLevelStates( int maxMessageLevel )
57      {
58          boolean[] states = new boolean[5];
59  
60          Arrays.fill( states, false );
61  
62          switch ( maxMessageLevel )
63          {
64          case (LEVEL_DEBUG): {
65              states[LEVEL_DEBUG] = true;
66          }
67          case (LEVEL_INFO): {
68              states[LEVEL_INFO] = true;
69          }
70          case (LEVEL_WARNING): {
71              states[LEVEL_WARNING] = true;
72          }
73          case (LEVEL_ERROR): {
74              states[LEVEL_ERROR] = true;
75          }
76          case (LEVEL_SEVERE): {
77              states[LEVEL_SEVERE] = true;
78          }
79          }
80  
81          return states;
82      }
83  
84      public static String getLevelLabel( int messageLevel )
85      {
86          if ( messageLevel > -1 && LEVEL_NAMES.size() > messageLevel )
87          {
88              return (String) LEVEL_NAMES.get( messageLevel );
89          }
90  
91          throw new IllegalArgumentException( "Invalid message level: " + messageLevel );
92      }
93  }