From 9490593b778b36f02622334ec9aae869472d2caf Mon Sep 17 00:00:00 2001 From: extio-de Date: Wed, 24 Dec 2025 15:12:02 +0100 Subject: [PATCH] feat(storage): Introduce StorageResource and enhance StorageService with resource-based methods --- .../game_engine/storage/StorageResource.java | 7 +++ .../game_engine/storage/StorageService.java | 47 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/main/java/de/extio/game_engine/storage/StorageResource.java diff --git a/src/main/java/de/extio/game_engine/storage/StorageResource.java b/src/main/java/de/extio/game_engine/storage/StorageResource.java new file mode 100644 index 0000000..e11ecbb --- /dev/null +++ b/src/main/java/de/extio/game_engine/storage/StorageResource.java @@ -0,0 +1,7 @@ +package de.extio.game_engine.storage; + +import java.util.List; + +public record StorageResource(List pathSegments, String resourceName) { + +} diff --git a/src/main/java/de/extio/game_engine/storage/StorageService.java b/src/main/java/de/extio/game_engine/storage/StorageService.java index be9295d..173775e 100644 --- a/src/main/java/de/extio/game_engine/storage/StorageService.java +++ b/src/main/java/de/extio/game_engine/storage/StorageService.java @@ -2,6 +2,7 @@ package de.extio.game_engine.storage; import java.io.InputStream; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -11,6 +12,11 @@ public interface StorageService { boolean deleteByPath(List path, String name); + default boolean deleteByPath(final StorageResource resource) { + Objects.requireNonNull(resource, "resource"); + return this.deleteByPath(resource.pathSegments(), resource.resourceName()); + } + List listAll(); List listPath(List path, boolean recursive); @@ -19,24 +25,65 @@ public interface StorageService { Optional loadByPath(Class clazz, List path, String name); + default Optional loadByPath(final Class clazz, final StorageResource resource) { + Objects.requireNonNull(resource, "resource"); + return this.loadByPath(clazz, resource.pathSegments(), resource.resourceName()); + } + Optional loadStreamById(UUID id); Optional loadStreamByPath(List path, String name); + default Optional loadStreamByPath(final StorageResource resource) { + Objects.requireNonNull(resource, "resource"); + return this.loadStreamByPath(resource.pathSegments(), resource.resourceName()); + } + boolean moveById(UUID id, List newPath, String newName); + default boolean moveById(final UUID id, final StorageResource newResource) { + Objects.requireNonNull(newResource, "newResource"); + return this.moveById(id, newResource.pathSegments(), newResource.resourceName()); + } + boolean moveByPath(List oldPath, String oldName, List newPath, String newName); + default boolean moveByPath(final StorageResource oldResource, final StorageResource newResource) { + Objects.requireNonNull(oldResource, "oldResource"); + Objects.requireNonNull(newResource, "newResource"); + return this.moveByPath(oldResource.pathSegments(), oldResource.resourceName(), newResource.pathSegments(), newResource.resourceName()); + } + Optional searchById(UUID id); Optional searchByPath(List path, String name); + default Optional searchByPath(final StorageResource resource) { + Objects.requireNonNull(resource, "resource"); + return this.searchByPath(resource.pathSegments(), resource.resourceName()); + } + List searchByPattern(List basePath, String pattern, boolean recursive); UUID store(List path, String name, Object obj); + default UUID store(final StorageResource resource, final Object obj) { + Objects.requireNonNull(resource, "resource"); + return this.store(resource.pathSegments(), resource.resourceName(), obj); + } + UUID storeStream(List path, String name, InputStream inputStream); + default UUID storeStream(final StorageResource resource, final InputStream inputStream) { + Objects.requireNonNull(resource, "resource"); + return this.storeStream(resource.pathSegments(), resource.resourceName(), inputStream); + } + StorageOutputStream storeStream(List path, String name); + default StorageOutputStream storeStream(final StorageResource resource) { + Objects.requireNonNull(resource, "resource"); + return this.storeStream(resource.pathSegments(), resource.resourceName()); + } + }