Repository navigation
Expand file tree
/
Copy pathQueryOrderBy.java
More file actions
78 lines (64 loc) · 2.09 KB
/
Copy pathQueryOrderBy.java
File metadata and controls
78 lines (64 loc) · 2.09 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
package org.javawebstack.orm.query;
import org.javawebstack.orm.TableInfo;
import java.util.Objects;
/**
* The QueryOrderBy class encodes an Order By Statement.
*/
public class QueryOrderBy {
private final QueryColumn queryColumn;
private final boolean desc;
QueryOrderBy(String columnName, boolean desc) {
queryColumn = new QueryColumn(columnName);
this.desc = desc;
}
QueryOrderBy(QueryColumn column, boolean desc) {
this.queryColumn = column;
this.desc = desc;
}
/**
* Retrieves the QueryColumn of the statement which encodes the column name.
*
* @return The encoding QueryColumn object.
*/
public QueryColumn getQueryColumn() {
return queryColumn;
}
/**
* Retrieves the information if this column is ordered ascendingly or descendingly.
*
* @return false if ascending, true if descending.
*/
public boolean isDesc() {
return desc;
}
/**
* Compares the encoded column name.
*
* @param o An object to compare to.
* @return True if the object is a QueryOrderBy with a QueryColumn with generates the same identifier.
*/
public boolean hasEqualColumn(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
QueryOrderBy that = (QueryOrderBy) o;
return getQueryColumn().equals(that.getQueryColumn());
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
QueryOrderBy that = (QueryOrderBy) o;
return isDesc() == that.isDesc() && getQueryColumn().equals(that.getQueryColumn());
}
public int hashCode() {
return Objects.hash(getQueryColumn(), isDesc());
}
public String toString() {
return this.toString(null);
}
public String toString(TableInfo info) {
String stringifiedOrderBy = getQueryColumn().toString(info);
if (isDesc())
stringifiedOrderBy += " DESC";
return stringifiedOrderBy;
}
}