XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEServerManager

【Java】我的世界XFE服务器管理器

公开
关注 0 Fork 0 Star 0
UTF-8
package com.xfestudio.xfeservermanager.api.operation;

import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.time.Instant;
import java.util.Map;
import java.util.Objects;

/** Serializable state of a short or asynchronous management operation. */
public record OperationResult(
        String operationId,
        OperationStatus status,
        String message,
        Map<String, String> data,
        ApiError error,
        Instant startedAt,
        Instant completedAt
) {
    public OperationResult {
        operationId = ApiChecks.notBlank(operationId, "operationId");
        Objects.requireNonNull(status, "status");
        message = ApiChecks.notBlank(message, "message");
        data = ApiChecks.immutableMap(data, "data");
        Objects.requireNonNull(startedAt, "startedAt");
        if (status.isTerminal() != (completedAt != null)) {
            throw new IllegalArgumentException("completedAt must be present exactly for terminal states");
        }
        if (status == OperationStatus.FAILED && error == null) {
            throw new IllegalArgumentException("failed operations require an error");
        }
        if (status != OperationStatus.FAILED && error != null) {
            throw new IllegalArgumentException("only failed operations may contain an error");
        }
    }
}