<commit_before>package structure.intf;

import java.util.HashSet;

import exceptions.ShouldNotHappenException;

public abstract class Guard {

	/**
	 * Checking the guard
	 * 
	 * @return true if guard evaluates to true on binding
	 */
	public abstract boolean check(Binding binding);

	public abstract boolean check(Binding binding, int qvar, Object firstQval);

	public abstract boolean usesQvars();

	public abstract int[] vars();

	public Guard replace(int var, Object val) {
		throw new ShouldNotHappenException(
				"Not implemented - experimental feature!");
	}

	protected final String name;

	public Guard(String name) {
		this.name = name;
	}

	/*
	 * Get the name of the guard
	 * 
	 * @return the name of the guard
	 */
	public String getName() {
		return name;
	}

	public static Guard isTrue(final int var0) {
		return new Guard("x_" + var0 + "== true") {
			@Override
			public boolean check(Binding binding) {
				boolean val0 = (Boolean) binding.getForced(var0);
				return val0;
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				boolean val0 = (Boolean) ((var0 == qvar) ? firstQval : binding
						.getForced(var0));
				return val0;
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0 };
			}
		};
	}

	/*
	 * Produce a guard capturing binding(var0) == binding(var1)
	 * 
	 * @ returns a guard for this property
	 */
	public static Guard isEqual(final int var0, final int var1) {
		return new Guard("x_" + var0 + " == x_" + var1) {
			@Override
			public boolean check(Binding binding) {
				Object val0 = binding.getForced(var0);
				Object val1 = binding.getForced(var1);
				return (val0 == val1);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object val0 = (var0 == qvar) ? firstQval : binding
						.getForced(var0);
				Object val1 = (var1 == qvar) ? firstQval : binding
						.getForced(var1);
				return (val0 == val1);
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0 || var1 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0, var1 };
			}
		};
	}

	public static Guard varIsEqualToIntVal(final int var, final int val) {
		return new Guard("x_" + var + " == " + val) {
			@Override
			public boolean check(Binding binding) {
				int varVal = binding.getForcedAsInteger(var);
				return varVal == val;
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				int varVal = (Integer) ((var == qvar) ? firstQval : binding
						.getForced(var));
				return varVal == val;
			}

			@Override
			public boolean usesQvars() {
				return var < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var };
			}
		};
	}

	public static Guard isSemEqualToConstant(final int var0, final Object value) {
		return new Guard("x_" + var0 + " equals x_" + value) {
			@Override
			public boolean check(Binding binding) {
				Object val0 = binding.getForced(var0);
				return (val0.equals(value));
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object val0 = (var0 == qvar) ? firstQval : binding
						.getForced(var0);
				return (val0.equals(value));
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0 };
			}
		};
	}

	/*
	 * Produce a guard capturing binding(var0) != binding(var1)
	 * 
	 * @ returns a guard for this property
	 */
	public static Guard isNotEqual(final int var0, final int var1) {
		return new Guard("x_" + var0 + " != x_" + var1) {
			@Override
			public boolean check(Binding binding) {
				Object val0 = binding.getForced(var0);
				Object val1 = binding.getForced(var1);
				return (val0 != val1);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object val0 = (var0 == qvar) ? firstQval : binding
						.getForced(var0);
				Object val1 = (var1 == qvar) ? firstQval : binding
						.getForced(var1);
				return (val0 != val1);
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0 || var1 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0, var1 };
			}
		};
	}

	/*
	 * Produce a guard capturing binding(var0) equals binding(var1)
	 * 
	 * @ returns a guard for this property
	 */
	public static Guard isEqualSem(final int var0, final int var1) {
		return new Guard("x_" + var0 + " equals x_" + var1) {
			@Override
			public boolean check(Binding binding) {
				Object val0 = binding.getForced(var0);
				Object val1 = binding.getForced(var1);
				return val0.equals(val1);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object val0 = (var0 == qvar) ? firstQval : binding
						.getForced(var0);
				Object val1 = (var1 == qvar) ? firstQval : binding
						.getForced(var1);
				return val0.equals(val1);
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0 || var1 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0, var1 };
			}
		};
	}

	public static Guard varIsEqualSemToVal(final int var, final Object val) {
		return new Guard("x_" + var + " == " + val) {
			@Override
			public boolean check(Binding binding) {
				Object varVal = binding.getForced(var);
				return varVal.equals(val);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object varVal = (var == qvar) ? firstQval : binding
						.getForced(var);
				return varVal.equals(val);
			}

			@Override
			public boolean usesQvars() {
				return var < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var };
			}
		};
	}

	public static Guard varIsNotEqualSemToVal(final int var, final Object val) {
		return new Guard("x_" + var + " != " + val) {
			@Override
			public boolean check(Binding binding) {
				Object varVal = binding.getForced(var);
				return !varVal.equals(val);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object varVal = (var == qvar) ? firstQval : binding
						.getForced(var);
				return !varVal.equals(val);
			}

			@Override
			public boolean usesQvars() {
				return var < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var };
			}
		};
	}

	/*
	 * Produce a guard capturing binding(var0) > binding(var1)
	 * 
	 * @ returns a guard for this property
	 */
	public static Guard isGreaterThan(final int var0, final int var1) {
		return new Guard("x_" + var0 + " > x_" + var1) {
			@Override
			public boolean check(Binding binding) {
				Integer val0 = binding.getForcedAsInteger(var0);
				Integer val1 = binding.getForcedAsInteger(var1);
				return (val0 > val1);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Integer val0 = (Integer) ((var0 == qvar) ? firstQval : binding
						.getForced(var0));
				Integer val1 = (Integer) ((var1 == qvar) ? firstQval : binding
						.getForced(var1));
				return (val0 > val1);
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0 || var1 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0, var1 };
			}

			/*
			 * public Guard replace(final int var, final Object val){
			 * if(var!=var0 && var!=var1) return this; return new Guard(""){
			 * public boolean check(Binding binding){ Integer val0 = (Integer)
			 * ((var0==var) ? val : binding.getForcedAsInteger(var0)); Integer
			 * val1 = (Integer) ((var1==var) ? val :
			 * binding.getForcedAsInteger(var1)); return (val0 > val1); }
			 * 
			 * @Override public boolean usesQvars() { return false; } }; }
			 */
		};
	}

	public static Guard varIsLessThanVal(final int var, final int val) {
		return new Guard("x_" + var + " < " + val) {

			@Override
			public int[] vars() {
				return new int[] { var };
			}

			@Override
			public boolean usesQvars() {
				return var < 0;
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Integer varVal = (Integer) ((var == qvar) ? firstQval : binding
						.getForced(var));
				return varVal < val;
			}

			@Override
			public boolean check(Binding binding) {
				int varVal = binding.getForcedAsInteger(var);
				return varVal < val;
			}
		};
	}

	public static Guard varIsGreaterThanVal(final int var, final int val) {
		return new Guard("x_" + var + " > " + val) {

			@Override
			public int[] vars() {
				return new int[] { var };
			}

			@Override
			public boolean usesQvars() {
				return var < 0;
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Integer varVal = (Integer) ((var == qvar) ? firstQval : binding
						.getForced(var));
				return varVal > val;
			}

			@Override
			public boolean check(Binding binding) {
				int varVal = binding.getForcedAsInteger(var);
				return varVal > val;
			}
		};
	}
