001/* Copyright (C) 2013 TU Dortmund
002 * This file is part of LearnLib, http://www.learnlib.de/.
003 * 
004 * LearnLib 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 * LearnLib 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 LearnLib; if not, see
015 * http://www.gnu.de/documents/lgpl.en.html.
016 */
017package de.learnlib.eqtests.basic;
018
019import java.util.ArrayList;
020import java.util.Arrays;
021import java.util.Collection;
022import java.util.List;
023
024import net.automatalib.automata.fsa.DFA;
025import net.automatalib.automata.transout.MealyMachine;
026import net.automatalib.words.Word;
027import de.learnlib.api.EquivalenceOracle;
028import de.learnlib.oracles.DefaultQuery;
029
030public class EQOracleChain<A, I, O> implements EquivalenceOracle<A, I, O> {
031        
032        public static class DFAEQOracleChain<I> extends EQOracleChain<DFA<?,I>,I,Boolean>
033                        implements DFAEquivalenceOracle<I> {
034                @SafeVarargs
035                public DFAEQOracleChain(
036                                EquivalenceOracle<? super DFA<?, I>, I, Boolean>... oracles) {
037                        super(oracles);
038                }
039                public DFAEQOracleChain(
040                                List<? extends EquivalenceOracle<? super DFA<?, I>, I, Boolean>> oracles) {
041                        super(oracles);
042                }
043        }
044        
045        public static class MealyEQOracleChain<I,O> extends EQOracleChain<MealyMachine<?,I,?,O>,I,Word<O>> {
046                @SafeVarargs
047                public MealyEQOracleChain(
048                                EquivalenceOracle<? super MealyMachine<?, I, ?, O>, I, Word<O>>... oracles) {
049                        super(oracles);
050                }
051                public MealyEQOracleChain(
052                                List<? extends EquivalenceOracle<? super MealyMachine<?, I, ?, O>, I, Word<O>>> oracles) {
053                        super(oracles);
054                }
055        }
056        
057        private final List<EquivalenceOracle<? super A, I, O>> oracles;
058
059        public EQOracleChain(List<? extends EquivalenceOracle<? super A,I,O>> oracles) {
060                this.oracles = new ArrayList<>(oracles);
061        }
062        
063        @SafeVarargs
064        public EQOracleChain(EquivalenceOracle<? super A,I,O> ...oracles) {
065                this(Arrays.asList(oracles));
066        }
067
068        /*
069         * (non-Javadoc)
070         * @see de.learnlib.api.EquivalenceOracle#findCounterExample(java.lang.Object, java.util.Collection)
071         */
072        @Override
073        public DefaultQuery<I, O> findCounterExample(A hypothesis,
074                        Collection<? extends I> inputs) {
075                for(EquivalenceOracle<? super A,I,O> eqOracle : oracles) {
076                        DefaultQuery<I,O> ceQry = eqOracle.findCounterExample(hypothesis, inputs);
077                        if(ceQry != null)
078                                return ceQry;
079                }
080                return null;
081        }
082
083}