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.UUID; 021import java.util.logging.Level; 022import java.util.logging.Logger; 023 024/** 025 * Generates random UUID strings in the standard 8-4-4-4-12 format (e.g. "550e8400-e29b-41d4-a716-446655440000"). 026 * The generator is thread-safe and produces reproducible results when using the same seed. 027 * 028 * <p><em>Example usage from tests:</em></p> 029 * <pre> 030 * var generator = new UUIDStringGenerator(); 031 * String uuid = generator.next(); // Returns a valid UUID string 032 * UUID.fromString(uuid); // Can be parsed back to UUID 033 * </pre> 034 * 035 * @author Oliver Wolff 036 */ 037public class UUIDStringGenerator implements TypedGenerator<String> { 038 039 private static final Logger LOGGER = Logger.getLogger(UUIDStringGenerator.class.getName()); 040 private final TypedGenerator<UUID> uuids = new UUIDGenerator(); 041 042 @Override 043 public String next() { 044 var result = uuids.next().toString(); 045 LOGGER.log(Level.FINE, "Generated UUID: {0}", result); 046 return result; 047 } 048 049 @Override 050 public Class<String> getType() { 051 return String.class; 052 } 053 054}