WorldTemplatePaginatedList.java

com.mojang.realmsclient.dto.WorldTemplatePaginatedList

信息

  • 全限定名:com.mojang.realmsclient.dto.WorldTemplatePaginatedList
  • 类型:public record
  • 包:com.mojang.realmsclient.dto
  • 源码路径:src/main/java/com/mojang/realmsclient/dto/WorldTemplatePaginatedList.java
  • 起始行号:L15
  • 职责:

    TODO

字段/常量

  • LOGGER
    • 类型: Logger
    • 修饰符: private static final
    • 源码定位: L16
    • 说明:

      TODO

内部类/嵌套类型

构造器

public WorldTemplatePaginatedList(int size) @ L18

  • 构造器名:WorldTemplatePaginatedList
  • 源码定位:L18
  • 修饰符:public

参数:

  • size: int

说明:

TODO

方法

下面的方法块按源码顺序生成。

public boolean isLastPage() @ L22

  • 方法名:isLastPage
  • 源码定位:L22
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public static WorldTemplatePaginatedList parse(String json) @ L26

  • 方法名:parse
  • 源码定位:L26
  • 返回类型:WorldTemplatePaginatedList
  • 修饰符:public static

参数:

  • json: String

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public record WorldTemplatePaginatedList(List<WorldTemplate> templates, int page, int size, int total) {
    private static final Logger LOGGER = LogUtils.getLogger();
 
    public WorldTemplatePaginatedList(int size) {
        this(List.of(), 0, size, -1);
    }
 
    public boolean isLastPage() {
        return this.page * this.size >= this.total && this.page > 0 && this.total > 0 && this.size > 0;
    }
 
    public static WorldTemplatePaginatedList parse(String json) {
        List<WorldTemplate> templates = new ArrayList<>();
        int page = 0;
        int size = 0;
        int total = 0;
 
        try {
            JsonObject object = LenientJsonParser.parse(json).getAsJsonObject();
            if (object.get("templates").isJsonArray()) {
                for (JsonElement element : object.get("templates").getAsJsonArray()) {
                    WorldTemplate template = WorldTemplate.parse(element.getAsJsonObject());
                    if (template != null) {
                        templates.add(template);
                    }
                }
            }
 
            page = JsonUtils.getIntOr("page", object, 0);
            size = JsonUtils.getIntOr("size", object, 0);
            total = JsonUtils.getIntOr("total", object, 0);
        } catch (Exception var9) {
            LOGGER.error("Could not parse WorldTemplatePaginatedList", (Throwable)var9);
        }
 
        return new WorldTemplatePaginatedList(templates, page, size, total);
    }
}

引用的其他类

  • WorldTemplate

    • 引用位置: 方法调用
    • 关联成员: WorldTemplate.parse()
  • JsonUtils

    • 引用位置: 方法调用
    • 关联成员: JsonUtils.getIntOr()
  • LenientJsonParser

    • 引用位置: 方法调用
    • 关联成员: LenientJsonParser.parse()