-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathAbstractRowValue.java
More file actions
82 lines (71 loc) · 2.54 KB
/
AbstractRowValue.java
File metadata and controls
82 lines (71 loc) · 2.54 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
package sqlancer.common.schema;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public abstract class AbstractRowValue<T extends AbstractTables<?, C>, C extends AbstractTableColumn<?, ?>, O> {
private final T tables;
private final Map<C, O> values;
protected AbstractRowValue(T tables, Map<C, O> values) {
this.tables = tables;
this.values = values;
}
public T getTable() {
return tables;
}
public Map<C, O> getValues() {
return values;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
int i = 0;
for (C c : tables.getColumns()) {
if (i++ != 0) {
sb.append(", ");
}
sb.append(values.get(c));
}
return sb.toString();
}
public String getRowValuesAsString() {
List<C> columnsToCheck = tables.getColumns();
return getRowValuesAsString(columnsToCheck);
}
public String getRowValuesAsString(List<C> columnsToCheck) {
StringBuilder sb = new StringBuilder();
Map<C, O> expectedValues = getValues();
for (int i = 0; i < columnsToCheck.size(); i++) {
if (i != 0) {
sb.append(", ");
}
O expectedColumnValue = expectedValues.get(columnsToCheck.get(i));
sb.append(expectedColumnValue);
}
return sb.toString();
}
public String asStringGroupedByTables() {
StringBuilder sb = new StringBuilder();
List<C> columnList = getValues().keySet().stream().collect(Collectors.toList());
List<AbstractTable<?, ?, ?>> tableList = columnList.stream().map(c -> c.getTable()).distinct().sorted()
.collect(Collectors.toList());
for (int j = 0; j < tableList.size(); j++) {
if (j != 0) {
sb.append("\n");
}
AbstractTable<?, ?, ?> t = tableList.get(j);
sb.append("-- ").append(t.getName()).append("\n");
List<C> columnsForTable = columnList.stream().filter(c -> c.getTable().equals(t))
.collect(Collectors.toList());
for (int i = 0; i < columnsForTable.size(); i++) {
if (i != 0) {
sb.append("\n");
}
sb.append("--\t");
sb.append(columnsForTable.get(i));
sb.append("=");
sb.append(getValues().get(columnsForTable.get(i)));
}
}
return sb.toString();
}
}