KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > typeconstraints2 > SubTypeConstraint2


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.typeconstraints2;
12
13 import org.eclipse.core.runtime.Assert;
14
15 public final class SubTypeConstraint2 implements ITypeConstraint2 {
16
17     private final ConstraintVariable2 fAncestor;
18
19     private final ConstraintVariable2 fDescendant;
20
21     public SubTypeConstraint2(final ConstraintVariable2 descendant, final ConstraintVariable2 ancestor) {
22         Assert.isNotNull(descendant);
23         Assert.isNotNull(ancestor);
24         fDescendant= descendant;
25         fAncestor= ancestor;
26     }
27
28     /*
29      * @see java.lang.Object#equals(java.lang.Object)
30      */

31     public final boolean equals(Object JavaDoc other) {
32         // can use object identity on ConstraintVariables, since we have the stored (or to be stored) objects
33
if (other.getClass() != SubTypeConstraint2.class)
34             return false;
35
36         ITypeConstraint2 otherTC= (ITypeConstraint2) other;
37         return fDescendant == otherTC.getLeft() && fAncestor == otherTC.getRight();
38     }
39
40     public final ConstraintVariable2 getLeft() {
41         return fDescendant;
42     }
43
44     public final ConstraintVariable2 getRight() {
45         return fAncestor;
46     }
47
48     /*
49      * @see java.lang.Object#hashCode()
50      */

51     public final int hashCode() {
52         return fDescendant.hashCode() ^ 37 * fAncestor.hashCode();
53     }
54
55     /*
56      * @see java.lang.Object#toString()
57      */

58     public final String JavaDoc toString() {
59         return fDescendant.toString() + " <= " + fAncestor.toString(); //$NON-NLS-1$
60
}
61 }
62
Popular Tags