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   * 
29   */
30  public final class MessageLevels
31  {
32  
33      /**
34       * Debug.
35       */
36      public static final int LEVEL_DEBUG = 0;
37      /**
38       * Info
39       */
40      public static final int LEVEL_INFO = 1;
41      /**
42       * Warning.
43       */
44      public static final int LEVEL_WARNING = 2;
45      /**
46       * Error
47       */
48      public static final int LEVEL_ERROR = 3;
49      /**
50       * Severe
51       */
52      public static final int LEVEL_SEVERE = 4;
53      /**
54       * Disabled.
55       */
56      public static final int LEVEL_DISABLED = 5;
57  
58      private static final List<String> LEVEL_NAMES;
59  
60      static
61      {
62          List<String> names = new ArrayList<String>();
63          names.add( "DEBUG" );
64          names.add( "INFO" );
65          names.add( "WARN" );
66          names.add( "ERROR" );
67          names.add( "SEVERE" );
68  
69          LEVEL_NAMES = Collections.unmodifiableList( names );
70      }
71  
72      private MessageLevels()
73      {
74      }
75  
76      /**
77       * @param maxMessageLevel for which level.
78       * @return level states.
79       */
80      public static boolean[] getLevelStates( int maxMessageLevel )
81      {
82          boolean[] states = new boolean[5];
83  
84          Arrays.fill( states, false );
85  
86          switch ( maxMessageLevel )
87          {
88              case ( LEVEL_DEBUG ):
89                  states[LEVEL_DEBUG] = true;
90              case ( LEVEL_INFO ):
91                  states[LEVEL_INFO] = true;
92              case ( LEVEL_WARNING ):
93                  states[LEVEL_WARNING] = true;
94              case ( LEVEL_ERROR ):
95                  states[LEVEL_ERROR] = true;
96              case ( LEVEL_SEVERE ):
97                  states[LEVEL_SEVERE] = true;
98              default:
99          }
100 
101         return states;
102     }
103 
104     /**
105      * @param messageLevel the message leve.
106      * @return The label.
107      */
108     public static String getLevelLabel( int messageLevel )
109     {
110         if ( messageLevel > -1 && LEVEL_NAMES.size() > messageLevel )
111         {
112             return (String) LEVEL_NAMES.get( messageLevel );
113         }
114 
115         throw new IllegalArgumentException( "Invalid message level: " + messageLevel );
116     }
117 }