Class Sort

java.lang.Object
cloud.opencode.base.core.page.Sort

public final class Sort extends Object
Sort - Sort specification for queries 排序 - 查询排序规范

Represents an ordered collection of sort orders, each consisting of a property name and a direction (ASC or DESC). Compatible with Spring Data semantics while having no dependency on Spring Data Commons.

表示有序的排序规范集合,每项包含属性名和方向(ASC 或 DESC)。 与 Spring Data 语义兼容,但不依赖 Spring Data Commons。

Features | 主要功能:

  • Fluent builder API for composing sort orders - 流式构建 API 组合排序规范
  • ASC / DESC direction with null handling - 支持 ASC / DESC 及 null 处理
  • Immutable value object — safe to share and cache - 不可变值对象,可安全共享和缓存

Usage Examples | 使用示例:

Sort sort = Sort.by("name").and(Sort.by(Sort.Direction.DESC, "createdAt"));
Sort descAge = Sort.by(Sort.Direction.DESC, "age");
List<Sort.Order> orders = sort.getOrders();
String sql = "ORDER BY " + sort.toSql();  // name ASC, created_at DESC

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
Since:
JDK 25, opencode-base-core V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Field Details

    • UNSORTED

      public static final Sort UNSORTED
      Unsorted singleton. 无排序单例。
  • Method Details

    • by

      public static Sort by(String property)
    • by

      public static Sort by(Sort.Direction direction, String property)
    • by

      public static Sort by(Sort.Direction direction, String... properties)
    • by

      public static Sort by(Sort.Order... orders)
    • by

      public static Sort by(List<Sort.Order> orders)
    • unsorted

      public static Sort unsorted()
    • getOrders

      public List<Sort.Order> getOrders()
    • isUnsorted

      public boolean isUnsorted()
    • and

      public Sort and(Sort other)
    • toSql

      public String toSql()
      Renders this Sort as a SQL ORDER BY fragment (without the ORDER BY keyword). 渲染为 SQL ORDER BY 片段(不含 ORDER BY 关键字)。
      Returns:
      SQL fragment, or empty string if unsorted | SQL 片段,无排序时为空字符串
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object