001/* Copyright (C) 2013 TU Dortmund
002 * This file is part of AutomataLib, http://www.automatalib.net/.
003 * 
004 * AutomataLib is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU Lesser General Public
006 * License version 3.0 as published by the Free Software Foundation.
007 * 
008 * AutomataLib is distributed in the hope that it will be useful,
009 * but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
011 * Lesser General Public License for more details.
012 * 
013 * You should have received a copy of the GNU Lesser General Public
014 * License along with AutomataLib; if not, see
015 * http://www.gnu.de/documents/lgpl.en.html.
016 */
017package net.automatalib.util.ts;
018
019import java.util.Collection;
020import java.util.Iterator;
021
022import net.automatalib.commons.util.mappings.Mapping;
023import net.automatalib.ts.TransitionSystem;
024import net.automatalib.ts.UniversalTransitionSystem;
025import net.automatalib.util.ts.traversal.BFSOrderIterator;
026
027
028public abstract class TS {
029        
030        
031        public static <S,I,T> Iterable<T> allTransitions(final TransitionSystem<S,I,T> ts,
032                        final S state,
033                        final Collection<I> inputs) {
034                return new Iterable<T>() {
035                        @Override
036                        public Iterator<T> iterator() {
037                                return new AllTransitionsIterator<S,I,T>(ts, state, inputs);
038                        }
039                };
040        }
041        
042        public static <S,I> Iterable<S> bfsOrder(final TransitionSystem<S,I,?> ts, final Collection<? extends I> inputs) {
043                return new Iterable<S>() {
044                        @Override
045                        public Iterator<S> iterator() {
046                                return new BFSOrderIterator<S, I>(ts, inputs);
047                        }
048                        
049                };
050        }
051        
052        public static <S,SP> Mapping<S,SP> stateProperties(final UniversalTransitionSystem<S, ?, ?, SP, ?> uts) {
053                return new Mapping<S,SP>() {
054                        @Override
055                        public SP get(S elem) {
056                                return uts.getStateProperty(elem);
057                        }
058                };
059        }
060        
061        public static <T,TP> Mapping<T,TP> transitionProperties(final UniversalTransitionSystem<?, ?, T, ?, TP> uts) {
062                return new Mapping<T,TP>() {
063                        @Override
064                        public TP get(T elem) {
065                                return uts.getTransitionProperty(elem);
066                        }
067                };
068        }
069        
070}