]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints2/SubTypeConstraint2.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / core refactoring / org / eclipse / jdt / internal / corext / refactoring / typeconstraints2 / SubTypeConstraint2.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 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         @Override
32         public final boolean equals(Object other) {
33                 // can use object identity on ConstraintVariables, since we have the stored (or to be stored) objects
34                 if (other.getClass() != SubTypeConstraint2.class)
35                         return false;
36
37                 ITypeConstraint2 otherTC= (ITypeConstraint2) other;
38                 return fDescendant == otherTC.getLeft() && fAncestor == otherTC.getRight();
39         }
40
41         public final ConstraintVariable2 getLeft() {
42                 return fDescendant;
43         }
44
45         public final ConstraintVariable2 getRight() {
46                 return fAncestor;
47         }
48
49         /*
50          * @see java.lang.Object#hashCode()
51          */
52         @Override
53         public final int hashCode() {
54                 return fDescendant.hashCode() ^ 37 * fAncestor.hashCode();
55         }
56
57         /*
58          * @see java.lang.Object#toString()
59          */
60         @Override
61         public final String toString() {
62                 return fDescendant.toString() + " <= " + fAncestor.toString(); //$NON-NLS-1$
63         }
64 }