<commit_msg>Guard added<commit_after>package structure.intf;

import java.util.HashSet;

import exceptions.ShouldNotHappenException;

public abstract class Guard {

	/**
	 * Checking the guard
	 * 
	 * @return true if guard evaluates to true on binding
	 */
	public abstract boolean check(Binding binding);

	public abstract boolean check(Binding binding, int qvar, Object firstQval);

	public abstract boolean usesQvars();

	public abstract int[] vars();

	public Guard replace(int var, Object val) {
		throw new ShouldNotHappenException(
				"Not implemented - experimental feature!");
	}

	protected final String name;

	public Guard(String name) {
		this.name = name;
	}

	/*
	 * Get the name of the guard
	 * 
	 * @return the name of the guard
	 */
	public String getName() {
		return name;
	}

	public static Guard isTrue(final int var0) {
		return new Guard("x_" + var0 + "== true") {
			@Override
			public boolean check(Binding binding) {
				boolean val0 = (Boolean) binding.getForced(var0);
				return val0;
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				boolean val0 = (Boolean) ((var0 == qvar) ? firstQval : binding
						.getForced(var0));
				return val0;
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0 };
			}
		};
	}

	/*
	 * Produce a guard capturing binding(var0) == binding(var1)
	 * 
	 * @ returns a guard for this property
	 */
	public static Guard isEqual(final int var0, final int var1) {
		return new Guard("x_" + var0 + " == x_" + var1) {
			@Override
			public boolean check(Binding binding) {
				Object val0 = binding.getForced(var0);
				Object val1 = binding.getForced(var1);
				return (val0 == val1);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object val0 = (var0 == qvar) ? firstQval : binding
						.getForced(var0);
				Object val1 = (var1 == qvar) ? firstQval : binding
						.getForced(var1);
				return (val0 == val1);
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0 || var1 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0, var1 };
			}
		};
	}

	public static Guard varIsEqualToIntVal(final int var, final int val) {
		return new Guard("x_" + var + " == " + val) {
			@Override
			public boolean check(Binding binding) {
				int varVal = binding.getForcedAsInteger(var);
				return varVal == val;
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				int varVal = (Integer) ((var == qvar) ? firstQval : binding
						.getForced(var));
				return varVal == val;
			}

			@Override
			public boolean usesQvars() {
				return var < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var };
			}
		};
	}

	public static Guard isSemEqualToConstant(final int var0, final Object value) {
		return new Guard("x_" + var0 + " equals x_" + value) {
			@Override
			public boolean check(Binding binding) {
				Object val0 = binding.getForced(var0);
				return (val0.equals(value));
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object val0 = (var0 == qvar) ? firstQval : binding
						.getForced(var0);
				return (val0.equals(value));
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0 };
			}
		};
	}

	/*
	 * Produce a guard capturing binding(var0) != binding(var1)
	 * 
	 * @ returns a guard for this property
	 */
	public static Guard isNotEqual(final int var0, final int var1) {
		return new Guard("x_" + var0 + " != x_" + var1) {
			@Override
			public boolean check(Binding binding) {
				Object val0 = binding.getForced(var0);
				Object val1 = binding.getForced(var1);
				return (val0 != val1);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object val0 = (var0 == qvar) ? firstQval : binding
						.getForced(var0);
				Object val1 = (var1 == qvar) ? firstQval : binding
						.getForced(var1);
				return (val0 != val1);
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0 || var1 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0, var1 };
			}
		};
	}

	/*
	 * Produce a guard capturing binding(var0) equals binding(var1)
	 * 
	 * @ returns a guard for this property
	 */
	public static Guard isEqualSem(final int var0, final int var1) {
		return new Guard("x_" + var0 + " equals x_" + var1) {
			@Override
			public boolean check(Binding binding) {
				Object val0 = binding.getForced(var0);
				Object val1 = binding.getForced(var1);
				return val0.equals(val1);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object val0 = (var0 == qvar) ? firstQval : binding
						.getForced(var0);
				Object val1 = (var1 == qvar) ? firstQval : binding
						.getForced(var1);
				return val0.equals(val1);
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0 || var1 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0, var1 };
			}
		};
	}

	public static Guard varIsEqualSemToVal(final int var, final Object val) {
		return new Guard("x_" + var + " == " + val) {
			@Override
			public boolean check(Binding binding) {
				Object varVal = binding.getForced(var);
				return varVal.equals(val);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object varVal = (var == qvar) ? firstQval : binding
						.getForced(var);
				return varVal.equals(val);
			}

			@Override
			public boolean usesQvars() {
				return var < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var };
			}
		};
	}

	public static Guard varIsNotEqualSemToVal(final int var, final Object val) {
		return new Guard("x_" + var + " != " + val) {
			@Override
			public boolean check(Binding binding) {
				Object varVal = binding.getForced(var);
				return !varVal.equals(val);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Object varVal = (var == qvar) ? firstQval : binding
						.getForced(var);
				return !varVal.equals(val);
			}

			@Override
			public boolean usesQvars() {
				return var < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var };
			}
		};
	}

	/*
	 * Produce a guard capturing binding(var0) > binding(var1)
	 * 
	 * @ returns a guard for this property
	 */
	public static Guard isGreaterThan(final int var0, final int var1) {
		return new Guard("x_" + var0 + " > x_" + var1) {
			@Override
			public boolean check(Binding binding) {
				Integer val0 = binding.getForcedAsInteger(var0);
				Integer val1 = binding.getForcedAsInteger(var1);
				return (val0 > val1);
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Integer val0 = (Integer) ((var0 == qvar) ? firstQval : binding
						.getForced(var0));
				Integer val1 = (Integer) ((var1 == qvar) ? firstQval : binding
						.getForced(var1));
				return (val0 > val1);
			}

			@Override
			public boolean usesQvars() {
				return var0 < 0 || var1 < 0;
			}

			@Override
			public int[] vars() {
				return new int[] { var0, var1 };
			}

			/*
			 * public Guard replace(final int var, final Object val){
			 * if(var!=var0 && var!=var1) return this; return new Guard(""){
			 * public boolean check(Binding binding){ Integer val0 = (Integer)
			 * ((var0==var) ? val : binding.getForcedAsInteger(var0)); Integer
			 * val1 = (Integer) ((var1==var) ? val :
			 * binding.getForcedAsInteger(var1)); return (val0 > val1); }
			 * 
			 * @Override public boolean usesQvars() { return false; } }; }
			 */
		};
	}

	public static Guard varIsLessThanVal(final int var, final int val) {
		return new Guard("x_" + var + " < " + val) {

			@Override
			public int[] vars() {
				return new int[] { var };
			}

			@Override
			public boolean usesQvars() {
				return var < 0;
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Integer varVal = (Integer) ((var == qvar) ? firstQval : binding
						.getForced(var));
				return varVal < val;
			}

			@Override
			public boolean check(Binding binding) {
				int varVal = binding.getForcedAsInteger(var);
				return varVal < val;
			}
		};
	}

	public static Guard varIsGreaterThanVal(final int var, final int val) {
		return new Guard("x_" + var + " > " + val) {

			@Override
			public int[] vars() {
				return new int[] { var };
			}

			@Override
			public boolean usesQvars() {
				return var < 0;
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				Integer varVal = (Integer) ((var == qvar) ? firstQval : binding
						.getForced(var));
				return varVal > val;
			}

			@Override
			public boolean check(Binding binding) {
				int varVal = binding.getForcedAsInteger(var);
				return varVal > val;
			}
		};
	}
	
	public static Guard doubleVarIsGreaterThanOrEqualToVal(final int var, final double val) {
		return new Guard("x_" + var + " >= " + val) {

			@Override
			public int[] vars() {
				return new int[] { var };
			}

			@Override
			public boolean usesQvars() {
				return var < 0;
			}

			@Override
			public boolean check(Binding binding, int qvar, Object firstQval) {
				double varVal = (double) ((var == qvar) ? firstQval : binding
						.getForced(var));
				return varVal >= val;
			}

			@Override
			public boolean check(Binding binding) {
				double varVal = (double) binding.getForced(var);
				return varVal >= val;
			}
		};
	}

{'fraction_non_alphanumeric': 0.1223310322684219, 'fraction_numerical': 0.0153582704553968, 'mean_word_length': 2.842895332099527, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 22, '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': '510315', 'n_tokens_mistral': 7544, 'n_tokens_neox': 6013, 'n_words': 1810}