Record Class Sort
java.lang.Object
java.lang.Record
cloud.opencode.base.web.page.Sort
- Record Components:
orders- the sort orders | 排序顺序列表
Sort
排序
Represents sorting criteria for queries.
表示查询的排序条件。
Features | 主要功能:
- Multi-property sort support - 多属性排序支持
- SQL ORDER BY clause generation - SQL ORDER BY 子句生成
- Sort string parsing - 排序字符串解析
- SQL injection prevention via identifier validation - 通过标识符验证防止 SQL 注入
Usage Examples | 使用示例:
// Simple sort
Sort sort = Sort.asc("name");
Sort sort = Sort.desc("createdAt");
// Multi-property sort
Sort sort = Sort.asc("name").andDesc("createdAt");
// Parse sort string
Sort sort = Sort.parse("name,asc;age,desc");
// Generate SQL
String sql = sort.toSql(); // "name ASC, age DESC"
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: Yes (null orders default to empty list) - 空值安全: 是(null 排序默认为空列表)
- SQL injection safe: Yes (identifier validation and keyword blocking) - SQL 注入安全: 是(标识符验证和关键字阻止)
Performance | 性能特性:
- Time complexity: O(k) for parse() and toSql() where k is the number of sort orders - 时间复杂度: O(k),k 为排序条件数 - parse() 和 toSql() 均线性遍历排序条件
- Space complexity: O(k) - order list proportional to the number of sort criteria - 空间复杂度: O(k) - 排序条件列表与条件数成正比
- Since:
- JDK 25, opencode-base-web V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSort Direction 排序方向static final recordSort Order 排序顺序 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionand(Sort.Order order) Add and return new sort 添加并返回新排序Add ascending sort 添加升序Add descending sort 添加降序static SortCreate sort by property ascending 按属性升序创建排序static Sortby(Sort.Order... orders) Create sort by multiple properties 按多个属性创建排序static Sortby(List<Sort.Order> orders) Create sort by multiple properties 按多个属性创建排序static SortCreate sort by property descending 按属性降序创建排序final booleanIndicates whether some other object is "equal to" this one.getFirst()Get first order 获取第一个排序final inthashCode()Returns a hash code value for this object.booleanisSorted()Check if sorted 检查是否有排序booleanCheck if unsorted 检查是否无排序orders()Returns the value of theordersrecord component.static SortParse sort string 解析排序字符串toSql()Convert to SQL ORDER BY clause 转换为SQL ORDER BY子句final StringtoString()Returns a string representation of this record class.static Sortunsorted()Create unsorted 创建无排序
-
Constructor Details
-
Sort
Compact constructor 紧凑构造函数
-
-
Method Details
-
unsorted
-
asc
-
desc
-
by
Create sort by multiple properties 按多个属性创建排序- Parameters:
orders- the orders | 排序列表- Returns:
- the sort | 排序
-
by
Create sort by multiple properties 按多个属性创建排序- Parameters:
orders- the orders | 排序列表- Returns:
- the sort | 排序
-
parse
-
and
Add and return new sort 添加并返回新排序- Parameters:
order- the order to add | 要添加的排序- Returns:
- the new sort | 新排序
-
andAsc
-
andDesc
-
isSorted
public boolean isSorted()Check if sorted 检查是否有排序- Returns:
- true if sorted | 如果有排序返回true
-
isUnsorted
public boolean isUnsorted()Check if unsorted 检查是否无排序- Returns:
- true if unsorted | 如果无排序返回true
-
getFirst
-
toSql
Convert to SQL ORDER BY clause 转换为SQL ORDER BY子句- Returns:
- the SQL clause | SQL子句
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
orders
-