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.Pair;
020import net.automatalib.ts.acceptors.DeterministicAcceptorTS;
021import net.automatalib.ts.acceptors.abstractimpl.AbstractAcceptorTS;
022import net.automatalib.ts.acceptors.abstractimpl.AbstractDeterministicAcceptorTS;
023import net.automatalib.ts.comp.DTSComposition;
024
025public class DetAcceptorComposition<S1, S2, I, A1 extends DeterministicAcceptorTS<S1, I>, A2 extends DeterministicAcceptorTS<S2, I>>
026                extends DTSComposition<S1, S2, I, S1, S2, A1, A2> implements DeterministicAcceptorTS<Pair<S1,S2>, I> {
027
028        private final AcceptanceCombiner combiner;
029        
030        public DetAcceptorComposition(A1 ts1, A2 ts2, AcceptanceCombiner combiner) {
031                super(ts1, ts2);
032                this.combiner = combiner;
033        }
034        
035        @Override
036        public boolean isAccepting(Pair<S1, S2> state) {
037                S1 s1 = state.getFirst();
038                S2 s2 = state.getSecond();
039                boolean acc1 = ts1.isAccepting(s1);
040                boolean acc2 = ts2.isAccepting(s2);
041                return combiner.combine(acc1, acc2);
042        }
043
044        @Override
045        public boolean accepts(Iterable<I> input) {
046                return AbstractDeterministicAcceptorTS.accepts(this, input);
047        }
048
049        @Override
050        public Boolean getStateProperty(Pair<S1, S2> state) {
051                return AbstractAcceptorTS.getStateProperty(this, state);
052        }
053
054        @Override
055        public Void getTransitionProperty(Pair<S1, S2> transition) {
056                return AbstractAcceptorTS.getTransitionProperty(this, transition);
057        }
058
059}