package com.qianwen.core.tool.metadata;
|
|
import java.math.BigDecimal;
|
import com.qianwen.core.tool.utils.StringPool;
|
|
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/metadata/Interval.class */
|
public class Interval {
|
public static String year = StringPool.Y;
|
public static String quarter = "q";
|
public static String month = "M";
|
public static String weeks = "w";
|
public static String days = "d";
|
public static String hours = "h";
|
public static String minutes = "m";
|
public static String seconds = "s";
|
private final BigDecimal number;
|
private final String expression;
|
|
public Interval(final BigDecimal number, final String expression) {
|
this.number = number;
|
this.expression = expression;
|
}
|
|
public BigDecimal getNumber() {
|
return this.number;
|
}
|
|
public String getExpression() {
|
return this.expression;
|
}
|
|
public boolean isFixed() {
|
return this.expression.equalsIgnoreCase(hours) || this.expression.equals(minutes) || this.expression.equals(seconds);
|
}
|
|
public boolean isCalendar() {
|
return this.expression.equals(days) || this.expression.equals(month) || this.expression.equals(year);
|
}
|
|
public String toString() {
|
return this.number + this.expression;
|
}
|
|
public static Interval ofSeconds(int seconds2) {
|
return of(seconds2, seconds);
|
}
|
|
public static Interval ofDays(int days2) {
|
return of(days2, days);
|
}
|
|
public static Interval ofHours(int hours2) {
|
return of(hours2, hours);
|
}
|
|
public static Interval ofMonth(int month2) {
|
return of(month2, month);
|
}
|
|
public static Interval of(int month2, String expression) {
|
return new Interval(new BigDecimal(month2), expression);
|
}
|
|
public static Interval of(String expr) {
|
char[] charArray;
|
char[] number = new char[32];
|
int numIndex = 0;
|
for (char c : expr.toCharArray()) {
|
if (c == '-' || c == '.' || (c >= '0' && c <= '9')) {
|
int i = numIndex;
|
numIndex++;
|
number[i] = c;
|
} else {
|
BigDecimal val = new BigDecimal(number, 0, numIndex);
|
return new Interval(val, expr.substring(numIndex));
|
}
|
}
|
throw new IllegalArgumentException("can not parse interval expression:" + expr);
|
}
|
}
|