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.acceptors;
018
019import net.automatalib.commons.util.mappings.Mapping;
020import net.automatalib.ts.acceptors.AcceptorTS;
021import net.automatalib.ts.acceptors.DeterministicAcceptorTS;
022
023
024public abstract class Acceptors {
025        
026        private Acceptors() {}
027        
028        public static <S1,S2,I,T1,T2,
029                TS1 extends DeterministicAcceptorTS<S1,I>,
030                TS2 extends DeterministicAcceptorTS<S2,I>>
031        DetAcceptorComposition<S1, S2, I, TS1, TS2>
032        combine(TS1 ts1, TS2 ts2, AcceptanceCombiner combiner) {
033                return new DetAcceptorComposition<S1, S2, I, TS1, TS2>(ts1, ts2, combiner);
034        }
035        
036        
037        
038        public static <S1, S2, I, TS1 extends DeterministicAcceptorTS<S1, I>, TS2 extends DeterministicAcceptorTS<S2, I>>
039        DetAcceptorComposition<S1, S2, I, TS1, TS2> and(
040                        TS1 ts1, TS2 ts2) {
041                return combine(ts1, ts2, AcceptanceCombiner.AND);
042        }
043        
044        public static <S1, S2, I, TS1 extends DeterministicAcceptorTS<S1, I>, TS2 extends DeterministicAcceptorTS<S2, I>>
045        DetAcceptorComposition<S1, S2, I, TS1, TS2> or(
046                        TS1 ts1, TS2 ts2) {
047                return combine(ts1, ts2, AcceptanceCombiner.OR);
048        }
049        
050        public static <S1, S2, I, TS1 extends DeterministicAcceptorTS<S1, I>, TS2 extends DeterministicAcceptorTS<S2, I>>
051        DetAcceptorComposition<S1, S2, I, TS1, TS2> xor(
052                        TS1 ts1, TS2 ts2) {
053                return combine(ts1, ts2, AcceptanceCombiner.XOR);
054        }
055        
056        public static <S1, S2, I, TS1 extends DeterministicAcceptorTS<S1, I>, TS2 extends DeterministicAcceptorTS<S2, I>>
057        DetAcceptorComposition<S1, S2, I, TS1, TS2> equiv(
058                        TS1 ts1, TS2 ts2) {
059                return combine(ts1, ts2, AcceptanceCombiner.EQUIV);
060        }
061        
062        public static <S1, S2, I, TS1 extends DeterministicAcceptorTS<S1, I>, TS2 extends DeterministicAcceptorTS<S2, I>>
063        DetAcceptorComposition<S1, S2, I, TS1, TS2> impl(
064                        TS1 ts1, TS2 ts2) {
065                return combine(ts1, ts2, AcceptanceCombiner.IMPL);
066        }
067        
068        
069        public static <S> Mapping<S,Boolean> acceptance(final AcceptorTS<S, ?> acceptor) {
070                return new Mapping<S,Boolean>() {
071                        @Override
072                        public Boolean get(S elem) {
073                                return acceptor.isAccepting(elem);
074                        }
075                };
076        }
077        
078        
079
080}