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.impl;
017
018import de.cuioss.test.generator.TypedGenerator;
019import lombok.Getter;
020import lombok.NonNull;
021import lombok.RequiredArgsConstructor;
022import lombok.ToString;
023
024/**
025 * A decorator pattern implementation for {@link TypedGenerator} that allows wrapping
026 * and enhancing existing generators. This is particularly useful for testing corner cases
027 * and special scenarios.
028 * 
029 * <p>Features:</p>
030 * <ul>
031 *   <li>Wraps any existing TypedGenerator</li>
032 *   <li>Preserves type safety through generic type parameter</li>
033 *   <li>Provides explicit type information via {@link #getType()}</li>
034 *   <li>Thread-safe if the decorated generator is thread-safe</li>
035 * </ul>
036 * 
037 * <p><em>Example usage:</em></p>
038 * <pre>
039 * {@code
040 * // Create a decorator for integer generation
041 * TypedGenerator&lt;Integer&gt; baseGenerator = Generators.integers(1, 100);
042 * var decorator = new DecoratorGenerator&lt;>(Integer.class, baseGenerator);
043 * 
044 * // Use the decorated generator
045 * Integer value = decorator.next();
046 * }
047 * </pre>
048 * 
049 * <p>Common use cases include:</p>
050 * <ul>
051 *   <li>Adding validation or transformation logic</li>
052 *   <li>Logging or monitoring generator behavior</li>
053 *   <li>Implementing special case handling</li>
054 *   <li>Combining multiple generators</li>
055 * </ul>
056 *
057 * @author Oliver Wolff
058 * @param <T> The type of elements to be generated
059 * @see TypedGenerator
060 */
061@RequiredArgsConstructor
062@ToString(of = "type")
063public class DecoratorGenerator<T> implements TypedGenerator<T> {
064
065    @Getter
066    @NonNull
067    private final Class<T> type;
068
069    @Getter
070    @NonNull
071    private final TypedGenerator<T> decorator;
072
073    @Override
074    public T next() {
075        return decorator.next();
076    }
077
078}