KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > expressions > EqualsExpression


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.core.internal.expressions;
12
13 import org.w3c.dom.Element JavaDoc;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18
19 import org.eclipse.core.expressions.EvaluationResult;
20 import org.eclipse.core.expressions.Expression;
21 import org.eclipse.core.expressions.ExpressionInfo;
22 import org.eclipse.core.expressions.IEvaluationContext;
23
24 public class EqualsExpression extends Expression {
25     /**
26      * The seed for the hash code for all equals expressions.
27      */

28     private static final int HASH_INITIAL= EqualsExpression.class.getName().hashCode();
29
30     private Object JavaDoc fExpectedValue;
31     
32     public EqualsExpression(Object JavaDoc expectedValue) {
33         Assert.isNotNull(expectedValue);
34         fExpectedValue= expectedValue;
35     }
36     
37     public EqualsExpression(IConfigurationElement element) throws CoreException {
38         String JavaDoc value= element.getAttribute(ATT_VALUE);
39         Expressions.checkAttribute(ATT_VALUE, value);
40         fExpectedValue= Expressions.convertArgument(value);
41     }
42
43     public EqualsExpression(Element JavaDoc element) throws CoreException {
44         String JavaDoc value= element.getAttribute(ATT_VALUE);
45         Expressions.checkAttribute(ATT_VALUE, value.length() > 0 ? value : null);
46         fExpectedValue= Expressions.convertArgument(value);
47     }
48
49     public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
50         Object JavaDoc element= context.getDefaultVariable();
51         return EvaluationResult.valueOf(element.equals(fExpectedValue));
52     }
53
54     public void collectExpressionInfo(ExpressionInfo info) {
55         info.markDefaultVariableAccessed();
56     }
57
58     public boolean equals(final Object JavaDoc object) {
59         if (!(object instanceof EqualsExpression))
60             return false;
61         
62         final EqualsExpression that= (EqualsExpression)object;
63         return this.fExpectedValue.equals(that.fExpectedValue);
64     }
65
66     protected int computeHashCode() {
67         return HASH_INITIAL * HASH_FACTOR + fExpectedValue.hashCode();
68     }
69 }
70
Popular Tags