diff --git a/src/main/java/com/livingworld/regions/RegionStorage.java b/src/main/java/com/livingworld/regions/RegionStorage.java new file mode 100644 index 0000000..4d75483 --- /dev/null +++ b/src/main/java/com/livingworld/regions/RegionStorage.java @@ -0,0 +1,56 @@ +package com.livingworld.regions; + +import com.livingworld.core.services.PersistenceService; + +import java.util.Optional; + +/** + * Storage class for managing region persistence operations. + * + *

This class delegates loading and saving of regions to the provided + * {@link PersistenceService} instance, with argument validation.

+ */ +public class RegionStorage { + + private final PersistenceService persistenceService; + + /** + * Creates a new RegionStorage instance. + * + * @param persistenceService the persistence service to delegate to (must not be null) + * @throws IllegalArgumentException if persistenceService is null + */ + public RegionStorage(PersistenceService persistenceService) { + if (persistenceService == null) { + throw new IllegalArgumentException("PersistenceService must not be null"); + } + this.persistenceService = persistenceService; + } + + /** + * Loads a region from storage by its coordinate. + * + * @param coordinate the region coordinate to load (must not be null) + * @return an Optional containing the loaded region if it exists, or empty if not found + * @throws IllegalArgumentException if coordinate is null + */ + public Optional load(RegionCoordinate coordinate) { + if (coordinate == null) { + throw new IllegalArgumentException("RegionCoordinate must not be null"); + } + return persistenceService.loadRegion(coordinate); + } + + /** + * Saves a region to storage. + * + * @param region the region to save (must not be null) + * @throws IllegalArgumentException if region is null + */ + public void save(Region region) { + if (region == null) { + throw new IllegalArgumentException("Region must not be null"); + } + persistenceService.saveRegion(region); + } +} \ No newline at end of file