KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.constraints;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2;
16 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2;
17
18 /**
19  * Type constraint which models covariance-related types.
20  */

21 public final class CovariantTypeConstraint implements ITypeConstraint2 {
22
23     /** The ancestor type */
24     private final ConstraintVariable2 fAncestor;
25
26     /** The descendant type */
27     private final ConstraintVariable2 fDescendant;
28
29     /**
30      * Creates a new covariant type constraint.
31      *
32      * @param descendant the descendant type
33      * @param ancestor the ancestor type
34      */

35     public CovariantTypeConstraint(final ConstraintVariable2 descendant, final ConstraintVariable2 ancestor) {
36         Assert.isNotNull(descendant);
37         Assert.isNotNull(ancestor);
38         fDescendant= descendant;
39         fAncestor= ancestor;
40     }
41
42     /*
43      * @see java.lang.Object#equals(java.lang.Object)
44      */

45     public final boolean equals(final Object JavaDoc object) {
46         if (object.getClass() != CovariantTypeConstraint.class)
47             return false;
48         final ITypeConstraint2 other= (ITypeConstraint2) object;
49         return getLeft() == other.getLeft() && getRight() == other.getRight();
50     }
51
52     /*
53      * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2#getLeft()
54      */

55     public final ConstraintVariable2 getLeft() {
56         return fDescendant;
57     }
58
59     /*
60      * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2#getRight()
61      */

62     public final ConstraintVariable2 getRight() {
63         return fAncestor;
64     }
65
66     /*
67      * @see java.lang.Object#hashCode()
68      */

69     public final int hashCode() {
70         return fDescendant.hashCode() ^ 35 * fAncestor.hashCode();
71     }
72
73     /*
74      * @see java.lang.Object#toString()
75      */

76     public final String JavaDoc toString() {
77         return fDescendant.toString() + " <<= " + fAncestor.toString(); //$NON-NLS-1$
78
}
79 }
80
Popular Tags