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 de.cuioss.test.generator.internal.net.java.quickcheck.generator.PrimitiveGenerators;
020
021import java.time.LocalDate;
022
023/**
024 * Generates {@link LocalDate} instances within a reasonable range around the epoch.
025 * The generator creates dates between approximately 63 years before and after the epoch
026 * (1970-01-01), providing a good range for most testing scenarios.
027 * 
028 * <p>Features:</p>
029 * <ul>
030 *   <li>Generates dates from -23000 to +23000 days from epoch</li>
031 *   <li>Covers dates from roughly 1907 to 2033</li>
032 *   <li>Even distribution across the range</li>
033 *   <li>Thread-safe implementation</li>
034 * </ul>
035 * 
036 * <p><em>Example usage:</em></p>
037 * <pre>
038 * {@code
039 * // Create a generator
040 * var generator = new LocalDateGenerator();
041 * 
042 * // Generate single values
043 * LocalDate date = generator.next();
044 * 
045 * // Generate collections
046 * var collectionGen = new CollectionGenerator&lt;&gt;(generator);
047 * List&lt;LocalDate&gt; dates = collectionGen.list(5); // List of 5 dates
048 * }
049 * </pre>
050 * 
051 * <p>This generator is particularly useful for testing:</p>
052 * <ul>
053 *   <li>Date formatting and parsing</li>
054 *   <li>Date calculations and comparisons</li>
055 *   <li>Business logic involving dates</li>
056 * </ul>
057 *
058 * @author Eugen Fischer
059 * @see LocalDate
060 * @see PrimitiveGenerators#longs(long, long)
061 */
062public class LocalDateGenerator implements TypedGenerator<LocalDate> {
063
064    @Override
065    public LocalDate next() {
066        return LocalDate.ofEpochDay(PrimitiveGenerators.longs(-23000, 23000).next());
067    }
068
069    @Override
070    public Class<LocalDate> getType() {
071        return LocalDate.class;
072    }
073
074}