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.fsa.abstractimpl;
018
019import net.automatalib.automata.abstractimpl.AbstractMutableAutomaton;
020import net.automatalib.automata.fsa.MutableFSA;
021
022public abstract class AbstractMutableFSA<S, I> extends
023                AbstractMutableAutomaton<S, I, S, Boolean, Void> implements
024                MutableFSA<S, I> {
025        
026
027        public static <S, I> void setStateProperty(MutableFSA<S, I> $this, S state,
028                        Boolean property) {
029                boolean acc = (property != null) ? property.booleanValue() : false;
030                $this.setAccepting(state, acc);
031        }
032
033        public static <S, I> void setTransitionProperty(MutableFSA<S, I> $this,
034                        S transition, Void property) {
035        }
036
037        public static <S, I> void flipAcceptance(MutableFSA<S, I> $this) {
038                for (S state : $this)
039                        $this.setAccepting(state, !$this.isAccepting(state));
040        }
041        
042        public static <S,I> S addState(MutableFSA<S,I> $this) {
043                return $this.addState(false);
044        }
045        
046        public static <S,I> S addState(MutableFSA<S,I> $this, Boolean property) {
047                boolean acc = (property != null) ? property.booleanValue() : false;
048                return $this.addState(acc);
049        }
050        
051        public static <S,I> S addInitialState(MutableFSA<S,I> $this) {
052                return $this.addInitialState(false);
053        }
054        
055        public static <S,I> S addInitialState(MutableFSA<S,I> $this, Boolean property) {
056                boolean acc = (property != null) ? property.booleanValue() : false;
057                return $this.addInitialState(acc);
058        }
059        
060
061        public static <S,I> S createTransition(MutableFSA<S,I> $this, S successor, Void properties) {
062                return successor;
063        }
064
065        public static <S,I> S copyTransition(MutableFSA<S,I> $this, S trans, S succ) {
066                return succ;
067        }
068        
069        
070        public static <S,I> S addInitialState(MutableFSA<S,I> $this, boolean accepting) {
071                S init = $this.addState(accepting);
072                $this.setInitial(init, true);
073                return init;
074        }
075
076        
077        /*
078         * (non-Javadoc)
079         * @see net.automatalib.automata.MutableAutomaton#setStateProperty(java.lang.Object, java.lang.Object)
080         */
081        @Override
082        public void setStateProperty(S state, Boolean property) {
083                setStateProperty(this, state, property);
084        }
085        
086        /*
087         * (non-Javadoc)
088         * @see net.automatalib.automata.MutableAutomaton#setTransitionProperty(java.lang.Object, java.lang.Object)
089         */
090        @Override
091        public void setTransitionProperty(S transition, Void property) {
092                setTransitionProperty(this, transition, property);
093        }
094        
095
096        
097        
098        /*
099         * (non-Javadoc)
100         * @see net.automatalib.automata.fsa.MutableFSA#flipAcceptance()
101         */
102        @Override
103        public void flipAcceptance() {
104                flipAcceptance(this);
105        }
106        
107        @Override
108        public S addState() {
109                return addState(this);
110        }
111        
112        @Override
113        public S addState(Boolean property) {
114                return addState(this, property);
115        }
116        
117        @Override
118        public S addInitialState() {
119                return addInitialState(this);
120        }
121        
122        @Override
123        public S addInitialState(Boolean property) {
124                return addInitialState(this, property);
125        }
126        
127        @Override
128        public S createTransition(S successor, Void properties) {
129                return createTransition(this, successor, properties);
130        }
131        
132        @Override
133        public S copyTransition(S transition, S successor) {
134                return copyTransition(this, transition, successor);
135        }
136        
137        @Override
138        public S addInitialState(boolean accepting) {
139                return addInitialState(this, accepting);
140        }
141}