Record Class BatchResult

java.lang.Object
java.lang.Record
cloud.opencode.base.io.batch.BatchResult
Record Components:
operation - the operation type | 操作类型
totalCount - total number of items | 总项目数
successCount - successful items | 成功项目数
failureCount - failed items | 失败项目数
skippedCount - skipped items | 跳过项目数
failures - map of failed paths to exceptions | 失败路径到异常的映射
startTime - operation start time | 操作开始时间
endTime - operation end time | 操作结束时间

public record BatchResult(String operation, int totalCount, int successCount, int failureCount, int skippedCount, Map<Path, Throwable> failures, Instant startTime, Instant endTime) extends Record
Batch Operation Result 批量操作结果

Immutable record containing the results of a batch file operation.

包含批量文件操作结果的不可变记录。

Features | 主要功能:

  • Immutable result of batch file operations - 批量文件操作的不可变结果
  • Success/failure/skipped counting - 成功/失败/跳过计数
  • Duration and throughput calculation - 持续时间和吞吐量计算
  • Failure details with path-to-exception mapping - 失败详情(路径到异常映射)

Usage Examples | 使用示例:

BatchResult result = OpenBatch.copyAll(files, targetDir);
if (result.isAllSuccess()) {
    System.out.println("All " + result.totalCount() + " files copied");
} else {
    result.failures().forEach((path, ex) -> System.err.println(path + ": " + ex));
}

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: No, constructor parameters must not be null - 空值安全: 否,构造器参数不可为null
Since:
JDK 25, opencode-base-io V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • BatchResult

      public BatchResult(String operation, int totalCount, int successCount, int failureCount, int skippedCount, Map<Path, Throwable> failures, Instant startTime, Instant endTime)
      Creates an instance of a BatchResult record class.
      Parameters:
      operation - the value for the operation record component
      totalCount - the value for the totalCount record component
      successCount - the value for the successCount record component
      failureCount - the value for the failureCount record component
      skippedCount - the value for the skippedCount record component
      failures - the value for the failures record component
      startTime - the value for the startTime record component
      endTime - the value for the endTime record component
  • Method Details

    • isAllSuccess

      public boolean isAllSuccess()
      Check if all operations succeeded 检查是否全部成功
      Returns:
      true if no failures | 如果没有失败返回 true
    • hasFailures

      public boolean hasFailures()
      Check if any operation failed 检查是否有失败
      Returns:
      true if any failure | 如果有失败返回 true
    • isPartialSuccess

      public boolean isPartialSuccess()
      Check if operation was partially successful 检查是否部分成功
      Returns:
      true if some succeeded and some failed | 如果部分成功部分失败返回 true
    • duration

      public Duration duration()
      Get operation duration 获取操作耗时
      Returns:
      duration | 耗时
    • successRate

      public double successRate()
      Get success rate 获取成功率
      Returns:
      success rate (0.0 to 1.0) | 成功率(0.0 到 1.0)
    • failedPaths

      public List<Path> failedPaths()
      Get failed paths 获取失败的路径
      Returns:
      list of failed paths | 失败路径列表
    • getFailure

      public Optional<Throwable> getFailure(Path path)
      Get exception for a specific path 获取特定路径的异常
      Parameters:
      path - the path | 路径
      Returns:
      exception or empty | 异常,不存在时返回空
    • summary

      public String summary()
      Get summary string 获取摘要字符串
      Returns:
      summary | 摘要
    • toString

      public 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
    • builder

      public static BatchResult.Builder builder(String operation)
      Create a builder 创建构建器
      Parameters:
      operation - the operation type | 操作类型
      Returns:
      builder | 构建器
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • operation

      public String operation()
      Returns the value of the operation record component.
      Returns:
      the value of the operation record component
    • totalCount

      public int totalCount()
      Returns the value of the totalCount record component.
      Returns:
      the value of the totalCount record component
    • successCount

      public int successCount()
      Returns the value of the successCount record component.
      Returns:
      the value of the successCount record component
    • failureCount

      public int failureCount()
      Returns the value of the failureCount record component.
      Returns:
      the value of the failureCount record component
    • skippedCount

      public int skippedCount()
      Returns the value of the skippedCount record component.
      Returns:
      the value of the skippedCount record component
    • failures

      public Map<Path, Throwable> failures()
      Returns the value of the failures record component.
      Returns:
      the value of the failures record component
    • startTime

      public Instant startTime()
      Returns the value of the startTime record component.
      Returns:
      the value of the startTime record component
    • endTime

      public Instant endTime()
      Returns the value of the endTime record component.
      Returns:
      the value of the endTime record component