Ptidej-v5.2-master/Ptidej Solver Metrics Tests/src/ptidej/solver/test/data/problem/fingerprint/CompositionTest.java
/*******************************************************************************
 * Copyright (c) 2001-2014 Yann-Gal Guhneuc and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Yann-Gal Guhneuc and others, see in file; API and its implementation
 ******************************************************************************/
package ptidej.solver.test.data.problem.fingerprint;

import java.util.ArrayList;
import java.util.List;
import ptidej.solver.Problem;
import ptidej.solver.Variable;
import ptidej.solver.approximation.DefaultNoApproximations;
import ptidej.solver.constraint.repository.CompositionConstraint;
import ptidej.solver.constraint.repository.NotEqualConstraint;

/**
 * @author Yann-Gal Guhneuc
 * @since  2004/09/05 
 */
public final class CompositionTest {
	public static final char[] AGGREGATED = "Aggregated".toCharArray();
	public static final char[] AGGREGATE = "Aggregate".toCharArray();

	public static Problem getProblem(final List allEntities) {
		final Problem pb = new Problem(90, "Composition Test", allEntities);

		final ArrayList aggregateList = new ArrayList();
		aggregateList.add(allEntities.get(2));
		aggregateList.add(allEntities.get(3));

		final ArrayList aggregatedList = new ArrayList();
		aggregatedList.add(allEntities.get(0));
		aggregatedList.add(allEntities.get(1));

		final Variable aggregate =
			new Variable(pb, CompositionTest.AGGREGATE, true, aggregateList);
		final Variable aggregated =
			new Variable(pb, CompositionTest.AGGREGATED, true, aggregatedList);

		pb.addVar(aggregate);
		pb.addVar(aggregated);

		final CompositionConstraint c1 =
			new CompositionConstraint(
				"Aggregate <>--> Aggregated",
				"throw new RuntimeException(\"Composite <>--> Component\");",
				aggregate,
				aggregated,
				100,
				DefaultNoApproximations.getDefaultApproximations());
		final NotEqualConstraint c2 =
			new NotEqualConstraint(
				"Composite <> leaf",
				"throw new RuntimeException(\"Aggregate <> Aggregated\");",
				aggregate,
				aggregated,
				100,
				DefaultNoApproximations.getDefaultApproximations());

		pb.post(c1);
		pb.post(c2);

		return pb;
	}
}
