All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.ocl.internal.evaluation.IterationTemplateAny Maven / Gradle / Ivy

/**
 * 
 *
 * Copyright (c) 2005, 2009 IBM Corporation, Borland Software Corp., 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
 *   Borland - Bug 265066
 *
 * 
 *
 * $Id: IterationTemplateAny.java,v 1.5 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 class IterationTemplateAny
		extends IterationTemplate {

	protected IterationTemplateAny(
			EvaluationVisitor v) {
	
		super(v);
	}

	public static 
	IterationTemplate getInstance(
			EvaluationVisitor v) {
		return new IterationTemplateAny(v);
	}
	
	@Override
    protected Object evaluateResult(
			List> iterators, String resultName, Object bodyVal) {
		
		EvaluationEnvironment env = getEvalEnvironment();
		// should be exactly one iterator
		String iterName = iterators.get(0).getName();
		Object currObj = env.getValueOf(iterName);
		Object resultVal = null;
		
		// If the body result is undefined then the entire expression's value
		// is invalid
		if ((bodyVal == null) || (bodyVal == getInvalid())) {
			setDone(true);
			return getInvalid();
		}
		
		boolean bodyCond = ((Boolean)bodyVal).booleanValue();
		if (bodyCond) {
			resultVal = currObj;
			setDone(true);
		}
		return resultVal;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy