/*******************************************************************************
* Copyright (c) 2005, 2009 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
*******************************************************************************/
package org.eclipse.ocl.internal.evaluation;
import java.util.Collection;
import java.util.List;
import org.eclipse.ocl.EvaluationEnvironment;
import org.eclipse.ocl.EvaluationVisitor;
import org.eclipse.ocl.expressions.Variable;
/**
*
*/
public final class IterationTemplateCollectNested<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E>
extends IterationTemplate<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> {
private IterationTemplateCollectNested(
EvaluationVisitor<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> v) {
super(v);
}
public static<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E>
IterationTemplate<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> getInstance(
EvaluationVisitor<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> v) {
return new IterationTemplateCollectNested<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E>(v);
}
@Override
protected Object evaluateResult(List<Variable<C, PM>> iterators, String resultName, Object bodyVal) {
EvaluationEnvironment<C, O, P, CLS, E> env = getEvalEnvironment();
@SuppressWarnings("unchecked")
Collection<Object> currVal = (Collection<Object>) env.getValueOf(resultName);
// If the body result is invalid then the entire expression's value
// is invalid, because OCL does not permit invalid in a collection
if (bodyVal == getInvalid()) {
setDone(true);
return bodyVal;
}
currVal.add(bodyVal);
return currVal;
}
}