<commit_before>package structure.impl;

import structure.intf.Binding;
import structure.intf.QEA;
import exceptions.ShouldNotHappenException;

/**
 * A QEA with at most one quantified variable
 * 
 * @author <NAME>
 * @author <NAME>
 */
public abstract class NonSimpleQEA implements QEA { // TODO Check name

	protected int[] finalStates; // TODO Can we use a boolean array here?

	protected final int initialState;

	protected final boolean isPropositional;

	protected final boolean quantificationUniversal;

	protected final int freeVariablesCount;

	public NonSimpleQEA(int numStates, int initialState,
			Quantification quantification, int freeVariablesCount) {
		finalStates = new int[numStates + 1];
		this.initialState = initialState;
		this.freeVariablesCount = freeVariablesCount;
		switch (quantification) {
		case FORALL:
			quantificationUniversal = true;
			isPropositional = false;
			break;
		case EXISTS:
			quantificationUniversal = false;
			isPropositional = false;
			break;
		case NONE:
			quantificationUniversal = false;
			isPropositional = true;
			break;
		default:
			throw new ShouldNotHappenException("Unknown quantification "
					+ quantification);
		}
	}

	/**
	 * Adds the specified state to the set of final states
	 * 
	 * @param state
	 *            State name
	 */
	public void setStateAsFinal(int state) {
		finalStates[state] = 1;
	}

	/**
	 * Adds the specified states to the set of final statess
	 * 
	 * @param states
	 *            Names of states to add
	 */
	public void setStatesAsFinal(int... states) {
		for (int state : states) {
			finalStates[state] = 1;
		}
	}

	@Override
	public int[] getStates() {
		int[] q = new int[finalStates.length - 1];
		for (int i = 0; i < q.length; i++) {
			q[i] = i + 1;
		}
		return q;
	}

	/**
	 * Creates a new binding of free variable for the current QEA
	 * 
	 * @return Binding
	 */
	public Binding newBinding() {
		return new BindingImpl(freeVariablesCount);
	}

	/**
	 * Returns the initial state for this QEA
	 * 
	 * @return Initial state
	 */
	public int getInitialState() {
		return initialState;
	}

	@Override
	public int[] getLambda() {
		if (isPropositional) {
			return new int[] {};
		}
		if (quantificationUniversal) {
			return new int[] { -1 };
		}
		return new int[] { 1 };
	}

	@Override
	public boolean usesFreeVariables() {
		return true;
	}

	@Override<commit_msg>Array of values for free variables increased size in 1. This is to avoid exception when free variables names start in 1<commit_after>package structure.impl;

import structure.intf.Binding;
import structure.intf.QEA;
import exceptions.ShouldNotHappenException;

/**
 * A QEA with at most one quantified variable
 * 
 * @author <NAME>
 * @author <NAME>
 */
public abstract class NonSimpleQEA implements QEA { // TODO Check name

	protected int[] finalStates; // TODO Can we use a boolean array here?

	protected final int initialState;

	protected final boolean isPropositional;

	protected final boolean quantificationUniversal;

	protected final int freeVariablesCount;

	public NonSimpleQEA(int numStates, int initialState,
			Quantification quantification, int freeVariablesCount) {
		finalStates = new int[numStates + 1];
		this.initialState = initialState;
		this.freeVariablesCount = freeVariablesCount;
		switch (quantification) {
		case FORALL:
			quantificationUniversal = true;
			isPropositional = false;
			break;
		case EXISTS:
			quantificationUniversal = false;
			isPropositional = false;
			break;
		case NONE:
			quantificationUniversal = false;
			isPropositional = true;
			break;
		default:
			throw new ShouldNotHappenException("Unknown quantification "
					+ quantification);
		}
	}

	/**
	 * Adds the specified state to the set of final states
	 * 
	 * @param state
	 *            State name
	 */
	public void setStateAsFinal(int state) {
		finalStates[state] = 1;
	}

	/**
	 * Adds the specified states to the set of final statess
	 * 
	 * @param states
	 *            Names of states to add
	 */
	public void setStatesAsFinal(int... states) {
		for (int state : states) {
			finalStates[state] = 1;
		}
	}

	@Override
	public int[] getStates() {
		int[] q = new int[finalStates.length - 1];
		for (int i = 0; i < q.length; i++) {
			q[i] = i + 1;
		}
		return q;
	}

	/**
	 * Creates a new binding of free variable for the current QEA
	 * 
	 * @return Binding
	 */
	public Binding newBinding() {
		// TODO Free variables names should start in 0 or 1?
		return new BindingImpl(freeVariablesCount + 1);
	}

	/**
	 * Returns the initial state for this QEA
	 * 
	 * @return Initial state
	 */
	public int getInitialState() {
		return initialState;
	}

	@Override
	public int[] getLambda() {
		if (isPropositional) {
			return new int[] {};
		}
		if (quantificationUniversal) {
			return new int[] { -1 };
		}
		return new int[] { 1 };
	}

	@Override
	public boolean usesFreeVariables() {
		return true;
	}

	@Override
{'fraction_non_alphanumeric': 0.0954610217789538, 'fraction_numerical': 0.0042743741095053935, 'mean_word_length': 3.2954545454545454, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2070', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1436, 'n_words': 491}