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