001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.corext.refactoring.structure;
011:
012: import org.eclipse.core.runtime.Assert;
013:
014: /**
015: * Maplet from a type variable in a source class to a type variable in a target class.
016: */
017: public final class TypeVariableMaplet {
018:
019: /** The source index */
020: private final int fSourceIndex;
021:
022: /** The source of the mapping */
023: private final String fSourceName;
024:
025: /** The target index */
026: private final int fTargetIndex;
027:
028: /** The target of the mapping */
029: private final String fTargetName;
030:
031: /**
032: * Creates a new type variable maplet.
033: *
034: * @param source
035: * the simple name of the type variable in the source class
036: * @param index
037: * the index of the source type variable in the source class declaration
038: * @param target
039: * the simple name of the type variable in the range class
040: * @param offset
041: * the index of the range type variable in the range class declaration
042: */
043: public TypeVariableMaplet(final String source, final int index,
044: final String target, final int offset) {
045: Assert.isNotNull(source);
046: Assert.isNotNull(target);
047: Assert.isTrue(source.length() > 0);
048: Assert.isTrue(target.length() > 0);
049: Assert.isTrue(index >= 0);
050: Assert.isTrue(offset >= 0);
051: fSourceName = source;
052: fTargetName = target;
053: fSourceIndex = index;
054: fTargetIndex = offset;
055: }
056:
057: public final boolean equals(final Object object) {
058: if (object instanceof TypeVariableMaplet) {
059: final TypeVariableMaplet mapping = (TypeVariableMaplet) object;
060: return mapping.getSourceName().equals(fSourceName)
061: && mapping.getTargetName().equals(fTargetName)
062: && mapping.getSourceIndex() == fSourceIndex
063: && mapping.getTargetIndex() == fTargetIndex;
064: }
065: return false;
066: }
067:
068: /**
069: * Returns the source index of this type variable maplet.
070: *
071: * @return the source index of this maplet
072: */
073: public final int getSourceIndex() {
074: return fSourceIndex;
075: }
076:
077: /**
078: * Returns the source of this type variable maplet.
079: *
080: * @return the source of this maplet
081: */
082: public final String getSourceName() {
083: return fSourceName;
084: }
085:
086: /**
087: * Returns the target index of this type variable maplet.
088: *
089: * @return the target index of this maplet
090: */
091: public final int getTargetIndex() {
092: return fTargetIndex;
093: }
094:
095: /**
096: * Returns the target of this type variable maplet.
097: *
098: * @return the target of this maplet
099: */
100: public final String getTargetName() {
101: return fTargetName;
102: }
103:
104: public final int hashCode() {
105: return fSourceIndex | fTargetIndex | fSourceName.hashCode()
106: | fTargetName.hashCode();
107: }
108: }
|