001: /*
002: Copyright (c) 2005, MentorGen, LLC
003: All rights reserved.
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions are met:
007:
008: + Redistributions of source code must retain the above copyright notice,
009: this list of conditions and the following disclaimer.
010: + Redistributions in binary form must reproduce the above copyright notice,
011: this list of conditions and the following disclaimer in the documentation
012: and/or other materials provided with the distribution.
013: + Neither the name of MentorGen LLC nor the names of its contributors may be
014: used to endorse or promote products derived from this software without
015: specific prior written permission.
016:
017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
020: ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
021: LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
022: CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
023: SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
024: INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
025: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
026: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
027: POSSIBILITY OF SUCH DAMAGE.
028: */
029: package com.mentorgen.tools.profile.runtime;
030:
031: /**
032: * A simple class to capture metrics for a method in a particular thread
033: *
034: * @author Andrew Wilcox
035: *
036: */
037: final class Method {
038: private String _className;
039: private String _methodName;
040:
041: Method(String className, String method) {
042: _className = className;
043: _methodName = method;
044: }
045:
046: String getClassName() {
047: return _className;
048: }
049:
050: String getMethodName() {
051: return _methodName;
052: }
053:
054: String toInvertedString() {
055: String className = _className.replace('/', '.');
056:
057: int index = className.lastIndexOf('.');
058: String shortName = null;
059: String packageName = "";
060:
061: if (index > -1) {
062: shortName = className.substring(index + 1);
063: packageName = className.substring(0, index);
064: } else {
065: shortName = className;
066: }
067:
068: StringBuffer b = new StringBuffer();
069: b.append(shortName);
070: b.append(':');
071: b.append(_methodName);
072: b.append("\t(");
073: b.append(packageName);
074: b.append(")");
075: return b.toString();
076: }
077:
078: //
079: // from object
080: //
081:
082: public String toString() {
083: StringBuffer b = new StringBuffer(_className.replace('/', '.'));
084: b.append(':');
085: b.append(_methodName);
086: return b.toString();
087: }
088:
089: @Override
090: public boolean equals(Object other) {
091: assert other instanceof Method;
092: Method m = (Method) other;
093: return this ._className.equals(m._className)
094: && this ._methodName.equals(m._methodName);
095: }
096:
097: @Override
098: public int hashCode() {
099: return _className.hashCode() + _methodName.hashCode();
100: }
101:
102: }
|