blob: 58214b739a12e096d7db71969bac6da61133bcde [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Akos Horvath, Gergely Varro - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
public class VariableID implements Comparable {
private GTPattern pattern;
private Integer uid;
private String variable;
public VariableID(GTPattern pattern, int uid, String variable) {
this.pattern = pattern;
this.uid = uid;
this.variable = variable;
}
public boolean equals(Object id) {
if (id != null && id instanceof VariableID) {
VariableID otherID = (VariableID) id;
return (pattern.getName().equals(otherID.pattern.getName()) &&
uid == otherID.uid &&
variable.equals(otherID.variable));
} else {
return false;
}
}
// TODO not a smooth solution
public int hashCode() {
//return 1;
return uid;
// return uid+geVariableName().hashCode;
}
public int compareTo(Object arg0) {
VariableID otherID = (VariableID) arg0;
if(equals(arg0))
return 0;
else
if(uid == otherID.uid)
return variable.compareTo(otherID.variable);
else
return (uid < otherID.uid ? -1 : 1);
}
public String toString() {
return pattern.getName() + "_" + uid.toString() + "_" + variable;
}
/** Returns the user friendly (readable) representation of the search node's name
* @return
*/
public String getFancyName() {
return "'"+variable + " variable of pattern "+pattern.getName()+"'";
}
}