Interface StorageResult<T>
- Type Parameters:
T
- The type of data being stored
- All Known Implementing Classes:
StorageResult.ExceptionResult
,StorageResult.FailureResult
,StorageResult.NoneResult
,StorageResult.PartialFailureResult
,StorageResult.SuccessResult
public sealed interface StorageResult<T>
permits StorageResult.SuccessResult<T>, StorageResult.PartialFailureResult<T>, StorageResult.FailureResult<T>, StorageResult.ExceptionResult<T>, StorageResult.NoneResult<T>
Represents the result of a storage operation.
This sealed interface provides a type-safe way to handle different outcomes
of storage operations, including success, partial success, failure, and exception.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final record
Represents a storage operation that resulted in an exception.static final record
Represents a failed storage operation where all data failed to be stored.static final record
Represents a storage operation that resulting in nothing occurring.static final record
Represents a partially failed storage operation where some data were stored successfully and others failed.static final record
Represents a fully successful storage operation where all data were stored successfully.static enum
-
Method Summary
Modifier and TypeMethodDescriptionerror()
Returns an Optional containing the exception if one occurred during the storage operation.static <T> StorageResult<T>
static <T> StorageResult<T>
exception
(Exception error, List<T> failedData, QualityCode qualityCode) Returns the list of data that failed to be stored.static <T> StorageResult<T>
failure
(QualityCode qualityCode, List<T> failedData) static <T> StorageResult<T>
static <T> StorageResult<T>
join
(StorageResult<? extends T> result1, StorageResult<? extends T> result2) Joins twoStorageResult
instances into a single combined result.static <T> StorageResult<T>
none()
static <T> StorageResult<T>
of
(QualityCode qualityCode, List<T> successfulData, List<T> failedData, Exception error) static <T> StorageResult<T>
static <T> StorageResult<T>
static <T> StorageResult<T>
partialFailure
(List<T> successfulData, List<T> failedData) static <T> StorageResult<T>
partialFailure
(List<T> successfulData, List<T> failedData, Exception error) Returns the quality code associated with this storage result.static <T> StorageResult<T>
success()
static <T> StorageResult<T>
success
(QualityCode qualityCode) static <T> StorageResult<T>
success
(QualityCode qualityCode, List<T> successfulData) static <T> StorageResult<T>
Returns the list of successfully stored data.type()
Returns the exact type that this storage result represents.static <T> StorageResult<T>
unsupported
(List<T> failedData)
-
Method Details
-
qualityCode
QualityCode qualityCode()Returns the quality code associated with this storage result.- Returns:
- the
QualityCode
indicating the quality of the storage operation
-
successfulData
Returns the list of successfully stored data.- Returns:
- an unmodifiable
List
of successfully storedT
-
failedData
Returns the list of data that failed to be stored.- Returns:
- an unmodifiable
List
ofT
that failed to be stored
-
error
Returns an Optional containing the exception if one occurred during the storage operation. -
type
StorageResult.Type type()Returns the exact type that this storage result represents.- Returns:
- the result
StorageResult.Type
-
none
-
success
-
success
-
success
-
success
-
unsupported
-
failure
-
failure
-
exception
-
exception
-
partialFailure
-
partialFailure
static <T> StorageResult<T> partialFailure(List<T> successfulData, List<T> failedData, @Nullable Exception error) -
of
-
of
static <T> StorageResult<T> of(@Nullable List<T> successfulData, @Nullable List<T> failedData, Exception error) -
of
static <T> StorageResult<T> of(QualityCode qualityCode, @Nullable List<T> successfulData, @Nullable List<T> failedData, @Nullable Exception error) -
join
static <T> StorageResult<T> join(StorageResult<? extends T> result1, StorageResult<? extends T> result2) Joins twoStorageResult
instances into a single combined result.- Type Parameters:
T
- The type of data being stored- Parameters:
result1
- The first StorageResult to joinresult2
- The second StorageResult to join- Returns:
- A new StorageResult that combines the data and status of both input results
-