use of org.osate.xtext.aadl2.errormodel.util.EMV2Util in project osate2 by osate.
the class EMV2Util method isEqual.
/**
* Determine if the two expressions are the same.
* Compare operators and compare referenced elements by pathname
* @param ce1
* @param ce2
* @return
*/
public static boolean isEqual(ConditionExpression ce1, ConditionExpression ce2) {
if ((ce1 == null) && (ce2 == null)) {
return true;
}
if (ce1 == null) {
return false;
}
if (ce2 == null) {
return false;
}
if (ce1.getClass() != ce2.getClass()) {
return false;
}
// They are the same class, so we test for only one being a certain class
if (ce1 instanceof ConditionElement) {
ConditionElement element1 = (ConditionElement) ce1;
ConditionElement element2 = (ConditionElement) ce2;
return (getPathNameWithoutType(element1.getQualifiedErrorPropagationReference().getEmv2Target()).equalsIgnoreCase(getPathNameWithoutType(element2.getQualifiedErrorPropagationReference().getEmv2Target())));
}
if (ce1 instanceof AndExpression) {
AndExpression expr1 = (AndExpression) ce1;
AndExpression expr2 = (AndExpression) ce2;
if (expr1.getOperands().size() != expr2.getOperands().size()) {
return false;
}
for (int i = 0; i < expr1.getOperands().size(); i++) {
if (!isEqual(expr1.getOperands().get(i), expr2.getOperands().get(i))) {
return false;
}
}
return true;
}
if (ce1 instanceof OrExpression) {
OrExpression expr1 = (OrExpression) ce1;
OrExpression expr2 = (OrExpression) ce2;
if (expr1.getOperands().size() != expr2.getOperands().size()) {
return false;
}
for (int i = 0; i < expr1.getOperands().size(); i++) {
if (!isEqual(expr1.getOperands().get(i), expr2.getOperands().get(i))) {
return false;
}
}
return true;
}
OsateDebug.osateDebug("[EMV2Util] isEqual does not handled this class type " + ce1 + "|" + ce2);
return false;
}
Aggregations