KickJava   Java API By Example, From Geeks To Geeks.

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


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 conditional expression type constraints.
20  */

21 public final class ConditionalTypeConstraint implements ITypeConstraint2 {
22
23     /** The else type variable */
24     private final ConstraintVariable2 fElseVariable;
25
26     /** The expression type variable */
27     private final ConstraintVariable2 fExpressionVariable;
28
29     /** The then type variable */
30     private final ConstraintVariable2 fThenVariable;
31
32     /**
33      * Creates a new conditional type constraint.
34      *
35      * @param expressionVariable the expression type constraint variable
36      * @param thenVariable the then type constraint variable
37      * @param elseVariable the else type constraint variable
38      */

39     public ConditionalTypeConstraint(final ConstraintVariable2 expressionVariable, final ConstraintVariable2 thenVariable, final ConstraintVariable2 elseVariable) {
40         Assert.isNotNull(expressionVariable);
41         Assert.isNotNull(thenVariable);
42         Assert.isNotNull(elseVariable);
43         fExpressionVariable= expressionVariable;
44         fThenVariable= thenVariable;
45         fElseVariable= elseVariable;
46     }
47
48     /*
49      * @see java.lang.Object#equals(java.lang.Object)
50      */

51     public final boolean equals(final Object JavaDoc object) {
52         if (object.getClass() != ConditionalTypeConstraint.class)
53             return false;
54         final ITypeConstraint2 other= (ITypeConstraint2) object;
55         return getLeft() == other.getLeft() && getRight() == other.getRight();
56     }
57
58     /**
59      * Returns the expression type constraint variable.
60      *
61      * @return the expression type constraint variable
62      */

63     public final ConstraintVariable2 getExpression() {
64         return fExpressionVariable;
65     }
66
67     /*
68      * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2#getLeft()
69      */

70     public final ConstraintVariable2 getLeft() {
71         return fThenVariable;
72     }
73
74     /*
75      * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2#getRight()
76      */

77     public final ConstraintVariable2 getRight() {
78         return fElseVariable;
79     }
80
81     /*
82      * @see java.lang.Object#hashCode()
83      */

84     public final int hashCode() {
85         return fThenVariable.hashCode() ^ 33 * fElseVariable.hashCode();
86     }
87
88     /*
89      * @see java.lang.Object#toString()
90      */

91     public final String JavaDoc toString() {
92         return fThenVariable.toString() + " <?= " + fElseVariable.toString(); //$NON-NLS-1$
93
}
94 }
95
Popular Tags