View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.logging.log4j.audit.util;
18  
19  public final class NamingUtils {
20  
21      private NamingUtils() {
22      }
23  
24      public static String getPackageName(String className) {
25          return className.substring(0, className.lastIndexOf("."));
26      }
27  
28      public static String getSimpleName(String className) {
29          return className.substring(className.lastIndexOf(".") + 1);
30      }
31  
32      public static String getMethodShortName(String name) {
33          return name.replaceFirst("(get|set|is|has)", "");
34      }
35  
36      public static String upperFirst(String name) {
37          return String.valueOf(name.charAt(0)).toUpperCase() + name.substring(1);
38      }
39  
40      public static String lowerFirst(String name) {
41          return String.valueOf(name.charAt(0)).toLowerCase() + name.substring(1);
42      }
43  
44      public static String getSetterName(String fieldName) {
45          return "set" + upperFirst(fieldName);
46      }
47  
48      public static String getGetterName(String fieldName, String type) {
49          if ("boolean".equals(type)) {
50              return "is" + upperFirst(fieldName);
51          } else {
52              return "get" + upperFirst(fieldName);
53          }
54      }
55  
56      public static String getClassName(String className) {
57          return upperFirst(className.replaceAll("[^a-zA-Z0-9_]+", ""));
58      }
59  
60      public static String getFieldName(String fieldName) {
61          return fieldName.replaceAll("[^a-zA-Z0-9_]+", "");
62      }
63  
64      public static String methodCaseName(String variable) {
65          return variable.substring(0, 1).toUpperCase() + variable.substring(1);
66      }
67  
68      public static String getAccessorName(String type, String methodName) {
69          String prefix = "get";
70          if (type.equals("boolean")) {
71              prefix = "is";
72          }
73          return prefix + methodCaseName(methodName);
74      }
75  
76      public static String getMutatorName(String methodName) {
77          return "set" + methodCaseName(methodName);
78      }
79  }