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

com.ecfeed.core.model.LabelCondition Maven / Gradle / Ivy

Go to download

An open library used to connect to the ecFeed service. It can be also used as a standalone testing tool. It is integrated with Junit5 and generates a stream of test cases using a selected algorithm (e.g. Cartesian, N-Wise). There are no limitations associated with the off-line version but the user cannot access the on-line computation servers and the model database.

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2016 ecFeed AS.                                                
 * 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 
 *  
 *******************************************************************************/

package com.ecfeed.core.model;

import java.util.ArrayList;
import java.util.List;

import com.ecfeed.core.utils.EMathRelation;
import com.ecfeed.core.utils.EvaluationResult;
import com.ecfeed.core.utils.MessageStack;

public class LabelCondition implements IStatementCondition {

	private String fRightLabel;
	private RelationStatement fParentRelationStatement;

	public LabelCondition(String label, RelationStatement parentRelationStatement) {
		fRightLabel = label;
		fParentRelationStatement = parentRelationStatement;
	}

	@Override
	public EvaluationResult evaluate(List choices) {

		ChoiceNode choice = 
				StatementConditionHelper.getChoiceForMethodParameter(
						choices, fParentRelationStatement.getLeftParameter());

		if (choice == null) {
			return EvaluationResult.INSUFFICIENT_DATA;
		}

		return evaluateContainsLabel(choice);
	}

	@Override
	public boolean updateReferences(MethodNode methodNode) {

		return true;
	}

	@Override
	public Object getCondition(){
		return fRightLabel;
	}

	@Override
	public boolean adapt(List values) {
		return false;
	}

	@Override
	public boolean compare(IStatementCondition condition) {

		if(condition instanceof LabelCondition == false) {
			return false;
		}

		LabelCondition compared = (LabelCondition)condition;

		return (getCondition().equals(compared.getCondition()));
	}

	@Override
	public Object accept(IStatementVisitor visitor) throws Exception {
		return visitor.visit(this);
	}

	@Override
	public String toString() {
		return StatementConditionHelper.createLabelDescription(fRightLabel);
	}

	@Override
	public LabelCondition getCopy() {
		return new LabelCondition(fRightLabel, fParentRelationStatement);
	}

	public String getRightLabel() {
		return fRightLabel;
	}

	@Override
	public boolean mentions(MethodParameterNode methodParameterNode) {

		return false;
	}

	private EvaluationResult evaluateContainsLabel(ChoiceNode choice) {

		boolean containsLabel = choice.getAllLabels().contains(fRightLabel);

		EMathRelation relation = fParentRelationStatement.getRelation(); 

		switch (relation) {

		case EQUAL:
			return EvaluationResult.convertFromBoolean(containsLabel);
		case NOT_EQUAL:
			return EvaluationResult.convertFromBoolean(!containsLabel);
		default:
			return EvaluationResult.FALSE;
		}

	}

	@Override
	public boolean isAmbiguous(List> domain, MessageStack messageStack) {
		return false;
	}

	@Override
	public List getListOfChoices() {
		return new ArrayList();
	}

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy