org.eclipse.ocl.internal.evaluation.IterationTemplateExists Maven / Gradle / Ivy
/**
*
*
* Copyright (c) 2005, 2007 IBM Corporation and others.
* 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:
* IBM - Initial API and implementation
*
*
*
* $Id: IterationTemplateExists.java,v 1.3 2009/09/01 20:11:22 ewillink Exp $
*/
package org.eclipse.ocl.internal.evaluation;
import java.util.List;
import org.eclipse.ocl.EvaluationEnvironment;
import org.eclipse.ocl.EvaluationVisitor;
import org.eclipse.ocl.expressions.Variable;
/**
*
*/
public final class IterationTemplateExists
extends IterationTemplate {
private IterationTemplateExists(
EvaluationVisitor v) {
super(v);
}
public static
IterationTemplate
getInstance(EvaluationVisitor v) {
return new IterationTemplateExists(v);
}
@Override
protected Object evaluateResult(List> iterators, String resultName, Object body) {
EvaluationEnvironment env = getEvalEnvironment();
// check for undefined result:
// the current result value cannot be true since the short-circuit
// "isDone" mechanism below would have caused the evaluation to stop.
// If the body result is undefined then the entire expression's value
// is invalid
if ((body == null) || (body == getInvalid())) {
setDone(true);
return getInvalid();
}
Boolean currVal = (Boolean)env.getValueOf(resultName);
Boolean bodyVal = (Boolean)body;
boolean resultVal = currVal.booleanValue() || bodyVal.booleanValue();
if (resultVal)
setDone(true);
return resultVal ? Boolean.TRUE : Boolean.FALSE;
}
}