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.automata.abstractimpl;
018
019import java.util.Iterator;
020
021import net.automatalib.automata.Automaton;
022import net.automatalib.automata.concepts.StateIDs;
023import net.automatalib.ts.abstractimpl.AbstractTS;
024
025
026
027/**
028 * Abstract base class for automata.
029 * 
030 * @author Malte Isberner <malte.isberner@gmail.com>
031 *
032 * @param <S> state class.
033 * @param <I> input symbol class.
034 * @param <T> transition class.
035 */
036public abstract class AbstractAutomaton<S, I, T> extends AbstractTS<S, I, T> implements Automaton<S, I, T> {
037        /**
038         * Provides a realization of {@link Automaton#size()} using
039         * {@link Automaton#getStates()}.
040         * @see Automaton#size()
041         */
042        public static <S,I,T> int size(Automaton<S,I,T> $this) {
043                return $this.getStates().size();
044        }
045        
046        /**
047         * Provides a realization of {@link Automaton#iterator()} using
048         * {@link Automaton#iterator()}.
049         * @see Automaton#iterator()
050         */
051        public static <S,I,T> Iterator<S> iterator(Automaton<S,I,T> $this) {
052                return $this.getStates().iterator();
053        }
054        
055        /**
056         * Provides a realization of {@link Automaton#stateIDs()} using
057         * a {@link SimpleStateIDs} object.
058         * @see Automaton#stateIDs()
059         */
060        public static <S,I,T> StateIDs<S> stateIDs(Automaton<S,I,T> $this) {
061                return new SimpleStateIDs<>($this);
062        }
063        
064        //////////////////////////////////////////////////////////////////////////////////////////////
065
066        /*
067         * (non-Javadoc)
068         * @see net.automatalib.ts.SimpleFiniteTS#size()
069         */
070        @Override
071        public int size() {
072                return size(this);
073        }
074
075        /*
076         * (non-Javadoc)
077         * @see java.lang.Iterable#iterator()
078         */
079        @Override
080        public Iterator<S> iterator() {
081                return iterator(this);
082        }
083        
084        /*
085         * (non-Javadoc)
086         * @see net.automatalib.automata.simple.SimpleAutomaton#stateIDs()
087         */
088        @Override
089        public StateIDs<S> stateIDs() {
090                return stateIDs(this);
091        }
092}