de.prob.prolog.match.PrologMatch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of prologlib Show documentation
Show all versions of prologlib Show documentation
Part of the ProB Parser library
package de.prob.prolog.match;
import java.util.HashMap;
import java.util.Map;
import de.prob.prolog.term.PrologTerm;
/**
* This class and its subclasses are used to do pattern-matching on Prolog
* terms. It is a kind of unification.
*
* This base class matches every {@link PrologTerm}.
*/
public class PrologMatch {
private final String name;
public PrologMatch anon() {
return named(null);
}
public PrologMatch named(final String name) {
return new PrologMatch(name);
}
protected PrologMatch(final String name) {
this.name = name;
}
public final boolean matches(final PrologTerm term,
final Map hits) {
boolean isMatch = isMatch(term, hits);
if (isMatch && hits != null && name != null) {
hits.put(name, term);
}
return isMatch;
}
protected boolean isMatch(final PrologTerm term,
final Map hits) {
return true;
}
public final Map getMatches(final PrologTerm term) {
Map hits = new HashMap();
boolean matches = matches(term, hits);
return matches ? hits : null;
}
public final boolean matches(final PrologTerm term) {
return matches(term, null);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy