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

de.prob.prolog.match.PrologListMatch 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.ListPrologTerm;
import de.prob.prolog.term.PrologTerm;

/**
 * Matches on a list with optional given length, provides direct access to the
 * list.
 */
public class PrologListMatch extends PrologMatch {
	private final Integer size;

	public static PrologListMatch anonList(int size) {
		return namedList(null, size);
	}

	public static PrologListMatch anonList() {
		return namedList(null);
	}

	public static PrologListMatch namedList(String name, int size) {
		return new PrologListMatch(name, size);
	}

	public static PrologListMatch namedList(String name) {
		return new PrologListMatch(name);
	}

	private PrologListMatch(final String name, final int size) {
		super(name);
		this.size = size;
	}

	private PrologListMatch(final String name) {
		super(name);
		this.size = -1;
	}

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy