-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathResponseValue.java
More file actions
65 lines (56 loc) · 1.73 KB
/
ResponseValue.java
File metadata and controls
65 lines (56 loc) · 1.73 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
/* Copyright (c) restSQL Project Contributors. Licensed under MIT. */
package org.restsql.core;
/**
* Represents a response column name, value and column number, which may be placed into a set ordered by column number.
* In a hierarchical resource, the children set is placed into a column with the name of the child table (or alias) and
* a column number at the max integer value.
*
* @author Mark Sawers
*/
public class ResponseValue implements Comparable<ResponseValue> {
private final String name;
private final Object value;
private final int columnNumber;
public ResponseValue(final String name, final Object value, final int columnNumber) {
this.name = name;
this.value = value;
this.columnNumber = columnNumber;
}
@Override
public int compareTo(ResponseValue value) {
if (columnNumber < value.getColumnNumber()) {
return -1;
} else if (columnNumber > value.getColumnNumber()) {
return 1;
} else {
return 0;
}
}
/** Returns true if the names, values and column numbers are equal. */
@Override
public boolean equals(Object o) {
return ((ResponseValue) o).getName().equals(name) && ((ResponseValue) o).getValue().equals(value)
&& ((ResponseValue) o).getColumnNumber() == columnNumber;
}
/** Returns column number in the select clause in the SQL Resource definition query. */
public int getColumnNumber() {
return columnNumber;
}
/** Returns name. */
public String getName() {
return name;
}
/** Returns value. */
public Object getValue() {
return value;
}
@Override
public int hashCode() {
return name.hashCode() + value.hashCode();
}
/** Returns string representation in the form <code>name: value</code>. */
@Override
public String toString() {
return name + ": " + value;
}
}