KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > structure > TypeVariableMaplet


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.refactoring.structure;
12
13 import org.eclipse.core.runtime.Assert;
14
15 /**
16  * Maplet from a type variable in a source class to a type variable in a target class.
17  */

18 public final class TypeVariableMaplet {
19
20     /** The source index */
21     private final int fSourceIndex;
22
23     /** The source of the mapping */
24     private final String JavaDoc fSourceName;
25
26     /** The target index */
27     private final int fTargetIndex;
28
29     /** The target of the mapping */
30     private final String JavaDoc fTargetName;
31
32     /**
33      * Creates a new type variable maplet.
34      *
35      * @param source
36      * the simple name of the type variable in the source class
37      * @param index
38      * the index of the source type variable in the source class declaration
39      * @param target
40      * the simple name of the type variable in the range class
41      * @param offset
42      * the index of the range type variable in the range class declaration
43      */

44     public TypeVariableMaplet(final String JavaDoc source, final int index, final String JavaDoc target, final int offset) {
45         Assert.isNotNull(source);
46         Assert.isNotNull(target);
47         Assert.isTrue(source.length() > 0);
48         Assert.isTrue(target.length() > 0);
49         Assert.isTrue(index >= 0);
50         Assert.isTrue(offset >= 0);
51         fSourceName= source;
52         fTargetName= target;
53         fSourceIndex= index;
54         fTargetIndex= offset;
55     }
56
57     public final boolean equals(final Object JavaDoc object) {
58         if (object instanceof TypeVariableMaplet) {
59             final TypeVariableMaplet mapping= (TypeVariableMaplet) object;
60             return mapping.getSourceName().equals(fSourceName) && mapping.getTargetName().equals(fTargetName) && mapping.getSourceIndex() == fSourceIndex && mapping.getTargetIndex() == fTargetIndex;
61         }
62         return false;
63     }
64
65     /**
66      * Returns the source index of this type variable maplet.
67      *
68      * @return the source index of this maplet
69      */

70     public final int getSourceIndex() {
71         return fSourceIndex;
72     }
73
74     /**
75      * Returns the source of this type variable maplet.
76      *
77      * @return the source of this maplet
78      */

79     public final String JavaDoc getSourceName() {
80         return fSourceName;
81     }
82
83     /**
84      * Returns the target index of this type variable maplet.
85      *
86      * @return the target index of this maplet
87      */

88     public final int getTargetIndex() {
89         return fTargetIndex;
90     }
91
92     /**
93      * Returns the target of this type variable maplet.
94      *
95      * @return the target of this maplet
96      */

97     public final String JavaDoc getTargetName() {
98         return fTargetName;
99     }
100
101     public final int hashCode() {
102         return fSourceIndex | fTargetIndex | fSourceName.hashCode() | fTargetName.hashCode();
103     }
104 }
105
Popular Tags