Record Class DataResult.Success<T>

java.lang.Object
java.lang.Record
com.github.darksoulq.abyssallib.common.serialization.DataResult.Success<T>
Type Parameters:
T - The type of the successful value.
Record Components:
value - The successfully serialized or deserialized data.
warnings - Collection tracking degraded performance notes mapping.
All Implemented Interfaces:
DataResult<T>
Enclosing interface:
DataResult<T>

public static record DataResult.Success<T>(T value, List<DataError> warnings) extends Record implements DataResult<T>
The structural implementation of a successful serialization state, handling optional partials.
  • Constructor Details

    • Success

      public Success(T value, List<DataError> warnings)
      Creates an instance of a Success record class.
      Parameters:
      value - the value for the value record component
      warnings - the value for the warnings record component
  • Method Details

    • isSuccess

      public boolean isSuccess()
      Specified by:
      isSuccess in interface DataResult<T>
      Returns:
      True if this result represents a success (including partial successes), false otherwise.
    • isError

      public boolean isError()
      Specified by:
      isError in interface DataResult<T>
      Returns:
      True if this result represents an error, false otherwise.
    • isPartial

      public boolean isPartial()
      Specified by:
      isPartial in interface DataResult<T>
      Returns:
      True if this result is successful but carries recorded warnings.
    • result

      public Optional<T> result()
      Specified by:
      result in interface DataResult<T>
      Returns:
      An Optional containing the value if successful, or empty if an error.
    • error

      public Optional<String> error()
      Specified by:
      error in interface DataResult<T>
      Returns:
      An Optional containing the formatted error message if an error, or empty if successful.
    • dataError

      public Optional<DataError> dataError()
      Specified by:
      dataError in interface DataResult<T>
      Returns:
      An Optional containing the exact DataError type evaluated during deserialization.
    • getOrThrow

      public T getOrThrow()
      Description copied from interface: DataResult
      Retrieves the value or throws a RuntimeException if this is an error.
      Specified by:
      getOrThrow in interface DataResult<T>
      Returns:
      The wrapped value.
    • orElse

      public T orElse(T defaultValue)
      Description copied from interface: DataResult
      Retrieves the value, or returns the provided default value if this is an error.
      Specified by:
      orElse in interface DataResult<T>
      Parameters:
      defaultValue - The fallback value.
      Returns:
      The wrapped value or the default.
    • map

      public <R> DataResult<R> map(Function<? super T, ? extends R> mapper)
      Description copied from interface: DataResult
      Transforms the wrapped value using the provided mapping function.
      Specified by:
      map in interface DataResult<T>
      Type Parameters:
      R - The new value type.
      Parameters:
      mapper - The transformation logic.
      Returns:
      A new DataResult containing the transformed value.
    • flatMap

      public <R> DataResult<R> flatMap(Function<? super T, ? extends DataResult<? extends R>> mapper)
      Description copied from interface: DataResult
      Transforms the wrapped value into a new DataResult using the provided flat-mapping function. Supports covariant return types to prevent generic capture mismatches.
      Specified by:
      flatMap in interface DataResult<T>
      Type Parameters:
      R - The new value type.
      Parameters:
      mapper - The transformation logic that yields a DataResult.
      Returns:
      A new DataResult.
    • mapError

      public DataResult<T> mapError(Function<String,String> errorMapper)
      Description copied from interface: DataResult
      Transforms the error message if this result represents an error.
      Specified by:
      mapError in interface DataResult<T>
      Parameters:
      errorMapper - The logic to apply to the existing error message.
      Returns:
      A new DataResult with the transformed error.
    • prependPath

      public DataResult<T> prependPath(String path)
      Description copied from interface: DataResult
      Prepends a path segment to the error context or recorded warnings to build a complete diagnostic trajectory.
      Specified by:
      prependPath in interface DataResult<T>
      Parameters:
      path - The path segment to prepend.
      Returns:
      A new DataResult reflecting the updated path logic.
    • addWarning

      public DataResult<T> addWarning(DataError warning)
      Description copied from interface: DataResult
      Injects a recorded warning into the execution timeline without forcing a structural failure.
      Specified by:
      addWarning in interface DataResult<T>
      Parameters:
      warning - The localized diagnostic logging message mapped as an error.
      Returns:
      A modified instance retaining the internal value but flagging warning status.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • value

      public T value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • warnings

      public List<DataError> warnings()
      Returns the value of the warnings record component.
      Specified by:
      warnings in interface DataResult<T>
      Returns:
      the value of the warnings record component