View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.util.scan.annotations;
8   
9   import java.util.ArrayList;
10  import java.util.HashMap;
11  import java.util.List;
12  import java.util.Map;
13  
14  public class AnnotationInfo
15  {
16      private String className;
17      private List<NameValue> params = new ArrayList<NameValue>();
18  
19      public List<NameValue> getParams()
20      {
21          return params;
22      }
23  
24      public Map<String, Object> getParamsAsMap()
25      {
26          Map m = new HashMap(params.size());
27          for (NameValue param : params)
28          {
29              m.put(param.name, param.value);
30          }
31          return m;
32      }
33  
34      public void setParams(List<NameValue> params)
35      {
36          this.params = params;
37      }
38  
39      public String getClassName()
40      {
41          return className;
42      }
43  
44      public void setClassName(String className)
45      {
46          this.className = className;
47      }
48  
49      public boolean equals(final Object o)
50      {
51          if (this == o)
52          {
53              return true;
54          }
55          if (o == null || getClass() != o.getClass())
56          {
57              return false;
58          }
59  
60          final AnnotationInfo that = (AnnotationInfo) o;
61  
62          if (!className.equals(that.className))
63          {
64              return false;
65          }
66          if (params != null ? !params.equals(that.params) : that.params != null)
67          {
68              return false;
69          }
70  
71          return true;
72      }
73  
74      public int hashCode()
75      {
76          int result;
77          result = className.hashCode();
78          result = 31 * result + (params != null ? params.hashCode() : 0);
79          return result;
80      }
81  
82      @Override
83      public String toString()
84      {
85          StringBuilder sb = new StringBuilder(params.size() * 20);
86          sb.append(className).append('(');
87          for (int i = 0; i < params.size(); i++)
88          {
89              NameValue param = params.get(i);
90              sb.append(param.name).append('=').append(param.value);
91              if (i < params.size() - 1)
92              {
93                  sb.append(',');
94              } else
95              {
96                  sb.append(')');
97              }
98          }
99          return sb.toString();
100     }
101 
102     public static class NameValue
103     {
104         public String name;
105         public Object value;
106 
107         NameValue(final String name, final Object value)
108         {
109             this.name = name;
110             this.value = value;
111         }
112 
113         public boolean equals(final Object o)
114         {
115             if (this == o)
116             {
117                 return true;
118             }
119             if (o == null || getClass() != o.getClass())
120             {
121                 return false;
122             }
123 
124             final NameValue nameValue = (NameValue) o;
125 
126             if (!name.equals(nameValue.name))
127             {
128                 return false;
129             }
130             if (!value.equals(nameValue.value))
131             {
132                 return false;
133             }
134 
135             return true;
136         }
137 
138         public int hashCode()
139         {
140             int result;
141             result = name.hashCode();
142             result = 31 * result + value.hashCode();
143             return result;
144         }
145 
146         @Override
147         public String toString()
148         {
149             return String.format("%s=%s", name, value);
150         }
151     }
152 }