All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.learnlib.api.query.DefaultQuery Maven / Gradle / Ivy

There is a newer version: 0.17.0
Show newest version
/* Copyright (C) 2013-2020 TU Dortmund
 * This file is part of LearnLib, http://www.learnlib.de/.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.learnlib.api.query;

import net.automatalib.words.Word;

/**
 * A query is a container for tests a learning algorithms performs, containing the actual test and the corresponding
 * result.
 *
 * @param 
 *         input symbol type
 * @param 
 *         output domain type
 *
 * @author Maik Merten
 */
public class DefaultQuery extends AbstractQuery {

    private D output;

    public DefaultQuery(Word prefix, Word suffix, D output) {
        this(prefix, suffix);
        this.output = output;
    }

    public DefaultQuery(Word prefix, Word suffix) {
        super(prefix, suffix);
    }

    public DefaultQuery(Word input) {
        super(input);
    }

    public DefaultQuery(Word input, D output) {
        super(input);
        this.output = output;
    }

    public DefaultQuery(Query query) {
        super(query);
    }

    public D getOutput() {
        return output;
    }

    /**
     * Checks if the query is normalized, i.e., if all the information is stored in the {@link #getSuffix() suffix} part
     * of the counterexample.
     *
     * @return {@code true} if the counterexample is normalized, {@code false} otherwise.
     */
    public boolean isNormalized() {
        return prefix.isEmpty();
    }

    @Override
    public void answer(D output) {
        this.output = output;
    }

    /**
     * @see AbstractQuery#toStringWithAnswer(Object)
     */
    @Override
    public String toString() {
        return toStringWithAnswer(output);
    }

}