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.domain; 017 018import de.cuioss.test.generator.TypedGenerator; 019 020import java.util.Locale; 021 022/** 023 * Generates full names in the format 'firstname lastname' based on the specified locale. 024 * Supports both German and English name sets. 025 * 026 * <p>Name sources:</p> 027 * <ul> 028 * <li>German names from {@link NameGenerators#FIRSTNAMES_ANY_GERMAN} and {@link NameGenerators#FAMILY_NAMES_GERMAN}</li> 029 * <li>English names from {@link NameGenerators#FIRSTNAMES_ANY_ENGLISH} and {@link NameGenerators#FAMILY_NAMES_ENGLISH}</li> 030 * </ul> 031 * 032 * <p><em>Example usage:</em></p> 033 * <pre> 034 * // For German names 035 * var generator = new FullNameGenerator(Locale.GERMAN); 036 * String name = generator.next(); // e.g. "Hans Schmidt" 037 * 038 * // For English names 039 * generator = new FullNameGenerator(Locale.ENGLISH); 040 * name = generator.next(); // e.g. "John Smith" 041 * </pre> 042 * 043 * @author Oliver Wolff 044 * 045 */ 046public class FullNameGenerator implements TypedGenerator<String> { 047 048 private final TypedGenerator<String> firstNames; 049 private final TypedGenerator<String> familyNames; 050 051 /** 052 * Creates a new FullNameGenerator with the default locale (English). 053 */ 054 public FullNameGenerator() { 055 this(Locale.ENGLISH); 056 } 057 058 /** 059 * Creates a new FullNameGenerator for the specified locale. 060 * 061 * @param locale Determines the name set to use. If {@link Locale#GERMAN}, German names will be used; 062 * for all other locales, English names will be used. 063 */ 064 public FullNameGenerator(final Locale locale) { 065 if (Locale.GERMAN.equals(locale)) { 066 firstNames = NameGenerators.FIRSTNAMES_ANY_GERMAN.generator(); 067 familyNames = NameGenerators.FAMILY_NAMES_GERMAN.generator(); 068 } else { 069 firstNames = NameGenerators.FIRSTNAMES_ANY_ENGLISH.generator(); 070 familyNames = NameGenerators.FAMILY_NAMES_ENGLISH.generator(); 071 } 072 } 073 074 @Override 075 public String next() { 076 return firstNames.next() + ' ' + familyNames.next(); 077 } 078 079}