first commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.metalloop.common.enums;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 排序方式枚举 ASC-升序 DESC-降序
|
||||
*
|
||||
* @author yy
|
||||
*/
|
||||
public enum Direction {
|
||||
|
||||
/**
|
||||
* 升序
|
||||
*/
|
||||
ASC,
|
||||
|
||||
/**
|
||||
* 降序
|
||||
*/
|
||||
DESC;
|
||||
|
||||
/**
|
||||
* 是否升序
|
||||
*/
|
||||
public boolean isAscending() {
|
||||
return this.equals(ASC);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否降序
|
||||
*/
|
||||
public boolean isDescending() {
|
||||
return this.equals(DESC);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过字符串获取排序枚举
|
||||
*
|
||||
* @param value 字符串
|
||||
* @throws IllegalArgumentException 无法解析错误.
|
||||
*/
|
||||
public static Direction fromString(String value) {
|
||||
|
||||
try {
|
||||
return Direction.valueOf(value.toUpperCase(Locale.US));
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"无效值 '%s'! 必须为 'desc' 或者 'asc' (大小写不敏感).", value), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user