001/*
002 * Copyright © 2025 CUI-OpenSource-Software (info@cuioss.de)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package de.cuioss.test.generator.internal.net.java.quickcheck.generator.support;
017
018import de.cuioss.test.generator.internal.net.java.quickcheck.Generator;
019
020import java.util.Objects;
021
022/**
023 * {@link Generator} implementation that transforms input generator test cases
024 * of type I to output test cases of type T.
025 *
026 * @param <I> input generator test case type
027 * @param <T> output generator test case type
028 *
029 */
030public abstract class AbstractTransformerGenerator<I, T> implements Generator<T> {
031
032    private Generator<I> inputGenerator;
033
034    protected AbstractTransformerGenerator(Generator<I> inputGenerator) {
035        setInputGenerator(inputGenerator);
036    }
037
038    protected abstract T transform(Generator<I> inputGenerator);
039
040    @Override
041    public T next() {
042        return transform(inputGenerator);
043    }
044
045    Generator<I> getInputGenerator() {
046        return inputGenerator;
047    }
048
049    void setInputGenerator(Generator<I> inputGenerator) {
050        Objects.requireNonNull(inputGenerator, "inputGenerator");
051        this.inputGenerator = inputGenerator;
052    }
053}