View Javadoc

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