-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathWindowOffset.java
More file actions
87 lines (73 loc) · 2.08 KB
/
Copy pathWindowOffset.java
File metadata and controls
87 lines (73 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
import java.util.Locale;
public class WindowOffset implements Serializable {
private Expression expression;
private Type type;
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
if (expression != null) {
buffer.append(' ').append(expression);
if (type != null) {
buffer.append(' ');
buffer.append(type);
}
} else {
if (type != null) {
switch (type) {
case PRECEDING:
buffer.append(" UNBOUNDED PRECEDING");
break;
case FOLLOWING:
buffer.append(" UNBOUNDED FOLLOWING");
break;
case CURRENT:
buffer.append(" CURRENT ROW");
break;
default:
break;
}
}
}
return buffer.toString();
}
public WindowOffset withExpression(Expression expression) {
this.setExpression(expression);
return this;
}
public WindowOffset withType(Type type) {
this.setType(type);
return this;
}
public <E extends Expression> E getExpression(Class<E> type) {
return type.cast(getExpression());
}
public enum Type {
PRECEDING, FOLLOWING, CURRENT, EXPR;
public static Type from(String type) {
return Enum.valueOf(Type.class, type.toUpperCase(Locale.ROOT));
}
}
}