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

de.prob.prolog.match.PrologVariableMatch Maven / Gradle / Ivy

There is a newer version: 2.13.5
Show newest version
package de.prob.prolog.match;

import java.util.Map;

import de.prob.prolog.term.PrologTerm;
import de.prob.prolog.term.VariablePrologTerm;

/**
 * Matches a Prolog variable.
 */
public class PrologVariableMatch extends PrologMatch {
	private final String varName;

	public static PrologVariableMatch anonVar(String varName) {
		return namedVar(null, varName);
	}

	public static PrologVariableMatch anonVar() {
		return namedVar(null, null);
	}

	public static PrologVariableMatch namedVar(String name, String varName) {
		return new PrologVariableMatch(name, varName);
	}

	public static PrologVariableMatch namedVar(String name) {
		return namedVar(name, null);
	}

	/**
	 * Matches on a Prolog variable with the given name
	 * 
	 * @param name
	 *            the name, if null it will not be checked
	 */
	private PrologVariableMatch(final String name, final String varName) {
		super(name);
		this.varName = varName;
	}

	@Override
	protected boolean isMatch(PrologTerm term, Map hits) {
		boolean match = term instanceof VariablePrologTerm;
		if (match && varName != null) {
			match = varName.equals(((VariablePrologTerm) term).getName());
		}
		return match;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy