1 /***************************************************************************************
2 * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
3 * http://aspectwerkz.codehaus.org *
4 * ---------------------------------------------------------------------------------- *
5 * The software in this package is published under the terms of the LGPL license *
6 * a copy of which has been included with this distribution in the license.txt file. *
7 **************************************************************************************/
8 package org.codehaus.aspectwerkz.reflect;
9
10 /***
11 * Holds a tuple that consists of the class info and the info for a specific method.
12 *
13 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
14 * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
15 */
16 public class CflowMetaData {
17 /***
18 * The class name.
19 */
20 private final String m_className;
21
22 /***
23 * The class info.
24 */
25 private ClassInfo m_classMetaData;
26
27 /***
28 * The method info.
29 */
30 private final MethodInfo m_methodMetaData;
31
32 /***
33 * Creates a new ClassNameMethodInfoTuple.
34 *
35 * @param classMetaData the class metaData
36 * @param methodMetaData the method info
37 */
38 public CflowMetaData(final ClassInfo classMetaData, final MethodInfo methodMetaData) {
39 m_className = classMetaData.getName();
40 m_classMetaData = classMetaData;
41 m_methodMetaData = methodMetaData;
42 }
43
44 /***
45 * Returns the class info.
46 *
47 * @return the class info
48 */
49 public ClassInfo getClassInfo() {
50 return m_classMetaData;
51 }
52
53 /***
54 * Returns the class name.
55 *
56 * @return the class name
57 */
58 public String getClassName() {
59 return m_className;
60 }
61
62 /***
63 * Returns the method info.
64 *
65 * @return the method info
66 */
67 public MethodInfo getMethodInfo() {
68 return m_methodMetaData;
69 }
70
71
72 public String toString() {
73 return '[' + super.toString() + ": " + ',' + m_className + ',' + m_classMetaData + ',' + m_methodMetaData + ']';
74 }
75
76 public int hashCode() {
77 int result = 17;
78 result = (37 * result) + hashCodeOrZeroIfNull(m_className);
79 result = (37 * result) + hashCodeOrZeroIfNull(m_classMetaData);
80 result = (37 * result) + hashCodeOrZeroIfNull(m_methodMetaData);
81 return result;
82 }
83
84 protected static int hashCodeOrZeroIfNull(final Object o) {
85 if (null == o) {
86 return 19;
87 }
88 return o.hashCode();
89 }
90
91 public boolean equals(final Object o) {
92 if (this == o) {
93 return true;
94 }
95 if (!(o instanceof CflowMetaData)) {
96 return false;
97 }
98 final CflowMetaData obj = (CflowMetaData) o;
99 return areEqualsOrBothNull(obj.m_className, this.m_className)
100 && areEqualsOrBothNull(obj.m_classMetaData, this.m_classMetaData)
101 && areEqualsOrBothNull(obj.m_methodMetaData, this.m_methodMetaData);
102 }
103
104 protected static boolean areEqualsOrBothNull(final Object o1, final Object o2) {
105 if (null == o1) {
106 return (null == o2);
107 }
108 return o1.equals(o2);
109 }
110 }