001: /*/////////////////////////////////////////////////////////////////////
002:
003: Copyright (C) 2006 TiVo Inc. 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 TiVo Inc 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: /////////////////////////////////////////////////////////////////////*/
030:
031: package com.tivo.jipviewer;
032:
033: /**
034: * Represents a method.
035: * It's immutable.
036: *
037: * Some definitions:
038: * if constructed with the name 'com.tivo.trio.util.Dict:getString',
039: *
040: * methodName = getString
041: * className = Dict
042: * package = com.tivo.trio.util
043: *
044: */
045:
046: class JipMethod {
047: final String mName;
048:
049: // these are just so i don't keep parsing them out
050: // on every call. they're fully computable from mName!
051: final String mMethodName;
052: final String mClassName;
053: final String mPackageName;
054:
055: JipMethod(String name) {
056: mName = name;
057:
058: //
059: // pre-compute all the subnames.
060: //
061:
062: // method name...
063: int iColon = mName.lastIndexOf(':');
064: mMethodName = mName.substring(iColon + 1);
065: if (iColon == -1) {
066: mClassName = "";
067: mPackageName = "";
068: } else {
069: String fullClass = mName.substring(0, iColon);
070: int iDot = fullClass.lastIndexOf('.');
071: mClassName = fullClass.substring(iDot + 1);
072: if (iDot == -1) {
073: mPackageName = "";
074: } else {
075: mPackageName = fullClass.substring(0, iDot);
076: }
077: }
078: }
079:
080: String getName() {
081: return mName;
082: }
083:
084: String getClassName() {
085: return mClassName;
086: }
087:
088: String getMethodName() {
089: return mMethodName;
090: }
091:
092: String getPackageName() {
093: return mPackageName;
094: }
095:
096: //
097: // from object
098: //
099:
100: @Override
101: public String toString() {
102: return mName;
103: }
104:
105: @Override
106: public boolean equals(Object object) {
107: if (!(object instanceof JipMethod)) {
108: throw new RuntimeException("other isA " + object.getClass());
109: }
110: JipMethod other = (JipMethod) object;
111: return mName.equals(other.mName);
112: }
113:
114: @Override
115: public int hashCode() {
116: return mName.hashCode();
117: }
118: };
|