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

net.automatalib.util.automata.predicates.TransitionPredicates Maven / Gradle / Ivy

Go to download

This artifact provides various common utility operations for analyzing and manipulating automata and graphs, such as traversal, minimization and copying.

There is a newer version: 0.11.0
Show newest version
/* Copyright (C) 2014 TU Dortmund
 * This file is part of AutomataLib, http://www.automatalib.net/.
 * 
 * AutomataLib is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 3.0 as published by the Free Software Foundation.
 * 
 * AutomataLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with AutomataLib; if not, see
 * http://www.gnu.de/documents/lgpl.en.html.
 */
package net.automatalib.util.automata.predicates;

import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.function.Predicate;

import net.automatalib.automata.concepts.TransitionOutput;
import net.automatalib.ts.TransitionPredicate;

public abstract class TransitionPredicates {

	private TransitionPredicates() {}
	
	public static 
	TransitionPredicate safePred(TransitionPredicate pred, boolean nullValue) {
		if(pred != null) {
			return pred;
		}
		return (s,i,t) -> nullValue;
	}
	
	public static 
	TransitionPredicate compose(Predicate sourcePred, Predicate inputPred, Predicate transPred) {
		final Predicate sourcePred_ = (sourcePred == null) ? (s -> true) : sourcePred;
		final Predicate inputPred_ = (inputPred == null) ? (i -> true) : inputPred;
		final Predicate transPred_ = (transPred == null) ? (t -> true) : transPred;
		return (s,i,t) -> sourcePred_.test(s) && inputPred_.test(i) && transPred_.test(t);
	}
	
	public static 
	TransitionPredicate alwaysTrue() {
		return (s,i,t) -> true;
	}
	
	public static 
	TransitionPredicate alwaysFalse() {
		return (s,i,t) -> false;
	}
	
	public static 
	TransitionPredicate constantValue(boolean value) {
		return (s,i,t) -> value;
	}
	
	public static 
	TransitionPredicate sourceSatisfying(Predicate sourcePred) {
		return (s,i,t) -> sourcePred.test(s);
	}
	
	public static 
	TransitionPredicate inputSatisfying(Predicate inputPred) {
		return (s,i,t) -> inputPred.test(i);
	}
	
	public static 
	TransitionPredicate transitionSatisfying(Predicate transPred) {
		return (s,i,t) -> transPred.test(t);
	}
	
	public static 
	TransitionPredicate inputIs(Object input) {
		return (s,i,t) -> Objects.equals(i, input);
	}
	
	public static 
	TransitionPredicate inputIsNot(Object input) {
		return (s,i,t) -> !Objects.equals(i, input);
	}
	
	@SafeVarargs
	public static 
	TransitionPredicate inputIn(Object ...inputs) {
		return inputIn(Arrays.asList(inputs));
	}
	
	public static 
	TransitionPredicate inputIn(Collection inputs) {
		return (s,i,t) -> inputs.contains(i);
	}
	
	@SafeVarargs
	public static 
	TransitionPredicate inputNotIn(Object... inputs) {
		return inputNotIn(Arrays.asList(inputs));
	}
	
	public static 
	TransitionPredicate inputNotIn(Collection inputs) {
		return (s,i,t) -> !inputs.contains(i);
	}
	
	
	
	public static 
	TransitionPredicate outputSatisfies(TransitionOutput transOut,
			Predicate outputPred) {
		return new OutputSatisfies<>(transOut, outputPred);
	}
	
	public static 
	TransitionPredicate outputViolates(TransitionOutput transOut,
			Predicate outputPred) {
		return new OutputSatisfies<>(transOut, outputPred, true);
	}
	
	public static 
	TransitionPredicate outputIs(TransitionOutput transOut,
			Object output) {
		return outputSatisfies(transOut, o -> Objects.equals(o, output));
	}
	
	public static 
	TransitionPredicate outputIsNot(TransitionOutput transOut,
			Object output) {
		return outputViolates(transOut, o -> Objects.equals(o, output));
	}
	
	public static 
	TransitionPredicate outputIn(TransitionOutput transOut,
			Object... outputs) {
		return outputIn(transOut, Arrays.asList(outputs));
	}
	
	public static 
	TransitionPredicate outputIn(TransitionOutput transOut,
			Collection outputs) {
		return outputSatisfies(transOut, o -> outputs.contains(o));
	}
	
	
	public static 
	TransitionPredicate outputNotIn(TransitionOutput transOut,
			Object... outputs) {
		return outputNotIn(transOut, Arrays.asList(outputs));
	}
	
	public static 
	TransitionPredicate outputNotIn(TransitionOutput transOut,
			Collection outputs) {
		return outputViolates(transOut, o -> outputs.contains(o));
	}
	
	
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy