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.generator;
18  
19  import java.util.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  
23  import static org.apache.logging.log4j.audit.generator.Constants.*;
24  
25  public class ConstructorDefinition implements Comparable<ConstructorDefinition> {
26      private String visability = PUBLIC;
27  
28      private String name;
29  
30      private List<Parameter> parameters = new ArrayList<>();
31  
32      private List<String> exceptions = new ArrayList<>();
33  
34      private String content;
35  
36      public ConstructorDefinition(String className) {
37          this.name = className;
38      }
39  
40      public String getContent() {
41          return content;
42      }
43  
44      public List<String> getExceptions() {
45          return exceptions;
46      }
47  
48      public String getName() {
49          return name;
50      }
51  
52      public List<Parameter> getParameters() {
53          return parameters;
54      }
55  
56      public String getVisability() {
57          return visability;
58      }
59  
60      public void setContent(String content) {
61          this.content = content;
62      }
63  
64      public void setExceptions(List<String> exceptions) {
65          this.exceptions = exceptions;
66      }
67  
68      public void setName(String name) {
69          this.name = name;
70      }
71  
72      public void setParameters(List<Parameter> parameters) {
73          this.parameters = parameters;
74      }
75  
76      public void setVisability(String visability) {
77          this.visability = visability;
78      }
79  
80      @Override
81      public String toString() {
82          StringBuilder sb = new StringBuilder();
83          sb.append(getVisability()).append(" ");
84          sb.append(getName()).append("(");
85          if (getParameters() != null) {
86              boolean first = true;
87              for (Iterator<Parameter> iter = getParameters().iterator(); iter
88                      .hasNext(); ) {
89                  Parameter element = iter.next();
90                  if (!first) {
91                      sb.append(", ");
92                  }
93                  sb.append(element);
94                  first = false;
95              }
96          }
97          sb.append(")");
98          if (getExceptions() != null && getExceptions().size() > 0) {
99              sb.append(" throws ");
100             boolean first = true;
101             for (Iterator<String> iter = getExceptions().iterator(); iter
102                     .hasNext(); ) {
103                 String element = iter.next();
104                 if (!first) {
105                     sb.append(", ");
106                 }
107                 sb.append(element);
108                 first = false;
109             }
110         }
111 
112         sb.append(" {\n");
113         sb.append(getContent());
114         sb.append("\n}\n\n");
115         return sb.toString();
116     }
117 
118     @Override
119     public int compareTo(ConstructorDefinition arg0) {
120         return getParameters().size() - arg0.getParameters().size();
121     }
122 }